move clean-ephemeral to lxc pre-start hook
This commit is contained in:
parent
433e23022a
commit
4543bbc49f
@ -44,6 +44,10 @@ parser_disable_autostart.add_argument('app', help='Application name')
|
|||||||
parser_rebuild_issue = subparsers.add_parser('rebuild-issue', help='Rebuilds /etc/issue using current settings - used on VM startup')
|
parser_rebuild_issue = subparsers.add_parser('rebuild-issue', help='Rebuilds /etc/issue using current settings - used on VM startup')
|
||||||
parser_rebuild_issue.set_defaults(action='rebuild-issue')
|
parser_rebuild_issue.set_defaults(action='rebuild-issue')
|
||||||
|
|
||||||
|
parser_clean_ephemeral = subparsers.add_parser('clean-ephemeral', help='Cleans container ephemeral layer. Intended to be used with LXC hooks')
|
||||||
|
parser_clean_ephemeral.add_argument('lxc', nargs=argparse.REMAINDER)
|
||||||
|
parser_clean_ephemeral.set_defaults(action='clean-ephemeral')
|
||||||
|
|
||||||
parser_register_container = subparsers.add_parser('register-container', help='Register and assigns IP to an application container. Intended to be used with LXC hooks')
|
parser_register_container = subparsers.add_parser('register-container', help='Register and assigns IP to an application container. Intended to be used with LXC hooks')
|
||||||
parser_register_container.add_argument('lxc', nargs=argparse.REMAINDER)
|
parser_register_container.add_argument('lxc', nargs=argparse.REMAINDER)
|
||||||
parser_register_container.set_defaults(action='register-container')
|
parser_register_container.set_defaults(action='register-container')
|
||||||
@ -102,6 +106,8 @@ elif args.action == 'disable-autostart':
|
|||||||
mgr.disable_autostart(args.app)
|
mgr.disable_autostart(args.app)
|
||||||
elif args.action == 'rebuild-issue':
|
elif args.action == 'rebuild-issue':
|
||||||
mgr.rebuild_issue()
|
mgr.rebuild_issue()
|
||||||
|
elif args.action == 'clean-ephemeral':
|
||||||
|
mgr.clean_ephemeral()
|
||||||
elif args.action == 'register-container':
|
elif args.action == 'register-container':
|
||||||
mgr.register_container()
|
mgr.register_container()
|
||||||
elif args.action == 'unregister-container':
|
elif args.action == 'unregister-container':
|
||||||
|
@ -211,6 +211,11 @@ class VMMgr:
|
|||||||
raise validator.InvalidValueException('app', app)
|
raise validator.InvalidValueException('app', app)
|
||||||
subprocess.run(['/sbin/rc-update', 'del', app])
|
subprocess.run(['/sbin/rc-update', 'del', app])
|
||||||
|
|
||||||
|
def clean_ephemeral(self):
|
||||||
|
# Remove ephemeral layer data
|
||||||
|
app = os.environ['LXC_NAME']
|
||||||
|
tools.clean_ephemeral_layer(app)
|
||||||
|
|
||||||
def register_container(self):
|
def register_container(self):
|
||||||
# Set IP of a container based on values given via lxc.hook.start-host hook
|
# Set IP of a container based on values given via lxc.hook.start-host hook
|
||||||
app = os.environ['LXC_NAME']
|
app = os.environ['LXC_NAME']
|
||||||
@ -218,15 +223,13 @@ class VMMgr:
|
|||||||
ip = tools.get_unused_ip()
|
ip = tools.get_unused_ip()
|
||||||
tools.update_hosts_lease(ip, app)
|
tools.update_hosts_lease(ip, app)
|
||||||
tools.set_container_ip(pid, ip)
|
tools.set_container_ip(pid, ip)
|
||||||
# Remove ephemeral layer data
|
|
||||||
tools.remove_ephemeral_layer(app)
|
|
||||||
|
|
||||||
def unregister_container(self):
|
def unregister_container(self):
|
||||||
# Unset IP of a container based on values given via lxc.hook.post-stop hook
|
# Unset IP of a container based on values given via lxc.hook.post-stop hook
|
||||||
app = os.environ['LXC_NAME']
|
app = os.environ['LXC_NAME']
|
||||||
tools.update_hosts_lease(None, app)
|
tools.update_hosts_lease(None, app)
|
||||||
# Remove ephemeral layer data
|
# Remove ephemeral layer data
|
||||||
tools.remove_ephemeral_layer(app)
|
tools.clean_ephemeral_layer(app)
|
||||||
|
|
||||||
def register_proxy(self, app, reload_nginx=True):
|
def register_proxy(self, app, reload_nginx=True):
|
||||||
# Rebuild nginx configuration using IP of referenced app container and reload nginx
|
# Rebuild nginx configuration using IP of referenced app container and reload nginx
|
||||||
|
@ -155,7 +155,7 @@ def set_container_ip(pid, ip):
|
|||||||
cmd = 'ip addr add {}/16 broadcast 172.17.255.255 dev eth0 && ip route add default via 172.17.0.1'.format(ip)
|
cmd = 'ip addr add {}/16 broadcast 172.17.255.255 dev eth0 && ip route add default via 172.17.0.1'.format(ip)
|
||||||
subprocess.run(['nsenter', '-a', '-t', pid, '--', '/bin/sh', '-c', cmd])
|
subprocess.run(['nsenter', '-a', '-t', pid, '--', '/bin/sh', '-c', cmd])
|
||||||
|
|
||||||
def remove_ephemeral_layer(app):
|
def clean_ephemeral_layer(app):
|
||||||
layer = os.path.join('/var/lib/lxc', app, 'delta0')
|
layer = os.path.join('/var/lib/lxc', app, 'delta0')
|
||||||
if os.path.exists(layer):
|
if os.path.exists(layer):
|
||||||
for item in os.scandir(layer):
|
for item in os.scandir(layer):
|
||||||
|
@ -43,6 +43,7 @@ lxc.console.logfile = /var/log/lxc/{name}.log
|
|||||||
# Other
|
# Other
|
||||||
lxc.arch = x86_64
|
lxc.arch = x86_64
|
||||||
lxc.cap.drop = sys_admin
|
lxc.cap.drop = sys_admin
|
||||||
|
lxc.hook.pre-start = /usr/bin/vmmgr clean-ephemeral
|
||||||
lxc.hook.start-host = /usr/bin/vmmgr register-container
|
lxc.hook.start-host = /usr/bin/vmmgr register-container
|
||||||
lxc.hook.post-stop = /usr/bin/vmmgr unregister-container
|
lxc.hook.post-stop = /usr/bin/vmmgr unregister-container
|
||||||
lxc.include = /usr/share/lxc/config/common.conf
|
lxc.include = /usr/share/lxc/config/common.conf
|
||||||
|
Loading…
x
Reference in New Issue
Block a user