Skip to content

Commit 9e6952f

Browse files
committed
add env file with installation variables
1 parent 8313e1b commit 9e6952f

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

mytoninstaller/mytoninstaller.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
4040
from functools import partial
4141

4242

43+
def init_envs(local):
44+
local.buffer.cport = int(os.getenv('VALIDATOR_CONSOLE_PORT', random.randint(2000, 65000)))
45+
local.buffer.lport = int(os.getenv('LITESERVER_PORT', random.randint(2000, 65000)))
46+
local.buffer.vport = int(os.getenv('VALIDATOR_PORT', random.randint(2000, 65000)))
47+
local.buffer.archive_ttl = os.getenv('ARCHIVE_TTL')
48+
local.buffer.state_ttl = os.getenv('STATE_TTL')
49+
local.buffer.public_ip = os.getenv('PUBLIC_IP')
50+
local.buffer.add_shard = os.getenv('ADD_SHARD')
51+
local.buffer.archive_blocks = os.getenv('ARCHIVE_BLOCKS')
52+
local.buffer.collate_shard = os.getenv('COLLATE_SHARD', '')
53+
54+
4355
def Init(local, console):
4456
local.db.config.isStartOnlyOneProcess = False
4557
local.db.config.logLevel = "debug"
@@ -51,9 +63,7 @@ def Init(local, console):
5163
# create variables
5264
local.buffer.user = get_current_user()
5365
local.buffer.vuser = "validator"
54-
local.buffer.cport = int(os.getenv('VALIDATOR_CONSOLE_PORT', random.randint(2000, 65000)))
55-
local.buffer.lport = int(os.getenv('LITESERVER_PORT', random.randint(2000, 65000)))
56-
local.buffer.vport = int(os.getenv('VALIDATOR_PORT', random.randint(2000, 65000)))
66+
init_envs(local)
5767

5868
# this funciton injects MyPyClass instance
5969
def inject_globals(func):

mytoninstaller/settings.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ def FirstNodeSettings(local):
4747
vconfig_path = local.buffer.vconfig_path
4848
vport = local.buffer.vport
4949

50-
if os.getenv('ARCHIVE_TTL'):
51-
archive_ttl = int(os.getenv('ARCHIVE_TTL'))
50+
if local.buffer.archive_ttl is not None:
51+
archive_ttl = int(local.buffer.archive_ttl)
5252
else:
5353
archive_ttl = 2592000 if local.buffer.mode == 'liteserver' else 86400
5454
state_ttl = None
55-
if os.getenv('STATE_TTL'):
56-
state_ttl = int(os.getenv('STATE_TTL'))
55+
if local.buffer.state_ttl is not None:
56+
state_ttl = int(local.buffer.state_ttl)
5757
archive_ttl -= state_ttl
5858
if archive_ttl == 0:
5959
archive_ttl = 1 # todo: remove this when archive_ttl==0 will be allowed in node
@@ -93,16 +93,16 @@ def FirstNodeSettings(local):
9393
cmd = f"{validatorAppPath} --threads {cpus} --daemonize --global-config {globalConfigPath} --db {ton_db_dir} --logname {tonLogPath} --verbosity 1"
9494
cmd += ttl_cmd
9595

96-
if os.getenv('ADD_SHARD'):
97-
add_shard = os.getenv('ADD_SHARD')
96+
if local.buffer.add_shard is not None:
97+
add_shard = local.buffer.add_shard
9898
cmd += f' -M'
9999
for shard in add_shard.split():
100100
cmd += f' --add-shard {shard}'
101101

102102
add2systemd(name="validator", user=vuser, start=cmd, pre='/bin/sleep 2') # post="/usr/bin/python3 /usr/src/mytonctrl/mytoncore.py -e \"validator down\""
103103

104-
if os.getenv('PUBLIC_IP'):
105-
ip = os.getenv('PUBLIC_IP')
104+
if local.buffer.public_ip is not None:
105+
ip = local.buffer.public_ip
106106
else:
107107
ip = get_own_ip()
108108
addr = "{ip}:{vport}".format(ip=ip, vport=vport)
@@ -204,13 +204,13 @@ def parse_block_value(local, block: str):
204204

205205

206206
def download_archive_from_ts(local):
207-
archive_blocks = os.getenv('ARCHIVE_BLOCKS')
207+
if local.buffer.archive_blocks is None:
208+
return
209+
archive_blocks = local.buffer.archive_blocks
208210
downloads_path = '/var/ton-work/ts-downloads/'
209211
os.makedirs(downloads_path, exist_ok=True)
210212
subprocess.run(["chmod", "o+wx", downloads_path])
211213

212-
if archive_blocks is None:
213-
return
214214
block_from, block_to = archive_blocks, None
215215
if len(archive_blocks.split()) > 1:
216216
block_from, block_to = archive_blocks.split()
@@ -1189,7 +1189,7 @@ def SetInitialSync(local):
11891189
def SetupCollator(local):
11901190
if local.buffer.mode != "collator":
11911191
return
1192-
shards = os.getenv('COLLATE_SHARD', '').split()
1192+
shards = local.buffer.collate_shard.split()
11931193
if not shards:
11941194
shards = ['0:8000000000000000']
11951195
local.add_log(f"Setting up collator for shards: {shards}", "info")

scripts/install.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config_overridden=false
2323
show_help_and_exit() {
2424
echo 'Supported arguments:'
2525
echo ' -c, --config URL Provide custom network config'
26+
echo ' -e, --env-file PATH Provide env file with installation parameters'
2627
echo ' -t, --telemetry Disable telemetry'
2728
echo ' -i, --ignore-reqs Ignore minimum requirements'
2829
echo ' -d, --dump Use pre-packaged dump. Reduces duration of initial synchronization.'
@@ -47,6 +48,7 @@ fi
4748

4849
# node install parameters
4950
config="https://ton-blockchain.github.io/global.config.json"
51+
env_file=""
5052
telemetry=true
5153
ignore=false
5254
dump=false
@@ -77,7 +79,7 @@ while (($#)); do
7779
--ignore-reqs) newargv+=(-i) ;;
7880

7981
# with arg
80-
--config|--author|--repo|--branch|--mode|--network|--node-repo|--backup|--user)
82+
--config|--author|--repo|--branch|--mode|--network|--node-repo|--backup|--user|--node-version|--env-file)
8183
if (($# < 2)); then
8284
echo "Error: option $1 requires value" >&2; exit 2
8385
fi
@@ -92,6 +94,7 @@ while (($#)); do
9294
--backup) newargv+=(-p "$2") ;;
9395
--user) newargv+=(-u "$2") ;;
9496
--node-version) newargv+=(-v "$2") ;;
97+
--env-file) newargv+=(-e "$2") ;;
9598
esac
9699
shift ;;
97100
--*)
@@ -106,7 +109,7 @@ done
106109
#printf '\n'
107110
set -- "${newargv[@]}"
108111

109-
while getopts ":c:tidola:r:b:m:n:v:u:p:g:h" flag; do
112+
while getopts ":c:tidola:r:b:m:n:v:u:p:g:e:h" flag; do
110113
case "${flag}" in
111114
c) config=${OPTARG}; config_overridden=true;;
112115
t) telemetry=false;;
@@ -123,13 +126,23 @@ while getopts ":c:tidola:r:b:m:n:v:u:p:g:h" flag; do
123126
o) only_mtc=true;;
124127
l) only_node=true;;
125128
p) backup=${OPTARG};;
129+
e) env_file=${OPTARG};;
126130
h) show_help_and_exit;;
127131
*)
128132
echo "Flag -${flag} is not recognized. Aborting"
129133
exit 1 ;;
130134
esac
131135
done
132136

137+
if [ -n "$env_file" ]; then
138+
if [ ! -f "$env_file" ]; then
139+
echo "Env file not found, aborting."
140+
exit 1
141+
fi
142+
set -a
143+
source "$env_file"
144+
set +a
145+
fi
133146

134147
if [ "$only_mtc" = true ] && [ "$backup" = "none" ]; then
135148
echo "Backup file must be provided if only mtc installation"

0 commit comments

Comments
 (0)