def _start(name): _log('start, name=%s' % name) path = _get_path_run(name) kill_by_file(KLNK_NAME, path) binding = get_binding(name) umount(binding) mkdirs(binding) mountpoint = get_mountpoint(name) umount(mountpoint) mkdirs(mountpoint) cmd = [_get_path_cmd(), name2addr(name), mountpoint] # _log(' '.join(cmd)) pid = popen(cmd) if not chkpid(pid): raise Exception("failed to start ipc") path = _get_path_run(name) save_pid(path, pid) path = os.path.join(mountpoint, 'test') if not _touch(path): raise Exception('failed to start ipc') bind(mountpoint, binding) path = os.path.join(binding, 'test') if not _touch(path): raise Exception('failed to start ipc')
def create(name): dirname = get_path(name) _log('create, mnt=%s' % dirname) mkdirs(dirname) path = _get_bin(name) mkdirs(path) cpdir(PATH_BIN, path) multiprocessing.Process(target=ftp.create, args=(dirname, name2addr(name), FS_PORT)).start() if LBFS: _start_lbfs(name, create=True)
def start(name): path = get_path(name) _log('start, mnt=%s' % path) mkdirs(path) umount(path) ftp.mount(path, name2addr(name), FS_PORT) path = _get_bin(name) if not os.path.exists(path): log('failed to start (name=%s)' % name) raise Exception('Error: failed to start (name=%s)' % name) if LBFS: _start_lbfs(name)
def _check_fstab(name): fstab = [] fstab.append( 'proc proc proc nodev,noexec,nosuid 0 0\n') fstab.append('sysfs sys sysfs defaults 0 0\n') src = fs.get_mountpoint(name) dest = fs.get_binding(name) mkdirs(dest) fstab.append('%s %s none bind 0 0\n' % (src, dest)) src = ipc.get_mountpoint(name) dest = ipc.get_binding(name) mkdirs(dest) fstab.append('%s %s none bind 0 0\n' % (src, dest)) if LBFS: src = fs.get_mountpoint(name, lbfs=True) dest = os.path.join(fs.get_mnt(name), fs.get_name()) mkdirs(dest) fstab.append('%s %s none bind 0 0\n' % (src, dest)) if CKPT: src = ckpt.get_mountpoint(name) dest = os.path.join(fs.get_mnt(name), ckpt.get_name()) mkdirs(dest) fstab.append('%s %s none bind 0 0\n' % (src, dest)) path = os.path.join(PATH_LXC_LIB, name, 'fstab') with open(path, 'w') as f: f.writelines(fstab)
def _check_fstab(name): fstab = [] fstab.append('proc proc proc nodev,noexec,nosuid 0 0\n') fstab.append('sysfs sys sysfs defaults 0 0\n') src = fs.get_mountpoint(name) dest = fs.get_binding(name) mkdirs(dest) fstab.append('%s %s none bind 0 0\n' % (src, dest)) src = ipc.get_mountpoint(name) dest = ipc.get_binding(name) mkdirs(dest) fstab.append('%s %s none bind 0 0\n' % (src, dest)) if LBFS: src = fs.get_mountpoint(name, lbfs=True) dest = os.path.join(fs.get_mnt(name), fs.get_name()) mkdirs(dest) fstab.append('%s %s none bind 0 0\n' % (src, dest)) if CKPT: src = ckpt.get_mountpoint(name) dest = os.path.join(fs.get_mnt(name), ckpt.get_name()) mkdirs(dest) fstab.append('%s %s none bind 0 0\n' % (src, dest)) path = os.path.join(PATH_LXC_LIB, name, 'fstab') with open(path, 'w') as f: f.writelines(fstab)
def _start_lbfs(name, create=False): mnt = _get_lbfs_mnt(name) path = _get_path_run(name) home = _get_path_home(name) _log('start lbfs, name=%s, home=%s, mnt=%s' % (name, home, mnt)) kill_by_file(LBFS_NAME, path) umount(mnt) mkdirs(mnt) if create: mkdirs(home) cmd = [_get_path_cmd(), name, home, mnt] # _log(' '.join(cmd)) pid = popen(cmd) if not chkpid(pid): log('failed to start lbfs (name=%s)' % name) raise Exception('failed to start lbfs') save_pid(path, pid)
def _start(name, create=False): path = _get_path_run(name) kill_by_file(VMAP_NAME, path) vmap = os.path.join(PATH_INIT, VMAP_NAME) home = _get_path_home(name) if create: mkdirs(home) mountpoint = get_mountpoint(name) _log('start, home=%s, mnt=%s' % (home, mountpoint)) umount(mountpoint) mkdirs(mountpoint) cmd = [vmap, home, mountpoint] pid = popen(cmd) if not chkpid(pid): log('failed to start ckpt') raise Exception('failed to start ckpt') path = _get_path_run(name) save_pid(path, pid)
def _check_cfg(name): dirname = os.path.join(PATH_LXC_LIB, name) mkdirs(dirname) cfg = [] if PROBE: cfg.append('lxc.network.type = veth\n') cfg.append('lxc.network.link = %s\n' % BR_NAME) cfg.append('lxc.network.flags = up\n') cfg.append('lxc.network.hwaddr = %s\n' % _check_hwaddr()) cfg.append('lxc.rootfs = %s\n' % os.path.join(dirname, 'rootfs')) cfg.append('lxc.mount = %s\n' % os.path.join(dirname, 'fstab')) cfg.append('lxc.utsname = %s\n' % name) cfg.append('lxc.devttydir = lxc\n') cfg.append('lxc.tty = 4\n') cfg.append('lxc.pts = 1024\n') cfg.append('lxc.arch = i686\n') cfg.append('lxc.cap.drop = sys_module mac_admin\n') if AA_ALLOW_INCOMPLETE: cfg.append('lxc.aa_allow_incomplete = 1\n') if AA_PROFILE_UNCONFINED: cfg.append('lxc.aa_profile = unconfined\n') #cfg.append('lxc.pivotdir = lxc_putold\n') cfg.append('lxc.cgroup.devices.deny = a\n') cfg.append('lxc.cgroup.devices.allow = c *:* m\n') cfg.append('lxc.cgroup.devices.allow = b *:* m\n') cfg.append('lxc.cgroup.devices.allow = c 1:3 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 1:5 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 5:1 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 5:0 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 1:9 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 1:8 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 136:* rwm\n') cfg.append('lxc.cgroup.devices.allow = c 5:2 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 254:0 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 10:229 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 10:200 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 1:7 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 10:228 rwm\n') cfg.append('lxc.cgroup.devices.allow = c 10:232 rwm\n') path = os.path.join(dirname, 'config') with open(path, 'w') as f: f.writelines(cfg)
def _check_path(name): mkdirs(PATH_RUN) os.system('rm -f %s' % os.path.join(PATH_RUN, '%s.%s.pid' % (container.LXC_NAME, name))) os.system('rm -f %s' % os.path.join(PATH_RUN, '%s.%s.pid' % (ipc.KLNK_NAME, name))) os.system('rm -f %s' % os.path.join(PATH_RUN, '%s.%s.pid' % (fs.LBFS_NAME, name))) os.system('rm -f %s' % os.path.join(PATH_RUN, '%s.%s.pid' % (ckpt.VMAP_NAME, name))) mkdirs(PATH_MNT) mkdirs(os.path.join(PATH_MNT, fs.get_name())) mkdirs(os.path.join(PATH_MNT, ipc.get_name())) mkdirs(os.path.join(PATH_MNT, ckpt.get_name())) mkdirs(PATH_BIN) mkdirs(PATH_VAR) dirname = fs.get_log_path() mkdirs(dirname) os.system('rm -f %s' % os.path.join(dirname, '%s.%s.log' % (container.LXC_NAME, name))) os.system('rm -f %s' % os.path.join(dirname, '%s.%s.log' % (ipc.KLNK_NAME, name))) os.system('rm -f %s' % os.path.join(dirname, '%s.%s.log' % (fs.LBFS_NAME, name))) mkdirs(fs.get_conf_path()) dirname = fs.get_path(name) umount(dirname) mkdirs(dirname)