From 16cf7583f56f9ab69e1ddb5780b4fb42495a79f4 Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 28 Nov 2024 14:13:57 +0900 Subject: [PATCH 1/4] support multiple node args with same name --- mytoninstaller/mytoninstaller.py | 6 +++-- mytoninstaller/node_args.py | 29 ++++++++++++++++++--- mytoninstaller/scripts/set_node_argument.py | 7 +++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/mytoninstaller/mytoninstaller.py b/mytoninstaller/mytoninstaller.py index 270afe97..97e5ce4e 100644 --- a/mytoninstaller/mytoninstaller.py +++ b/mytoninstaller/mytoninstaller.py @@ -133,13 +133,15 @@ def Status(local, args): node_args = get_node_args() color_print("{cyan}===[ Node arguments ]==={endc}") for key, value in node_args.items(): - print(f"{key}: {value}") + for v in value: + print(f"{key}: {v}") #end define def set_node_argument(local, args): if len(args) < 1: - color_print("{red}Bad args. Usage:{endc} set_node_argument [arg-value] [-d (to delete)]") + color_print("{red}Bad args. Usage:{endc} set_node_argument [arg-value] [-d (to delete)].\n" + "Examples: 'set_node_argument --archive-ttl 86400' or 'set_node_argument --archive-ttl -d' or 'set_node_argument -M' or 'set_node_argument --add-shard 0:2000000000000000 0:a000000000000000'") return arg_name = args[0] args = [arg_name, args[1] if len(args) > 1 else ""] diff --git a/mytoninstaller/node_args.py b/mytoninstaller/node_args.py index af7b8380..e57d925b 100644 --- a/mytoninstaller/node_args.py +++ b/mytoninstaller/node_args.py @@ -15,21 +15,42 @@ def get_node_start_command(): #end define +""" def get_node_args(command: str = None): if command is None: command = get_node_start_command() - result = {} + result = [] key = '' for c in command.split(' ')[1:]: if c.startswith('--') or c.startswith('-'): if key: - result[key] = '' + result.append([key, '']) key = c elif key: - result[key] = c + result.append([key, c]) key = '' if key: - result[key] = '' + result.append([key, '']) + return result +#end define +""" + + +def get_node_args(command: str = None): + if command is None: + command = get_node_start_command() + result = {} # {key: [value1, value2]} + key = '' + for c in command.split(' ')[1:]: + if c.startswith('--') or c.startswith('-'): + if key: + result[key] = result.get(key, []) + [''] + key = c + elif key: + result[key] = result.get(key, []) + [c] + key = '' + if key: + result[key] = result.get(key, []) + [''] return result #end define diff --git a/mytoninstaller/scripts/set_node_argument.py b/mytoninstaller/scripts/set_node_argument.py index 19fe67a5..cd241bea 100644 --- a/mytoninstaller/scripts/set_node_argument.py +++ b/mytoninstaller/scripts/set_node_argument.py @@ -20,8 +20,11 @@ def set_node_arg(arg_name: str, arg_value: str = ''): if arg_value == '-d': args.pop(arg_name, None) else: - args[arg_name] = arg_value - new_command = command.split(' ')[0] + ' ' + ' '.join([f'{k} {v}' for k, v in args.items()]) + if ' ' in arg_value: + args[arg_name] = arg_value.split() + else: + args[arg_name] = [arg_value] + new_command = command.split(' ')[0] + ' ' + ' '.join([f'{k} {v}' for k, vs in args.items() for v in vs]) new_service = service.replace(command, new_command) with open('/etc/systemd/system/validator.service', 'w') as f: f.write(new_service) From e0d87d1b30810608fdb007afed84fd4bcce54e43 Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 28 Nov 2024 14:16:49 +0900 Subject: [PATCH 2/4] dont remove state-ttl for vals on updates --- mytonctrl/mytonctrl.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index de3d7ce8..25e340fc 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -369,14 +369,6 @@ def Upgrade(ton, args): upgrade_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/upgrade.sh') runArgs = ["bash", upgrade_script_path, "-a", author, "-r", repo, "-b", branch] exitCode = run_as_root(runArgs) - if ton.using_validator(): - try: - from mytoninstaller.mytoninstaller import set_node_argument, get_node_args - node_args = get_node_args() - if node_args.get('--state-ttl') == '604800': - set_node_argument(ton.local, ["--state-ttl", "-d"]) - except Exception as e: - color_print(f"{{red}}Failed to set node argument: {e} {{endc}}") if exitCode == 0: text = "Upgrade - {green}OK{endc}" else: From 342fef51b2a9bf41c469860fa80d1fbd23593e54 Mon Sep 17 00:00:00 2001 From: yungwine Date: Mon, 27 Jan 2025 15:44:56 +0400 Subject: [PATCH 3/4] fix chown in restore_backup --- mytonctrl/scripts/restore_backup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mytonctrl/scripts/restore_backup.sh b/mytonctrl/scripts/restore_backup.sh index 005ee7d8..9058e91d 100644 --- a/mytonctrl/scripts/restore_backup.sh +++ b/mytonctrl/scripts/restore_backup.sh @@ -43,6 +43,8 @@ rm -rf /var/ton-work/db/keyring chown -R $user:$user ${tmp_dir}/mytoncore chown -R $user:$user ${tmp_dir}/keys +chown validator:validator ${tmp_dir}/keys +chown -R validator:validator ${tmp_dir}/db cp -rfp ${tmp_dir}/db /var/ton-work cp -rfp ${tmp_dir}/keys /var/ton-work From 9074f6f4b36d1ba6cf9d63bcd69b3adc20cc9c13 Mon Sep 17 00:00:00 2001 From: yungwine Date: Mon, 27 Jan 2025 15:45:11 +0400 Subject: [PATCH 4/4] abort restore_backup if no backup file --- mytonctrl/scripts/restore_backup.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mytonctrl/scripts/restore_backup.sh b/mytonctrl/scripts/restore_backup.sh index 9058e91d..042657d7 100644 --- a/mytonctrl/scripts/restore_backup.sh +++ b/mytonctrl/scripts/restore_backup.sh @@ -16,6 +16,10 @@ do esac done +if [ ! -f "$name" ]; then + echo "Backup file not found, aborting." + exit 1 +fi COLOR='\033[92m' ENDC='\033[0m'