From 67caca817115c4257e795f8777a9a9bf1c14bda4 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Fri, 21 Sep 2018 16:21:55 +0200 Subject: [PATCH] Move app configuration to pre-start hook --- basic/srv/vm/cli.py | 10 +++++----- basic/srv/vm/mgr/__init__.py | 8 ++++---- zz-extra/lxc-build | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/basic/srv/vm/cli.py b/basic/srv/vm/cli.py index b14415a..477984e 100755 --- a/basic/srv/vm/cli.py +++ b/basic/srv/vm/cli.py @@ -44,9 +44,9 @@ 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.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_prepare_container = subparsers.add_parser('prepare-container', help='Cleans container ephemeral layer and sets common config for the app. Intended to be used with LXC hooks') +parser_prepare_container.add_argument('lxc', nargs=argparse.REMAINDER) +parser_prepare_container.set_defaults(action='prepare-container') 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) @@ -106,8 +106,8 @@ elif args.action == 'disable-autostart': mgr.disable_autostart(args.app) elif args.action == 'rebuild-issue': mgr.rebuild_issue() -elif args.action == 'clean-ephemeral': - mgr.clean_ephemeral() +elif args.action == 'prepare-container': + mgr.prepare_container() elif args.action == 'register-container': mgr.register_container() elif args.action == 'unregister-container': diff --git a/basic/srv/vm/mgr/__init__.py b/basic/srv/vm/mgr/__init__.py index d13278e..52e2f4b 100644 --- a/basic/srv/vm/mgr/__init__.py +++ b/basic/srv/vm/mgr/__init__.py @@ -210,18 +210,18 @@ class VMMgr: raise validator.InvalidValueException('app', app) subprocess.run(['/sbin/rc-update', 'del', app]) - def clean_ephemeral(self): - # Extract the variables from values given via lxc.hook.pre-start or lxc.hook.post-stop hook + def prepare_container(self): + # Extract the variables from values given via lxc.hook.pre-start hook app = os.environ['LXC_NAME'] # Remove ephemeral layer data tools.clean_ephemeral_layer(app) + # Configure host and common params used in the app + self.configure_app(app) def register_container(self): # Extract the variables from values given via lxc.hook.start-host hook app = os.environ['LXC_NAME'] pid = os.environ['LXC_PID'] - # Configure host and common params used in the app - self.configure_app(app) # Lease the first unused IP to the container ip = tools.get_unused_ip() tools.update_hosts_lease(ip, app) diff --git a/zz-extra/lxc-build b/zz-extra/lxc-build index f843344..cce7d31 100755 --- a/zz-extra/lxc-build +++ b/zz-extra/lxc-build @@ -43,7 +43,7 @@ lxc.console.logfile = /var/log/lxc/{name}.log # Other lxc.arch = x86_64 lxc.cap.drop = sys_admin -lxc.hook.pre-start = /usr/bin/vmmgr clean-ephemeral +lxc.hook.pre-start = /usr/bin/vmmgr prepare-container lxc.hook.start-host = /usr/bin/vmmgr register-container lxc.hook.post-stop = /usr/bin/vmmgr unregister-container lxc.include = /usr/share/lxc/config/common.conf