|
11 | 11 | from mypyconsole.mypyconsole import MyPyConsole |
12 | 12 |
|
13 | 13 | from mytoninstaller.config import GetLiteServerConfig, get_ls_proxy_config |
| 14 | +from mytoninstaller.node_args import get_node_args, set_node_arg |
14 | 15 | from mytoninstaller.utils import GetInitBlock |
15 | 16 | from mytoncore.utils import dict2b64, str2bool, b642dict |
16 | 17 |
|
@@ -62,6 +63,7 @@ def inject_globals(func): |
62 | 63 | console.name = "MyTonInstaller" |
63 | 64 | console.color = console.RED |
64 | 65 | console.AddItem("status", inject_globals(Status), "Print TON component status") |
| 66 | + console.AddItem("set_node_argument", inject_globals(set_node_argument), "Set node argument") |
65 | 67 | console.AddItem("enable", inject_globals(Enable), "Enable some function") |
66 | 68 | console.AddItem("update", inject_globals(Enable), "Update some function: 'JR' - jsonrpc. Example: 'update JR'") |
67 | 69 | console.AddItem("plsc", inject_globals(PrintLiteServerConfig), "Print lite-server config") |
@@ -111,16 +113,50 @@ def Status(local, args): |
111 | 113 | liteserver_key = keys_dir + "liteserver" |
112 | 114 | liteserver_pubkey = liteserver_key + ".pub" |
113 | 115 |
|
| 116 | + statuses = { |
| 117 | + 'Full node status': os.path.isfile(local.buffer.vconfig_path), |
| 118 | + 'Mytoncore status': os.path.isfile(local.buffer.mconfig_path), |
| 119 | + 'V.console status': os.path.isfile(server_key) or os.path.isfile(client_key), |
| 120 | + 'Liteserver status': os.path.isfile(liteserver_pubkey) |
| 121 | + } |
| 122 | + |
| 123 | + color_print("{cyan}===[ Services status ]==={endc}") |
| 124 | + for item in statuses.items(): |
| 125 | + status = '{green}enabled{endc}' if item[1] else '{red}disabled{endc}' |
| 126 | + color_print(f"{item[0]}: {status}") |
| 127 | + |
| 128 | + node_args = get_node_args() |
| 129 | + color_print("{cyan}===[ Node arguments ]==={endc}") |
| 130 | + for key, value in node_args.items(): |
| 131 | + print(f"{key}: {value}") |
| 132 | +#end define |
| 133 | + |
| 134 | + |
| 135 | +def restart_node(): |
| 136 | + exit_code = run_as_root(["systemctl", "daemon-reload"]) |
| 137 | + if not exit_code: |
| 138 | + raise Exception(f"`systemctl daemon-reload` failed with exit code {exit_code}") |
| 139 | + exit_code = run_as_root(["systemctl", "restart", "validator"]) |
| 140 | + if not exit_code: |
| 141 | + raise Exception(f"`systemctl restart validator` failed with exit code {exit_code}") |
| 142 | +#end define |
114 | 143 |
|
115 | | - fnStatus = os.path.isfile(local.buffer.vconfig_path) |
116 | | - mtcStatus = os.path.isfile(local.buffer.mconfig_path) |
117 | | - vcStatus = os.path.isfile(server_key) or os.path.isfile(client_key) |
118 | | - lsStatus = os.path.isfile(liteserver_pubkey) |
119 | 144 |
|
120 | | - print("Full node status:", fnStatus) |
121 | | - print("Mytoncore status:", mtcStatus) |
122 | | - print("V.console status:", vcStatus) |
123 | | - print("Liteserver status:", lsStatus) |
| 145 | +def set_node_argument(local, args): |
| 146 | + if len(args) < 1: |
| 147 | + color_print("{red}Bad args. Usage:{endc} set_node_argument <arg-name> [arg-value] [-d (to delete)]") |
| 148 | + return |
| 149 | + arg_name = args[0] |
| 150 | + if len(args) == 1: |
| 151 | + set_node_arg(arg_name) |
| 152 | + else: |
| 153 | + arg_value = args[1] |
| 154 | + if arg_value == "-d": |
| 155 | + set_node_arg(arg_name, None) |
| 156 | + else: |
| 157 | + set_node_arg(arg_name, arg_value) |
| 158 | + restart_node() |
| 159 | + color_print("set_node_argument - {green}OK{endc}") |
124 | 160 | #end define |
125 | 161 |
|
126 | 162 |
|
|
0 commit comments