Skip to content

Commit 6f1b686

Browse files
committed
update installer status
1 parent c651f6e commit 6f1b686

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

mytoninstaller/mytoninstaller.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from mypyconsole.mypyconsole import MyPyConsole
1212

1313
from mytoninstaller.config import GetLiteServerConfig, get_ls_proxy_config
14+
from mytoninstaller.node_args import get_node_args
1415
from mytoninstaller.utils import GetInitBlock
1516
from mytoncore.utils import dict2b64, str2bool, b642dict
1617

@@ -111,16 +112,22 @@ def Status(local, args):
111112
liteserver_key = keys_dir + "liteserver"
112113
liteserver_pubkey = liteserver_key + ".pub"
113114

114-
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-
120-
print("Full node status:", fnStatus)
121-
print("Mytoncore status:", mtcStatus)
122-
print("V.console status:", vcStatus)
123-
print("Liteserver status:", lsStatus)
115+
statuses = {
116+
'Full node status': os.path.isfile(local.buffer.vconfig_path),
117+
'Mytoncore status': os.path.isfile(local.buffer.mconfig_path),
118+
'V.console status': os.path.isfile(server_key) or os.path.isfile(client_key),
119+
'Liteserver status': os.path.isfile(liteserver_pubkey)
120+
}
121+
122+
color_print("{cyan}===[ Services status ]==={endc}")
123+
for item in statuses.items():
124+
status = '{green}enabled{endc}' if item[1] else '{red}disabled{endc}'
125+
color_print(f"{item[0]}: {status}")
126+
127+
node_args = get_node_args()
128+
color_print("{cyan}===[ Node arguments ]==={endc}")
129+
for key, value in node_args.items():
130+
print(f"{key}: {value}")
124131
#end define
125132

126133

mytoninstaller/node_args.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
3+
def get_validator_service():
4+
path = '/etc/systemd/system/validator.service'
5+
with open(path, 'r') as f:
6+
return f.read()
7+
8+
9+
def get_node_start_command():
10+
service = get_validator_service()
11+
for line in service.split('\n'):
12+
if 'ExecStart' in line:
13+
return line.split('=')[1].strip()
14+
15+
16+
def get_node_args(command: str = None):
17+
if command is None:
18+
command = get_node_start_command()
19+
result = {}
20+
key = ''
21+
for c in command.split(' ')[1:]:
22+
if c.startswith('--') or c.startswith('-'):
23+
if key:
24+
result[key] = ''
25+
key = c
26+
elif key:
27+
result[key] = c
28+
key = ''
29+
return result
30+
31+
32+
def set_node_arg(arg_name: str, arg_value: str = ''):
33+
"""
34+
:param arg_name:
35+
:param arg_value: arg value. if None, remove the arg; if empty string, argument is set without value
36+
:return:
37+
"""
38+
assert arg_name.startswith('-'), 'arg_name must start with "-" or "--"'
39+
service = get_validator_service()
40+
command = get_node_start_command()
41+
if command is None:
42+
raise Exception('Cannot find node start command in service file')
43+
args = get_node_args(command)
44+
if arg_value is None:
45+
args.pop(arg_name, None)
46+
else:
47+
args[arg_name] = arg_value
48+
new_command = command.split(' ')[0] + ' ' + ' '.join([f'{k} {v}' for k, v in args.items()])
49+
new_service = service.replace(command, new_command)
50+
with open('/etc/systemd/system/validator.service', 'w') as f:
51+
f.write(new_service)

0 commit comments

Comments
 (0)