Skip to content

Commit 6920a43

Browse files
committed
add background mtc installation
1 parent 24a35a5 commit 6920a43

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed

mytoninstaller/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def download_archive_from_ts(local):
269269
for bag in block_bags + master_block_bags:
270270
subprocess.run(f'mv {downloads_path}/{bag["bag"]}/packages/*/* {import_dir}', shell=True)
271271
# subprocess.run(['rm', '-rf', f"{downloads_path}/{bag['bag']}"])
272-
subprocess.run(['rm', '-rf', downloads_path])
272+
subprocess.run(['rm', '-rf', downloads_path + '*'])
273273

274274
stop_service(local, "ton_storage") # stop TS
275275
disable_service(local, "ton_storage")

scripts/install.py

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def validate_http_url(value):
5555
return True
5656

5757

58-
def validate_digits(value):
58+
def validate_digits_or_empty(value):
59+
if value == "":
60+
return True
5961
try:
6062
int(value)
6163
return True
@@ -114,7 +116,7 @@ def run_cli():
114116
}
115117
archive_ttl = questionary.text(
116118
get_archive_ttl_message(temp_answers),
117-
validate=validate_digits
119+
validate=validate_digits_or_empty
118120
).unsafe_ask()
119121

120122
dump = None
@@ -131,6 +133,10 @@ def run_cli():
131133
validate=validate_shard_format
132134
).unsafe_ask()
133135

136+
background = questionary.confirm(
137+
"Do you want to run MyTonCtrl installation in the background?"
138+
).unsafe_ask()
139+
134140
answers = {
135141
"mode": mode,
136142
"network": network,
@@ -139,13 +145,14 @@ def run_cli():
139145
"archive-blocks": archive_blocks,
140146
"archive-ttl": archive_ttl,
141147
"dump": dump,
142-
"add-shard": add_shard
148+
"add-shard": add_shard,
149+
"background": background
143150
}
144151
print(answers)
145152
return answers
146153

147154

148-
def parse_args(answers: dict):
155+
def run_install(answers: dict) -> list:
149156
mode = answers["mode"]
150157
network = answers["network"].lower()
151158
config = answers["config"]
@@ -154,18 +161,23 @@ def parse_args(answers: dict):
154161
validator_mode = answers["validator-mode"]
155162
archive_blocks = answers["archive-blocks"]
156163
dump = answers["dump"]
164+
background = answers["background"]
157165

158-
res = f' -n {network}'
166+
command = ['bash', 'install.sh']
167+
args = f' -n {network}'
168+
169+
user = os.environ.get("SUDO_USER") or os.environ.get("USER")
170+
args += f' -u {user}'
159171

160172
if network not in ('mainnet', 'testnet'):
161-
res += f' -c {config}'
173+
args += f' -c {config}'
162174

163175
if archive_ttl:
164-
os.putenv('ARCHIVE_TTL', archive_ttl) # set env variable
176+
os.environ['ARCHIVE_TTL'] = archive_ttl # set env variable
165177
if add_shard:
166-
os.putenv('ADD_SHARD', add_shard)
178+
os.environ['ADD_SHARD'] = add_shard
167179
if archive_blocks:
168-
os.putenv('ARCHIVE_BLOCKS', archive_blocks)
180+
os.environ['ARCHIVE_BLOCKS'] = archive_blocks
169181

170182
if validator_mode and validator_mode not in ('Skip', 'Validator wallet'):
171183
if validator_mode == 'Nominator pool':
@@ -174,14 +186,34 @@ def parse_args(answers: dict):
174186
validator_mode = 'single-nominator'
175187
elif validator_mode == 'Liquid Staking':
176188
validator_mode = 'liquid-staking'
177-
res += f' -m {validator_mode}'
189+
args += f' -m {validator_mode}'
178190
else:
179-
res += f' -m {mode}'
191+
args += f' -m {mode}'
180192

181193
if dump:
182-
res += ' -d'
183-
184-
return res
194+
args += ' -d'
195+
196+
log = None
197+
stdin = None
198+
if background:
199+
os.environ['PYTHONUNBUFFERED'] = '1'
200+
log = open("mytonctrl_installation.log", "a")
201+
stdin=subprocess.DEVNULL
202+
command = ['nohup'] + command
203+
command += args.split()
204+
205+
print(command)
206+
207+
process = subprocess.Popen(
208+
command,
209+
stdout=log,
210+
stderr=log,
211+
stdin=stdin,
212+
)
213+
if not background:
214+
process.wait()
215+
if background:
216+
print("="*100 + f"\nRunning installation in the background. Check './mytonctrl_installation.log' for progress. PID: {process.pid}\n" + "="*100)
185217

186218

187219
def main():
@@ -190,10 +222,7 @@ def main():
190222
except KeyboardInterrupt:
191223
print("\nInstallation cancelled by user")
192224
return
193-
command = parse_args(answers)
194-
# subprocess.run('bash scripts/install.sh ' + command, shell=True)
195-
print('bash install.sh ' + command)
196-
subprocess.run(['bash', 'install.sh'] + command.split())
225+
run_install(answers)
197226

198227

199228
if __name__ == '__main__':

0 commit comments

Comments
 (0)