diff options
Diffstat (limited to 'src/helpers/vyos-boot-config-loader.py')
-rwxr-xr-x | src/helpers/vyos-boot-config-loader.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/helpers/vyos-boot-config-loader.py b/src/helpers/vyos-boot-config-loader.py index 7c81a4c3c..c5bf22f10 100755 --- a/src/helpers/vyos-boot-config-loader.py +++ b/src/helpers/vyos-boot-config-loader.py @@ -20,19 +20,21 @@ import os import sys import pwd import grp -import subprocess import traceback from datetime import datetime from vyos.defaults import directories from vyos.configsession import ConfigSession, ConfigSessionError from vyos.configtree import ConfigTree +from vyos.util import cmd STATUS_FILE = '/tmp/vyos-config-status' TRACE_FILE = '/tmp/boot-config-trace' CFG_GROUP = 'vyattacfg' +trace_config = False + if 'log' in directories: LOG_DIR = directories['log'] else: @@ -45,6 +47,9 @@ try: cmdline = f.read() if 'vyos-debug' in cmdline: os.environ['VYOS_DEBUG'] = 'yes' + if 'vyos-config-debug' in cmdline: + os.environ['VYOS_DEBUG'] = 'yes' + trace_config = True except Exception as e: print('{0}'.format(e)) @@ -97,12 +102,7 @@ def failsafe(config_file_name): 'authentication', 'encrypted-password']) - cmd = ("useradd -s /bin/bash -G 'users,sudo' -m -N -p '{0}' " - "vyos".format(passwd)) - try: - subprocess.check_call(cmd, shell=True) - except subprocess.CalledProcessError as e: - sys.exit("{0}".format(e)) + cmd(f"useradd -s /bin/bash -G 'users,sudo' -m -N -p '{passwd}' vyos") if __name__ == '__main__': if len(sys.argv) < 2: @@ -130,8 +130,9 @@ if __name__ == '__main__': config_file = f.read() except Exception: write_config_status(1) - failsafe(default_file_name) - trace_to_file(TRACE_FILE) + if trace_config: + failsafe(default_file_name) + trace_to_file(TRACE_FILE) sys.exit(1) try: @@ -146,8 +147,9 @@ if __name__ == '__main__': # If here, there is no use doing session.discard, as we have no # recoverable config environment, and will only throw an error write_config_status(1) - failsafe(default_file_name) - trace_to_file(TRACE_FILE) + if trace_config: + failsafe(default_file_name) + trace_to_file(TRACE_FILE) sys.exit(1) time_elapsed_load = time_end_load - time_begin_load |