|
@@ -2,14 +2,27 @@ import subprocess |
|
|
from .zfs import *
|
|
|
from .zfs import *
|
|
|
import random
|
|
|
import random
|
|
|
import shutil
|
|
|
import shutil
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_jid(path):
|
|
|
|
|
|
data = json.loads(subprocess.check_output(['jls', '--libxo=json']))
|
|
|
|
|
|
lst = data['jail-information']['jail']
|
|
|
|
|
|
lst = list(filter(lambda a: a['path'] == path, lst))
|
|
|
|
|
|
if len(lst) == 0:
|
|
|
|
|
|
raise ValueError('JID not found for path: ' + path)
|
|
|
|
|
|
if len(lst) > 1:
|
|
|
|
|
|
raise ValueError('Ambiguous JID for path: ' + path)
|
|
|
|
|
|
return str(lst[0]['jid'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def jail_run(path, command):
|
|
|
def jail_run(path, command):
|
|
|
command = ['jail', '-c', 'host.hostname=' + os.path.split(path)[1], 'mount.devfs=1', 'interface=lo1', 'ip4.addr=127.0.1.0', 'path=' + path, 'command', '/bin/sh', '-c', command]
|
|
|
|
|
|
|
|
|
command = ['jail', '-c', 'host.hostname=' + os.path.split(path)[1], 'persist=1', 'mount.devfs=1', 'interface=lo1', 'ip4.addr=127.0.1.0', 'path=' + path, 'command', '/bin/sh', '-c', command]
|
|
|
print('Running:', ' '.join(command))
|
|
|
print('Running:', ' '.join(command))
|
|
|
try:
|
|
|
try:
|
|
|
res = subprocess.run(command)
|
|
|
res = subprocess.run(command)
|
|
|
finally:
|
|
|
finally:
|
|
|
|
|
|
subprocess.run(['jail', '-r', get_jid(path)])
|
|
|
subprocess.run(['umount', '-f', os.path.join(path, 'dev')])
|
|
|
subprocess.run(['umount', '-f', os.path.join(path, 'dev')])
|
|
|
if res.returncode != 0:
|
|
|
if res.returncode != 0:
|
|
|
# subprocess.run(['umount', os.path.join(path, 'dev')])
|
|
|
# subprocess.run(['umount', os.path.join(path, 'dev')])
|
|
|