Skip to content

Commit e61f3b5

Browse files
committed
add --only-node flag
1 parent 9114bb2 commit e61f3b5

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

modules/backups.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def create_tmp_ton_dir(self):
2727
self.create_keyring(dir_name_db)
2828
return dir_name
2929

30+
@staticmethod
31+
def run_create_backup(args):
32+
backup_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/create_backup.sh')
33+
return subprocess.run(["bash", backup_script_path] + args, timeout=5)
34+
3035
def create_backup(self, args):
3136
if len(args) > 1:
3237
color_print("{red}Bad args. Usage:{endc} create_backup [filename]")
@@ -35,8 +40,7 @@ def create_backup(self, args):
3540
command_args = ["-m", self.ton.local.buffer.my_work_dir, "-t", tmp_dir]
3641
if len(args) == 1:
3742
command_args += ["-d", args[0]]
38-
backup_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/create_backup.sh')
39-
process = subprocess.run(["bash", backup_script_path] + command_args, timeout=5)
43+
process = self.run_create_backup(command_args)
4044

4145
if process.returncode == 0:
4246
color_print("create_backup - {green}OK{endc}")

mytoninstaller/mytoninstaller.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
enable_ls_proxy,
3131
enable_ton_storage,
3232
enable_ton_storage_provider,
33-
EnableMode, ConfigureFromBackup
33+
EnableMode, ConfigureFromBackup, ConfigureOnlyNode
3434
)
3535
from mytoninstaller.config import (
3636
CreateLocalConfig,
@@ -280,7 +280,8 @@ def General(local, console):
280280
ox = sys.argv.index("--only-mtc")
281281
local.buffer.only_mtc = str2bool(sys.argv[ox+1])
282282
if "--only-node" in sys.argv:
283-
pass
283+
ox = sys.argv.index("--only-node")
284+
local.buffer.only_node = str2bool(sys.argv[ox+1])
284285
if "--backup" in sys.argv:
285286
bx = sys.argv.index("--backup")
286287
backup = sys.argv[bx+1]
@@ -297,6 +298,7 @@ def General(local, console):
297298
CreateSymlinks(local)
298299
EnableMode(local)
299300
ConfigureFromBackup(local)
301+
ConfigureOnlyNode(local)
300302
#end define
301303

302304

mytoninstaller/settings.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,3 +960,20 @@ def ConfigureFromBackup(local):
960960
args = ["chown", '-R', user + ':' + user, local.buffer.keys_dir]
961961
subprocess.run(args)
962962
set_external_ip(local, node_ip)
963+
964+
965+
def ConfigureOnlyNode(local):
966+
if not local.buffer.only_node:
967+
return
968+
from modules.backups import BackupModule
969+
mconfig_path = local.buffer.mconfig_path
970+
mconfig_dir = get_dir_from_path(mconfig_path)
971+
local.add_log("start ConfigureOnlyNode function", "info")
972+
973+
process = BackupModule.run_create_backup(["-m", mconfig_dir, ])
974+
if process.returncode != 0:
975+
local.add_log("Backup creation failed", "error")
976+
return
977+
local.add_log("Backup successfully created. Use this file on the controller server with `--only-mtc` flag on installation.", "info")
978+
979+
stop_service(local, 'mytoncore')

scripts/install.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ show_help_and_exit() {
3232
echo ' -n NETWORK Specify the network (mainnet or testnet)'
3333
echo ' -v VERSION Specify the ton node version (commit, branch, or tag)'
3434
echo ' -u USER Specify the user to be used for MyTonCtrl installation'
35+
echo ' -p PATH Provide backup file for MyTonCtrl installation'
36+
echo ' -o Install only MyTonCtrl. Must be used with -p'
37+
echo ' -l Install only TON node'
3538
echo ' -h Show this help'
3639
exit
3740
}
@@ -46,11 +49,12 @@ telemetry=true
4649
ignore=false
4750
dump=false
4851
only_mtc=false
52+
only_node=false
4953
backup=none
5054
cpu_required=16
5155
mem_required=64000000 # 64GB in KB
5256

53-
while getopts ":c:tidoa:r:b:m:n:v:u:p:h" flag; do
57+
while getopts ":c:tidola:r:b:m:n:v:u:p:h" flag; do
5458
case "${flag}" in
5559
c) config=${OPTARG};;
5660
t) telemetry=false;;
@@ -64,6 +68,7 @@ while getopts ":c:tidoa:r:b:m:n:v:u:p:h" flag; do
6468
v) ton_node_version=${OPTARG};;
6569
u) user=${OPTARG};;
6670
o) only_mtc=true;;
71+
l) only_node=true;;
6772
p) backup=${OPTARG};;
6873
h) show_help_and_exit;;
6974
*)
@@ -154,7 +159,7 @@ if [ "${user}" = "" ]; then # no user
154159
fi
155160
fi
156161
echo "User: $user"
157-
python3 -m mytoninstaller -u ${user} -t ${telemetry} --dump ${dump} -m ${mode} --only-mtc ${only_mtc} --backup ${backup}
162+
python3 -m mytoninstaller -u ${user} -t ${telemetry} --dump ${dump} -m ${mode} --only-mtc ${only_mtc} --backup ${backup} --only-node ${only_node}
158163

159164
# set migrate version
160165
migrate_version=1

0 commit comments

Comments
 (0)