@@ -38,6 +38,7 @@ from .compose import \ | |||||
command_compose_build, \ | command_compose_build, \ | ||||
command_compose_run | command_compose_run | ||||
from .bootstrap import command_bootstrap | from .bootstrap import command_bootstrap | ||||
from .misc import focker_lock | |||||
class ListForwarderFunctor(object): | class ListForwarderFunctor(object): | ||||
@@ -203,6 +204,7 @@ def create_parser(): | |||||
def main(): | def main(): | ||||
focker_lock() | |||||
zfs_init() | zfs_init() | ||||
parser = create_parser() | parser = create_parser() | ||||
args = parser.parse_args() | args = parser.parse_args() | ||||
@@ -15,8 +15,6 @@ import os | |||||
import jailconf | import jailconf | ||||
from .mount import getmntinfo | from .mount import getmntinfo | ||||
import shlex | import shlex | ||||
import fcntl | |||||
# import pdb | |||||
import stat | import stat | ||||
@@ -38,18 +36,9 @@ def backup_file(fname, nbackups=10): | |||||
def jail_conf_write(conf): | def jail_conf_write(conf): | ||||
os.makedirs('/var/lock', exist_ok=True) | |||||
with open('/var/lock/focker.lock', 'a+') as f: | |||||
print('Waiting for /var/lock/focker.lock ...') | |||||
fcntl.flock(f, fcntl.LOCK_EX) | |||||
print('Lock acquired') | |||||
try: | |||||
bakname = backup_file('/etc/jail.conf') | |||||
os.chmod(bakname, 0o600) | |||||
conf.write('/etc/jail.conf') | |||||
finally: | |||||
fcntl.flock(f, fcntl.LOCK_UN) | |||||
print('Lock released') | |||||
bakname = backup_file('/etc/jail.conf') | |||||
os.chmod(bakname, 0o600) | |||||
conf.write('/etc/jail.conf') | |||||
def jail_fs_create(image=None): | def jail_fs_create(image=None): | ||||
@@ -7,6 +7,8 @@ | |||||
import random | import random | ||||
from .zfs import zfs_exists | from .zfs import zfs_exists | ||||
import os | |||||
import fcntl | |||||
def random_sha256_hexdigest(): | def random_sha256_hexdigest(): | ||||
@@ -19,3 +21,20 @@ def find_prefix(head, tail): | |||||
if not zfs_exists(name): | if not zfs_exists(name): | ||||
break | break | ||||
return name | return name | ||||
def focker_lock(): | |||||
os.makedirs('/var/lock', exist_ok=True) | |||||
if focker_lock.fd is None: | |||||
focker_lock.fd = open('/var/lock/focker.lock', 'a+') | |||||
print('Waiting for /var/lock/focker.lock ...') | |||||
fcntl.flock(focker_lock.fd, fcntl.LOCK_EX) | |||||
print('Lock acquired.') | |||||
focker_lock.fd = None | |||||
def focker_unlock(): | |||||
if focker_lock.fd is None: | |||||
return | |||||
fcntl.flock(focker_lock.fd, fcntl.LOCK_UN) | |||||
print('Lock released') |