-
Notifications
You must be signed in to change notification settings - Fork 23
/
daemons-restart.sh
executable file
·170 lines (135 loc) · 4.17 KB
/
daemons-restart.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
# this script restarts all started komodo daemons with same params
CUR_DIR=$(pwd)
komodo_cli="$HOME/komodo/src/komodo-cli"
komodo_daemon="$HOME/komodo/src/komodod"
# NB! path to search assetchains.json will be derived from komodod location, in this example
# assetchains.json should be available in $HOME/komodo/src .
function init_colors ()
{
RESET="\033[0m"
BLACK="\033[30m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
MAGENTA="\033[35m"
CYAN="\033[36m"
WHITE="\033[37m"
}
# --------------------------------------------------------------------------
function log_print()
{
datetime=$(date '+%Y-%m-%d %H:%M:%S')
echo -e [$datetime] $1
}
# --------------------------------------------------------------------------
function wait_for_daemon()
{
#if [[ ! -z $1 && $1 != "KMD" ]]
if [ ! -z $1 ] && [ $1 != "KMD" ]
then
coin=$1
asset=" -ac_name=$1"
else
coin="KMD"
asset=""
fi
i=0
while ! $komodo_cli $asset getinfo >/dev/null 2>&1
do
i=$((i+1))
log_print "Waiting for daemon start/active $coin ($i)"
sleep 1
# TODO: in case if daemon start too long, for example, more than 5-7 mins. we should exit from script
done
}
# --------------------------------------------------------------------------
function stop_daemon()
{
#if [[ ! -z $1 && $1 != "KMD" ]]
if [ ! -z $1 ] && [ $1 != "KMD" ]
then
coin=$1
asset=" -ac_name=$1"
else
coin="KMD"
asset=""
fi
i=0
$komodo_cli $asset stop
if [ $coin == "KMD" ]
then
ddatadir=$HOME/.komodo
else
ddatadir=$HOME/.komodo/$coin
fi
while [ -f $ddatadir/komodod.pid ]
do
i=$((i+1))
log_print "Waiting for daemon $coin stop ($i)"
sleep 1
done
while [ ! -z $(lsof -Fp $ddatadir/.lock | head -1 | cut -c 2-) ]
do
i=$((i+1))
log_print "Waiting for .lock release by $coin ($i)"
sleep 1
done
}
# --------------------------------------------------------------------------
function restart_daemon() {
if [ ! -z $1 ] && [ $1 != "KMD" ]
then
coin=$1
asset=" -ac_name=$1"
else
coin="KMD"
asset=""
fi
log_print "Process ($coin) ..."
wait_for_daemon $coin
# disable generate to avoid daemon crash during multiple "error adding notary vin" messages
$komodo_cli $asset setgenerate false
blockhash=$($komodo_cli $asset getbestblockhash)
height=$($komodo_cli $asset getblock $blockhash | jq .height)
log_print "ht.$height ($blockhash)"
if [ $coin == "KMD" ]
then
daemon_args=$(ps -fC komodod | grep -v -- "-ac_name=" | grep -Po "komodod .*" | sed 's/komodod//g')
else
daemon_args=$(ps -fC komodod | grep -- "-ac_name=$coin" | grep -Po "komodod .*" | sed 's/komodod//g')
fi
# if previous time daemon launched with reindex or rescan, we don't need to re-launch daemon with same params,
# so, we just remove them from launch string.
daemon_args=$(echo $daemon_args | sed -e "s/-reindex//g")
daemon_args=$(echo $daemon_args | sed -e "s/-rescan//g")
log_print "($coin) Args: \"$daemon_args\""
# TODO: check args, if we can't get arg and can't start daemon, don't need to stop it (!)
log_print "Stopping daemon ... "
stop_daemon $coin
sleep 5
log_print "Starting daemon ($coin) ... "
# *** STARTING DAEMON ***
$komodo_daemon $daemon_args &
wait_for_daemon $coin
log_print "Done process ($coin)"
}
STEP_START='\e[1;47;42m'
STEP_END='\e[0m'
init_colors
echo Current directory: $CUR_DIR
#log_print "$STEP_START[ Step 1 ]$STEP_END Daemons re-start"
#cd $CUR_DIR/komodo/src
# source $CUR_DIR/kmd_coins.sh
readarray -t kmd_coins < <(cat $(dirname ${komodo_daemon})/assetchains.json | jq -r '[.[].ac_name] | join("\n")')
# printf '%s\n' "${kmd_coins[@]}"
for i in "${kmd_coins[@]}"
do
# VRSC uses different daemon, so we don't need to re-start it from komodo repo folder
if [ $i != "VRSC" ] && [ $i != "THC" ]; then
log_print "$STEP_START[ $i ]$STEP_END"
restart_daemon $i
fi
done
#cd $CUR_DIR