diff --git a/ctl.py b/ctl.py index 3110bd7..27629ac 100755 --- a/ctl.py +++ b/ctl.py @@ -12,7 +12,7 @@ import os import pty def di_syscall(cmd, workdir='.'): - #print('[dbg] CMD: %s' % (cmd)) + #print('[dbg] CMD: %s | WD: %s' % (cmd, workdir)) process = subprocess.run(cmd, capture_output=True, cwd=workdir) return (process.stdout.decode("utf-8").strip(), process.stderr.decode("utf-8").strip()) @@ -56,6 +56,41 @@ def get_config(path): return None +def create_example_config(): + conf_raw = """{ + # Container name + name: example--config + # Name container in log/output/console + title: Example Config + # Image container + image: hello-world:linux + # (optional) Shell command for container + shell: sh + # (optional) Signal for update configuration in container + upd-sig: HUP + # (optional) Arguments|Params for containered application + cmd: [ + --arg_key + value + ] + # (optional) Ports + ports: [ + 0.0.0.0:8080:80 + ] + # (optional) Volumes + volumes: [ + /etc/timezone:/etc/timezone:ro + /etc/localtime:/etc/localtime:ro + ] + # (optional) Environment + env: { + ENV_KEY: value + } +}""" + fd = open('./container.conf', 'w') + fd.write(conf_raw) + fd.close() + # -------------------------- # class Container: @@ -161,6 +196,11 @@ class Container: if len(sys.argv) == 1: print_help_exit() +if sys.argv[1] == 'init': + print('Create example config') + create_example_config() + exit() + conf = None begin_index_commands = None workdir = None @@ -168,6 +208,7 @@ if os.path.isfile(sys.argv[1]): conf = get_config(sys.argv[1]) begin_index_commands = 2 workdir = os.path.dirname(sys.argv[1]) + if len(workdir) == 0: workdir = '.' else: conf = get_config('container.conf') begin_index_commands = 1