-
Notifications
You must be signed in to change notification settings - Fork 13
/
control.sh
255 lines (234 loc) · 5.51 KB
/
control.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
## control.sh
## Version 0.9.5.1
## Tested with jq 1.5.1 on Ubuntu 16.04.1
#!/bin/bash
SH_FILE="check_height_and_rebuild.sh"
LOG_FILE="heightRebuild.log"
CONSENSUS_SH_FILE="check_consensus.sh"
CONSENSUS_LOG_FILE="consensus.log"
MANAGE_SH_FILE="manage.sh"
MANAGE_LOG_FILE="manage.log"
start_height() {
## Check for config file
CONFIG_FILE="mrv_config.json"
if [[ ! -e "$CONFIG_FILE" ]] ; then
wget "https://raw.githubusercontent.com/mrv777/LiskScripts/master/mrv_config.json"
PS3='Please select an editor to input config details: '
options=("nano" "vi")
select opt in "${options[@]}"
do
case $opt in
"nano")
nano mrv_config.json
break
;;
"vi")
vi mrv_config.json
break
;;
*) echo invalid option;;
esac
done
fi
if [[ ! -e "$LOG_FILE" ]] ; then
touch "$LOG_FILE"
fi
if [[ ! -e "$SH_FILE" ]] ; then
wget "https://raw.githubusercontent.com/mrv777/LiskScripts/master/check_height_and_rebuild.sh"
fi
echo "Starting heightRebuild Script"
nohup bash $SH_FILE -S $SRV > $LOG_FILE 2>&1& ## SRV???
}
check_height_running() {
# Check if it is running
if pgrep -fl $SH_FILE > /dev/null
then
echo "Killing heightRebuild process"
pkill -f $SH_FILE -9
else
echo "heightRebuild is not currently running"
fi
}
upgrade_height() {
if [[ -e "$SH_FILE" ]] ;
then
rm "$SH_FILE"
fi
wget "https://raw.githubusercontent.com/mrv777/LiskScripts/master/check_height_and_rebuild.sh"
echo "Starting heightRebuild Script"
nohup bash $SH_FILE -S $SRV > $LOG_FILE 2>&1&
}
start_consensus() {
## Check for config file
CONFIG_FILE="mrv_config.json"
if [[ ! -e "$CONFIG_FILE" ]] ; then
wget "https://raw.githubusercontent.com/mrv777/LiskScripts/master/mrv_config.json"
PS3='Please select an editor to input config details: '
options=("nano" "vi")
select opt in "${options[@]}"
do
case $opt in
"nano")
nano mrv_config.json
break
;;
"vi")
vi mrv_config.json
break
;;
*) echo invalid option;;
esac
done
fi
if [[ ! -e "$CONSENSUS_LOG_FILE" ]] ; then
touch "$CONSENSUS_LOG_FILE"
fi
if [[ ! -e "$CONSENSUS_SH_FILE" ]] ; then
wget "https://raw.githubusercontent.com/mrv777/LiskScripts/master/check_consensus.sh"
fi
echo "Starting consensus Script"
nohup bash $CONSENSUS_SH_FILE -S $SRV > $CONSENSUS_LOG_FILE 2>&1&
}
check_consensus_running() {
# Check if it is running
if pgrep -fl $CONSENSUS_SH_FILE > /dev/null
then
echo "Killing consensus process"
pkill -f $CONSENSUS_SH_FILE -9
else
echo "Consensus is not currently running"
fi
}
upgrade_consensus() {
if [[ -e "$CONSENSUS_SH_FILE" ]] ;
then
rm "$CONSENSUS_SH_FILE"
fi
wget "https://raw.githubusercontent.com/mrv777/LiskScripts/master/check_consensus.sh"
echo "Starting consensus Script"
nohup bash $CONSENSUS_SH_FILE -S $SRV > $CONSENSUS_SH_FILE 2>&1&
}
start_manage() {
if [[ ! -e "$MANAGE_LOG_FILE" ]] ; then
touch "$MANAGE_LOG_FILE"
fi
if [[ ! -e "$MANAGE_SH_FILE" ]] ; then
wget "https://raw.githubusercontent.com/mrv777/LiskScripts/master/manage.sh"
fi
echo "Starting Management Script"
nohup bash $MANAGE_SH_FILE -S $SRV > $MANAGE_LOG_FILE 2>&1&
}
check_manage_running() {
# Check if it is running
if pgrep -fl $MANAGE_SH_FILE > /dev/null
then
echo "Killing management script process"
pkill -f $MANAGE_SH_FILE -9
else
echo "Management script is not currently running"
fi
}
status() {
# Check if consensus is running
if pgrep -fl $CONSENSUS_SH_FILE > /dev/null
then
echo "Consensus is running"
else
echo "Consensus is not currently running"
fi
# Check if heightRebuild is running
if pgrep -fl $SH_FILE > /dev/null
then
echo "HeightRebuild is running"
else
echo "HeightRebuild is not currently running"
fi
# Check if manage.sh is running
if pgrep -fl $MANAGE_SH_FILE > /dev/null
then
echo "Management script is running"
else
echo "Management script is not currently running"
fi
}
logs() {
LOG_FILES=""
if [[ -e "$LOG_FILE" ]] ; then
LOG_FILES+="-cT ANSI "$LOG_FILE" "
fi
if [[ -e "$CONSENSUS_LOG_FILE" ]] ; then
LOG_FILES+="-cT ANSI "$CONSENSUS_LOG_FILE" "
fi
if [[ -e "$MANAGE_LOG_FILE" ]] ; then
LOG_FILES+="-cT ANSI "$MANAGE_LOG_FILE" "
fi
multitail $LOG_FILES
}
usage() {
echo "Usage: $0 <start|stop|upgrade>"
echo "start -- starts consensus & height_rebuild scripts"
echo "startc -- starts consensus script"
echo "starth -- starts height_rebuild script"
echo "startm -- starts manage script"
echo "stop -- stops all scripts"
echo "stopc -- stops consensus script"
echo "stoph -- stops height_rebuild script"
echo "stopm -- stops manage script"
echo "status -- check if scripts are running"
echo "logs -- display all logs (requires multitail)"
echo "upgrade -- upgrades and runs both scripts"
}
case $1 in
"start" )
check_height_running
start_height
check_consensus_running
start_consensus
;;
"startc" )
check_consensus_running
start_consensus
;;
"starth" )
check_height_running
start_height
;;
"startm" )
check_manage_running
start_manage
;;
"stop" )
check_height_running
check_consensus_running
check_manage_running
;;
"stopc" )
check_consensus_running
;;
"stoph" )
check_height_running
;;
"stopm" )
check_manage_running
;;
"status" )
status
;;
"logs" )
logs
;;
"upgrade" )
check_height_running
check_consensus_running
upgrade_height
upgrade_consensus
;;
*)
echo "Error: Unrecognized command."
echo ""
echo "Available commands are: "
usage
exit 1
exit 1
;;
esac