From b3f2a4be70309c51a3a119cc32bd01ec1a08d2de Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sun, 5 Apr 2020 20:34:40 +0200 Subject: [PATCH] Allow spoc-container start to pass a command --- usr/bin/spoc-container | 7 ++++--- usr/lib/python3.8/spoc/container.py | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/usr/bin/spoc-container b/usr/bin/spoc-container index 14e4474..7317ad7 100755 --- a/usr/bin/spoc-container +++ b/usr/bin/spoc-container @@ -87,9 +87,9 @@ def destroy(container_name): # Remove container and its directory Container(container_name, False).destroy() -def start(container_name): +def start(container_name, command): # Start the container using init values from its definition - Container(container_name).start() + Container(container_name).start(command) def stop(container_name): # Stop the container using halt signal from its definition @@ -147,6 +147,7 @@ parser_destroy.add_argument('container') parser_start = subparsers.add_parser('start') parser_start.set_defaults(action=start) parser_start.add_argument('container') +parser_start.add_argument('command', nargs=argparse.REMAINDER) parser_stop = subparsers.add_parser('stop') parser_stop.set_defaults(action=stop) @@ -174,7 +175,7 @@ elif args.action is modify: elif args.action is destroy: destroy(args.container) elif args.action is start: - start(args.container) + start(args.container, args.command) elif args.action is stop: stop(args.container) elif args.action is status: diff --git a/usr/lib/python3.8/spoc/container.py b/usr/lib/python3.8/spoc/container.py index 62579e7..d45e831 100644 --- a/usr/lib/python3.8/spoc/container.py +++ b/usr/lib/python3.8/spoc/container.py @@ -151,17 +151,18 @@ class Container: # Release the IP address from global hosts configuration net.release_ip(self.name) - def start(self): + def start(self, command=None): # Start the container including its dependencies depsolver = DepSolver() self.get_start_dependencies(depsolver) for dependency in depsolver.solve(): if dependency.get_state() != ContainerState.RUNNING: - dependency.do_start() + dependency.do_start(command if dependency.name == self.name else None) - def do_start(self): + def do_start(self, command=None): + cmd = ['--']+command if command else [] # Start the current container, wait until it is reported as started and execute application readiness check - subprocess.Popen(['lxc-start', '-P', config.CONTAINERS_DIR, self.name]) + subprocess.Popen(['lxc-start', '-P', config.CONTAINERS_DIR, self.name]+cmd) self.await_state(ContainerState.RUNNING) # Launch the readiness check in a separate thread, so it can be reliably cancelled after timeout with ThreadPoolExecutor(max_workers=1) as pool: