Skip to content

Commit 7128e9c

Browse files
committed
add setting external ip if only_mtc
1 parent 972e267 commit 7128e9c

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

mytonctrl/scripts/restore_backup.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ echo -e "${COLOR}[2/4]${ENDC} Extracted files from archive"
4848

4949
rm -r /var/ton-work/db/dht-*
5050

51-
python3 -c "import json;path='/var/ton-work/db/config.json';f=open(path);d=json.load(f);f.close();d['addrs'][0]['ip']=int($ip);f=open(path, 'w');f.write(json.dumps(d, indent=4));f.close()"
51+
if [ $ip -ne 0 ]; then
52+
echo "Replacing IP in node config"
53+
python3 -c "import json;path='/var/ton-work/db/config.json';f=open(path);d=json.load(f);f.close();d['addrs'][0]['ip']=int($ip);f=open(path, 'w');f.write(json.dumps(d, indent=4));f.close()"
54+
else
55+
echo "IP is not provided, skipping IP replacement"
56+
fi
5257

53-
echo -e "${COLOR}[3/4]${ENDC} Deleted DHT files, replaced IP in node config"
58+
echo -e "${COLOR}[3/4]${ENDC} Deleted DHT files"
5459

5560
systemctl start validator
5661
systemctl start mytoncore

mytoninstaller/settings.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
run_as_root,
1515
color_print,
1616
ip2int,
17-
Dict
17+
Dict, int2ip
1818
)
1919
from mytoninstaller.utils import StartValidator, StartMytoncore, start_service, stop_service, get_ed25519_pubkey
2020
from mytoninstaller.config import SetConfig, GetConfig, get_own_ip, backup_config
@@ -201,6 +201,8 @@ def FirstMytoncoreSettings(local):
201201
#end define
202202

203203
def EnableValidatorConsole(local):
204+
if local.buffer.only_mtc:
205+
return
204206
local.add_log("start EnableValidatorConsole function", "debug")
205207

206208
# Create variables
@@ -920,12 +922,25 @@ def EnableMode(local):
920922
subprocess.run(args)
921923

922924

925+
def set_external_ip(local, ip):
926+
mconfig_path = local.buffer.mconfig_path
927+
928+
mconfig = GetConfig(path=mconfig_path)
929+
930+
mconfig.liteClient.liteServer.ip = ip
931+
mconfig.validatorConsole.addr = f'{ip}:{mconfig.validatorConsole.addr.split(":")[1]}'
932+
933+
# write mconfig
934+
local.add_log("write mconfig", "debug")
935+
SetConfig(path=mconfig_path, data=mconfig)
936+
937+
923938
def ConfigureFromBackup(local):
939+
if not local.buffer.backup:
940+
return
924941
from mytoncore import MyTonCore
925942
from mypylib.mypylib import MyPyClass # todo move to file header
926943
from modules.backups import BackupModule
927-
if not local.buffer.backup:
928-
return
929944
mconfig_path = local.buffer.mconfig_path
930945
mconfig_dir = get_dir_from_path(mconfig_path)
931946
local.add_log("start ConfigureFromBackup function", "info")
@@ -935,3 +950,17 @@ def ConfigureFromBackup(local):
935950
ton.local.buffer.my_work_dir = mconfig_dir
936951
module = BackupModule(ton, local)
937952
module.restore_backup([backup_file, '-y'])
953+
954+
if local.buffer.only_mtc:
955+
local.add_log("Installing only mtc", "info")
956+
vconfig_path = local.buffer.vconfig_path
957+
vconfig = GetConfig(path=vconfig_path)
958+
try:
959+
node_ip = int2ip(vconfig['addrs'][0]['ip'])
960+
except:
961+
local.add_log("Can't get ip from validator", "error")
962+
return
963+
user = local.buffer.user
964+
args = ["chown", '-R', user + ':' + user, local.buffer.keys_dir]
965+
subprocess.run(args)
966+
set_external_ip(local, node_ip)

0 commit comments

Comments
 (0)