Skip to content

Commit d613688

Browse files
authored
Merge pull request #430 from yungwine/tha
ton http api updates
2 parents f959971 + faf3489 commit d613688

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

mytoninstaller/mytoninstaller.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ def PrintLiteServerConfig(local, args):
195195
def CreateLocalConfigFile(local, args):
196196
initBlock = GetInitBlock()
197197
initBlock_b64 = dict2b64(initBlock)
198-
args = ["python3", "-m", "mytoninstaller", "-u", local.buffer.user, "-e", "clc", "-i", initBlock_b64]
198+
user = local.buffer.user or os.environ.get("USER", "root")
199+
args = ["python3", "-m", "mytoninstaller", "-u", user, "-e", "clc", "-i", initBlock_b64]
199200
run_as_root(args)
200201
#end define
201202

mytoninstaller/settings.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,36 @@ def EnableJsonRpc(local):
485485
color_print(text)
486486
#end define
487487

488+
def tha_exists():
489+
try:
490+
resp = requests.get('http://127.0.0.1:8801/healthcheck', timeout=3)
491+
except:
492+
return False
493+
if resp.status_code == 200 and resp.text == '"OK"':
494+
return True
495+
return False
496+
#end define
497+
488498
def enable_ton_http_api(local):
489-
local.add_log("start EnableTonHttpApi function", "debug")
499+
try:
500+
if not tha_exists():
501+
do_enable_ton_http_api(local)
502+
except Exception as e:
503+
local.add_log(f"Error in enable_ton_http_api: {e}", "warning")
504+
pass
505+
#end define
506+
507+
def do_enable_ton_http_api(local):
508+
local.add_log("start do_enable_ton_http_api function", "debug")
490509
if not os.path.exists('/usr/bin/ton/local.config.json'):
491510
from mytoninstaller.mytoninstaller import CreateLocalConfigFile
492511
CreateLocalConfigFile(local, [])
493512
ton_http_api_installer_path = pkg_resources.resource_filename('mytoninstaller.scripts', 'ton_http_api_installer.sh')
494513
exit_code = run_as_root(["bash", ton_http_api_installer_path])
495514
if exit_code == 0:
496-
text = "EnableTonHttpApi - {green}OK{endc}"
515+
text = "do_enable_ton_http_api - {green}OK{endc}"
497516
else:
498-
text = "EnableTonHttpApi - {red}Error{endc}"
517+
text = "do_enable_ton_http_api - {red}Error{endc}"
499518
color_print(text)
500519
#end define
501520

0 commit comments

Comments
 (0)