IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
소스 검색

Introduce jail_run_v2().

tags/0.92
부모
커밋
4b33532422
2개의 변경된 파일47개의 추가작업 그리고 0개의 파일을 삭제
  1. +45
    -0
      jail.py
  2. +2
    -0
      requirements.txt

+ 45
- 0
jail.py 파일 보기

@@ -4,6 +4,50 @@ import random
import shutil
import json
from tabulate import tabulate
import os
import jailconf
import shlex
def jail_run_v2(path, command, env, mounts):
name = os.path.split(path)[-1]
if os.path.exists('/etc/jail.conf'):
conf = jailconf.load('/etc/jail.conf')
else:
conf = jailconf.JailConf()
conf[name] = blk = jailconf.JailBlock()
blk['path'] = path
env = [ 'export ' + k + '=' + shlex.quote(v) \
for (k, v) in env.items() ]
command = ' && '.join(env + [ command ])
# blk['exec.start'] = command
prestart = [ 'cp /etc/resolv.conf ' +
shlex.quote(os.path.join(path, 'etc/resolv.conf')) ]
poststop = []
if mounts:
for (from_, on) in mounts:
if not from_.startswith('/'):
from_, _ = zfs_find(from_, focker_type='volume')
from_ = zfs_mountpoint(from_)
prestart.append('mount -t nullfs ' + shlex.quote(from_) +
' ' + shlex.quote(os.path.join(path, on.strip('/'))))
poststop += [ 'umount -f ' +
os.path.join(path, on.strip('/')) \
for (_, on) in reversed(mounts) ]
if prestart:
blk['exec.prestart'] = shlex.quote(' && '.join(prestart))
if poststop:
blk['exec.poststop'] = shlex.quote(' && '.join(poststop))
blk['persist'] = True
blk['interface'] = 'lo1'
blk['ip4.addr'] = '127.0.1.0'
blk['mount.devfs'] = True
blk['exec.clean'] = True
conf.write('/etc/jail.conf')
# command = '/bin/sh -c ' + shlex.quote(command)
subprocess.check_output([ 'jail', '-c', name ])
subprocess.run([ 'jexec', name, '/bin/sh', '-c', command ])
subprocess.check_output([ 'jail', '-r', name ])
def get_jid(path):
@@ -58,6 +102,7 @@ def jail_run(path, command, mounts=[]):
def jail_remove(path):
print('Removing jail:', path)
# subprocess.
def command_jail_run(args):


+ 2
- 0
requirements.txt 파일 보기

@@ -0,0 +1,2 @@
tabulate
jailconf

불러오는 중...
취소
저장