/
xcash-maintenance
executable file
路395 lines (327 loc) 路 21 KB
/
xcash-maintenance
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#!/bin/bash
# Adjust this variable to the name of your xcash-daemon unit file name
XCASH_DAEMON_SRV=xcash-daemon
# Adjust this variable to the name of your xcash-wallets unit file name
XCASH_WALLET_SRV=xcash-rpc-wallet
# Adjust this variable to the name of your xcash-dpops unit file name
XCASH_DPOPS_SRV=xcash-dpops
# Adjust this variable to the name of your mongodb unit file name
MONGODB_SRV=mongodb
XCASH_DAEMON_LOG_FILE=~/xcash-official/logs/xcash-daemon-log.txt
XCASH_WALLET_LOG_FILE=~/xcash-official/logs/xcash-wallet-rpc.log
### CUSTOM VARIABLES ###
DAEMON_URL="http://127.0.0.1:18281/json_rpc"
WALLET_URL="http://127.0.0.1:18285/json_rpc"
DPOPS_QUERY=('curl -s -H "Content-Type: application/json" -X GET http://127.0.0.1:18283')
CURL=('curl -w "\n" -s -H "Content-Type: application/json" -X')
SEED_NODE1_URL="http://us1.xcash.foundation:18281/json_rpc"
SEED_NODE2_URL="http://oceania1.xcash.foundation:18281/json_rpc"
SEED_NODE3_URL="http://europe1.xcash.foundation:18281/json_rpc"
SEED_NODE4_URL="http://europe2.xcash.foundation:18281/json_rpc"
SEED_NODE5_URL="http://europe3.xcash.foundation:18281/json_rpc"
declare -ir TOTAL_DELEGATES=50
declare -ir ATOMIC_DIVISOR=1000000
# Color print variables
COLOR_PRINT_RED="\033[1;31m"
COLOR_PRINT_GREEN="\033[1;32m"
END_COLOR_PRINT="\033[0m"
PS3='
Please enter an option: '
options=(
"Check blockchain height"
"Get node statistics"
"Get node balance"
"Check services status"
"Start stopped services"
"Stop all services"
"Restart all services"
"Enable services autostart"
"Disable services autostart"
"Get X-Cash DPoPS log"
"Get X-Cash Daemon log"
"Get X-Cash RPC Wallet log"
"Check X-Cash DPoPS log for malfunctioning block verifiers"
"Check X-Cash DPoPS log for shared delegate errors"
"Check if repositories are up to date"
"Quit"
)
function check_height(){
if lsof -Pi :18281 -sTCP:LISTEN -t >/dev/null ; then
DATA=$($CURL GET $DAEMON_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}')
SEED_NODE1_DATA=$($CURL GET $SEED_NODE1_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}')
SEED_NODE1_HEIGHT=$(($(echo "$SEED_NODE1_DATA" | grep '"count"' | awk '{print $2}' | sed s'|,||g' | tr -d $'\r') + 0))
SEED_NODE2_DATA=$($CURL GET $SEED_NODE2_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}')
SEED_NODE2_HEIGHT=$(($(echo "$SEED_NODE2_DATA" | grep '"count"' | awk '{print $2}' | sed s'|,||g' | tr -d $'\r') + 0))
SEED_NODE3_DATA=$($CURL GET $SEED_NODE3_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}')
SEED_NODE3_HEIGHT=$(($(echo "$SEED_NODE3_DATA" | grep '"count"' | awk '{print $2}' | sed s'|,||g' | tr -d $'\r') + 0))
SEED_NODE4_DATA=$($CURL GET $SEED_NODE4_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}')
SEED_NODE4_HEIGHT=$(($(echo "$SEED_NODE4_DATA" | grep '"count"' | awk '{print $2}' | sed s'|,||g' | tr -d $'\r') + 0))
SEED_NODE5_DATA=$($CURL GET $SEED_NODE5_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}')
SEED_NODE5_HEIGHT=$(($(echo "$SEED_NODE5_DATA" | grep '"count"' | awk '{print $2}' | sed s'|,||g' | tr -d $'\r') + 0))
HEIGHT=$(echo "$DATA" | grep '"count"' | awk '{print $2}' | sed s'|,||g' | tr -d $'\r')
STATUS_COUNT=0
if (( HEIGHT >= SEED_NODE1_HEIGHT && SEED_NODE1_HEIGHT != 0 )); then
(( STATUS_COUNT++ ))
fi
if (( HEIGHT >= SEED_NODE2_HEIGHT && SEED_NODE2_HEIGHT != 0 )); then
(( STATUS_COUNT++ ))
fi
if (( HEIGHT >= SEED_NODE3_HEIGHT && SEED_NODE3_HEIGHT != 0 )); then
(( STATUS_COUNT++ ))
fi
if (( HEIGHT >= SEED_NODE4_HEIGHT && SEED_NODE4_HEIGHT != 0 )); then
(( STATUS_COUNT++ ))
fi
if (( HEIGHT >= SEED_NODE5_HEIGHT && SEED_NODE5_HEIGHT != 0 )); then
(( STATUS_COUNT++ ))
fi
echo
if (( STATUS_COUNT >= 3 )); then
echo -e "Blockhain sync status: ${COLOR_PRINT_GREEN}OK${END_COLOR_PRINT}"
else
echo -e "Blockhain sync status: ${COLOR_PRINT_RED}FAIL${END_COLOR_PRINT}"
fi
echo "Blockchain height: $HEIGHT"
else
echo
echo "X-Cash Daemon service is not running...."
echo "Check the $XCASH_DAEMON_SRV service status"
fi
}
function get_node_balance(){
if lsof -Pi :18285 -sTCP:LISTEN -t >/dev/null ; then
DATA=$($CURL GET $WALLET_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_balance","params":{"account_index":0,"address_indices":[0]}}')
ADDR=$(echo "$DATA" | grep '"address"' | awk '{print $2}' | sed s'|"||g' | sed s'|,||g' | head -1 | tr -d $'\r')
UNSPENT_OUTPUTS=$(echo "$DATA" | grep '"num_unspent_outputs"' | awk '{print $2}' | sed s'|"||g' | sed s'|,||g' | head -1 | tr -d $'\r')
ATOMIC_TOTAL_BALANCE=$(echo "$DATA" | grep '"balance"' | awk '{print $2}' | sed s'|,||g' | head -1 | tr -d $'\r')
ATOMIC_UNLOCKED_BALANCE=$(echo "$DATA" | grep '"unlocked_balance"' | awk '{print $2}' | sed s'|,||g' | head -1 | sed s"|^M||g" | tr -d $'\r')
TOTAL_BALANCE=$((ATOMIC_TOTAL_BALANCE/ATOMIC_DIVISOR))
UNLOCKED_BALANCE=$((ATOMIC_UNLOCKED_BALANCE/ATOMIC_DIVISOR))
echo
echo "Public address: $ADDR"
echo "Unspent outputs: $UNSPENT_OUTPUTS"
echo "Total balance: $TOTAL_BALANCE XCASH"
echo "Unlocked balance: $UNLOCKED_BALANCE XCASH"
else
echo
echo "X-Cash RCP Wallet service is not running...."
echo "Check the $XCASH_WALLET_SRV service status"
fi
}
function shared_delegates_website_statistics(){
if lsof -Pi :18283 -sTCP:LISTEN -t >/dev/null ; then
DATA=$($DPOPS_QUERY/shareddelegateswebsitegetstatistics | python3 -m json.tool)
RANK=$(echo "$DATA" | grep '"current_delegate_rank"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')
TOTAL_VOTES=$(($(echo "$DATA" | grep '"total_votes"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')/ATOMIC_DIVISOR))
ONLINE_PCT=$(echo "$DATA" | grep '"online_percentage"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')
ROUNDS=$(echo "$DATA" | grep '"block_verifier_total_rounds"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')
BLOCKS_FOUND=$(echo "$DATA" | grep '"total_blocks_found"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')
XCASH_FOUND=$(($(echo "$DATA" | grep '"total_xcash_from_blocks_found"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')/ATOMIC_DIVISOR))
TOTAL_PAYMENTS=$(echo "$DATA" | grep '"total_payments"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')
VOTERS=$(echo "$DATA" | grep '"total_voters"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')
FEE=$(echo "$DATA" | grep '"fee"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')
MIN_AMOUNT=$(echo "$DATA" | grep '"minimum_amount"' | awk '{print $2}' | sed s'|,||g' | sed s'|"||g' | tr -d $'\r')
echo
echo "######### DELEGATE STATUS #########"
if (( RANK <= TOTAL_DELEGATES )); then
echo -e "Rank....................${COLOR_PRINT_GREEN}$RANK${END_COLOR_PRINT}"
else
echo -e "Rank....................${COLOR_PRINT_RED}$RANK${END_COLOR_PRINT}"
fi
echo "Total Votes.............$TOTAL_VOTES XCASH"
echo "Online Percentage.......$ONLINE_PCT %"
echo "Total Rounds............$ROUNDS"
echo "Blocks Found............$BLOCKS_FOUND"
echo "X-Cash Found............$XCASH_FOUND XCASH"
echo "Total Payments..........$TOTAL_PAYMENTS"
echo "Total Voters............$VOTERS"
echo "Fee.....................$FEE %"
echo "Minimum Amount..........$MIN_AMOUNT XCASH"
else
echo
echo "X-Cash DPoPS service is not running...."
echo "Check the $XCASH_DPOPS_SRV service status"
fi
}
function check_services_status(){
echo
MONGODB_UP_SINCE=$(systemctl show $MONGODB_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
XCASH_DAEMON_UP_SINCE=$(systemctl show $XCASH_DAEMON_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
XCASH_WALLET_UP_SINCE=$(systemctl show $XCASH_WALLET_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
XCASH_DPOPS_UP_SINCE=$(systemctl show $XCASH_DPOPS_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
systemctl is-active $MONGODB_SRV --quiet \
&& echo -e "${COLOR_PRINT_GREEN}"\\u2714 MongoDB service is running since..............."$MONGODB_UP_SINCE""${END_COLOR_PRINT}" \
|| echo -e "${COLOR_PRINT_RED}"\\u2716 MongoDB service is not running"${END_COLOR_PRINT}"
systemctl is-active $XCASH_DAEMON_SRV --quiet \
&& echo -e "${COLOR_PRINT_GREEN}"\\u2714 X-Cash Daemon service is running since........."$XCASH_DAEMON_UP_SINCE""${END_COLOR_PRINT}" \
|| echo -e "${COLOR_PRINT_RED}"\\u2716 X-Cash Daemon service is not running"${END_COLOR_PRINT}"
systemctl is-active $XCASH_WALLET_SRV --quiet \
&& echo -e "${COLOR_PRINT_GREEN}"\\u2714 X-Cash RPC Wallet service is running since....."$XCASH_WALLET_UP_SINCE""${END_COLOR_PRINT}" \
|| echo -e "${COLOR_PRINT_RED}"\\u2716 X-Cash RPC Wallet service is not running"${END_COLOR_PRINT}"
systemctl is-active $XCASH_DPOPS_SRV --quiet \
&& echo -e "${COLOR_PRINT_GREEN}"\\u2714 X-Cash DPoPS service is running since.........."$XCASH_DPOPS_UP_SINCE""${END_COLOR_PRINT}" \
|| echo -e "${COLOR_PRINT_RED}"\\u2716 X-Cash DPoPS service is not running"${END_COLOR_PRINT}"
}
function start_stopped_services(){
echo
if (systemctl is-active $MONGODB_SRV --quiet); then
MONGODB_UP_SINCE=$(systemctl show $MONGODB_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
echo -e "${COLOR_PRINT_GREEN}"\\u2714 MongoDB service is running since..............."$MONGODB_UP_SINCE""${END_COLOR_PRINT}"
else
echo -en "${COLOR_PRINT_RED}"\\u2716 MongoDB service is not running, starting it............."${END_COLOR_PRINT}"
systemctl start $MONGODB_SRV && sleep 3
systemctl is-active $MONGODB_SRV --quiet \
&& echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}"
fi
if (systemctl is-active $XCASH_DAEMON_SRV --quiet); then
XCASH_DAEMON_UP_SINCE=$(systemctl show $XCASH_DAEMON_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
echo -e "${COLOR_PRINT_GREEN}"\\u2714 X-Cash Daemon service is running since........."$XCASH_DAEMON_UP_SINCE""${END_COLOR_PRINT}"
else
echo -en "${COLOR_PRINT_RED}"\\u2716 X-Cash Daemon service is not running, starting it......."${END_COLOR_PRINT}"
systemctl start $XCASH_DAEMON_SRV && sleep 3
systemctl is-active $XCASH_DAEMON_SRV --quiet \
&& echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}"
fi
if (systemctl is-active $XCASH_WALLET_SRV --quiet); then
XCASH_WALLET_UP_SINCE=$(systemctl show $XCASH_WALLET_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
echo -e "${COLOR_PRINT_GREEN}"\\u2714 X-Cash RPC Wallet service is running since....."$XCASH_WALLET_UP_SINCE""${END_COLOR_PRINT}"
else
echo -en "${COLOR_PRINT_RED}"\\u2716 X-Cash RPC Wallet service is not running, starting it..."${END_COLOR_PRINT}" \
&& systemctl start $XCASH_WALLET_SRV && sleep 3 \
&& systemctl is-active $XCASH_WALLET_SRV --quiet \
&& echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}"
fi
if (systemctl is-active $XCASH_DPOPS_SRV --quiet); then
XCASH_DPOPS_UP_SINCE=$(systemctl show $XCASH_DPOPS_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
echo -e "${COLOR_PRINT_GREEN}"\\u2714 X-Cash DPoPS service is running since.........."$XCASH_DPOPS_UP_SINCE""${END_COLOR_PRINT}"
else
echo -en "${COLOR_PRINT_RED}"\\u2716 X-Cash DPoPS service is not running, starting it........"${END_COLOR_PRINT}"
systemctl start $XCASH_DPOPS_SRV && sleep 3
systemctl is-active $XCASH_DPOPS_SRV --quiet \
&& echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}"
fi
}
function stop_all_services(){
echo
echo -en "${COLOR_PRINT_GREEN}"Stopping X-Cash DPoPS service..............................................."${END_COLOR_PRINT}" \
&& systemctl stop $XCASH_DPOPS_SRV && systemctl is-active $XCASH_DPOPS_SRV --quiet && echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Stopping MongoDB service...................................................."${END_COLOR_PRINT}" \
&& systemctl stop $MONGODB_SRV && systemctl is-active $MONGODB_SRV --quiet && echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Stopping X-Cash RPC Wallet service.........................................."${END_COLOR_PRINT}" \
&& systemctl stop $XCASH_WALLET_SRV && systemctl is-active $XCASH_WALLET_SRV --quiet && echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Stopping X-Cash Daemon service.............................................."${END_COLOR_PRINT}" \
&& systemctl stop $XCASH_DAEMON_SRV && systemctl is-active $XCASH_DAEMON_SRV --quiet && echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}"
}
function restart_all_services(){
echo
echo -en "${COLOR_PRINT_GREEN}"Stopping X-Cash DPoPS service..............................................."${END_COLOR_PRINT}" \
&& systemctl stop $XCASH_DPOPS_SRV && systemctl is-active $XCASH_DPOPS_SRV --quiet && echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Stopping MongoDB service...................................................."${END_COLOR_PRINT}" \
&& systemctl stop $MONGODB_SRV && systemctl is-active $MONGODB_SRV --quiet && echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Stopping X-Cash RPC Wallet service.........................................."${END_COLOR_PRINT}" \
&& systemctl stop $XCASH_WALLET_SRV && systemctl is-active $XCASH_WALLET_SRV --quiet && echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Stopping X-Cash Daemon service.............................................."${END_COLOR_PRINT}" \
&& systemctl stop $XCASH_DAEMON_SRV && systemctl is-active $XCASH_DAEMON_SRV --quiet && echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Starting X-Cash Daemon service.............................................."${END_COLOR_PRINT}" \
&& sleep 3 && systemctl start $XCASH_DAEMON_SRV && sleep 5 && systemctl is-active $XCASH_DAEMON_SRV --quiet && echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Starting X-Cash Wallet service.............................................."${END_COLOR_PRINT}" \
&& sleep 3 && systemctl start $XCASH_WALLET_SRV && sleep 5 && systemctl is-active $XCASH_WALLET_SRV --quiet && echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Starting MongoDB service...................................................."${END_COLOR_PRINT}" \
&& sleep 3 && systemctl start $MONGODB_SRV && sleep 3 && systemctl is-active $MONGODB_SRV --quiet && echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}"
echo -en "${COLOR_PRINT_GREEN}"Starting X-Cash DPoPS service..............................................."${END_COLOR_PRINT}" \
&& sleep 3 && systemctl start $XCASH_DPOPS_SRV && systemctl is-active $XCASH_DPOPS_SRV --quiet && echo -e "${COLOR_PRINT_GREEN}"\\u2714"${END_COLOR_PRINT}" || echo -e "${COLOR_PRINT_RED}"\\u2716"${END_COLOR_PRINT}"
check_services_status
}
function get_xcash_dpops_log(){
# Read the log starting from end of file
journalctl --unit=xcash-dpops --output cat | less -R +G
}
function check_xcash_dpops_log_for_malfunctioning_block_verifiers(){
# check for the past week (288*110*7)
echo "Checking for the past week for any malfunctioning block verifiers"
journalctl --unit=xcash-dpops -n 221760 --output cat | less -R +G | grep "does not have a majority data. This block verifier is not working correctly"
}
function check_xcash_dpops_log_for_shared_delegate_errors(){
# check for the past week (288*110*7)
echo "Checking for the past week for any shared delegate errors"
journalctl --unit=xcash-dpops -n 221760 --output cat | less -R +G | grep -A 3 "Failed to send a transaction list"
journalctl --unit=xcash-dpops -n 221760 --output cat | less -R +G | grep -A 11 "Failed to update the database for a delegate"
}
function get_xcash_daemon_log(){
# Read the log starting from end of file
less -R +G $XCASH_DAEMON_LOG_FILE
}
function get_xcash_wallet_log(){
# Read the log starting from end of file
less -R +G $XCASH_WALLET_LOG_FILE
}
function enable_services_autostart(){
echo
echo -e "${COLOR_PRINT_GREEN}Enabling services autostart...${END_COLOR_PRINT}"
systemctl enable ${MONGODB_SRV}.service ${XCASH_DAEMON_SRV}.service ${XCASH_WALLET_SRV}.timer ${XCASH_DPOPS_SRV}.timer
systemctl disable ${XCASH_WALLET_SRV}.service ${XCASH_DPOPS_SRV}.service
ENABLED_SERVICES=$(systemctl list-unit-files --state=enabled | grep -wc "${MONGODB_SRV}.service\|${XCASH_DAEMON_SRV}.service\|${XCASH_WALLET_SRV}.timer\|${XCASH_DPOPS_SRV}.timer")
DISABLED_SERVICES=$(systemctl list-unit-files --state=disabled | grep -wc "${XCASH_WALLET_SRV}.service\|${XCASH_DPOPS_SRV}.service")
if (( ENABLED_SERVICES == 4 )) && (( DISABLED_SERVICES == 2 )); then
echo -e "${COLOR_PRINT_GREEN}done${END_COLOR_PRINT}"
else
echo -e "${COLOR_PRINT_RED}failed${END_COLOR_PRINT}"
fi
}
function disable_services_autostart(){
echo
echo -e "${COLOR_PRINT_GREEN}Disabling services autostart...${END_COLOR_PRINT}"
systemctl disable ${XCASH_WALLET_SRV}.service ${XCASH_DPOPS_SRV}.service ${MONGODB_SRV}.service ${XCASH_DAEMON_SRV}.service ${XCASH_WALLET_SRV}.timer ${XCASH_DPOPS_SRV}.timer
DISABLED_SERVICES=$(systemctl list-unit-files --state=disabled | grep -wc "${XCASH_WALLET_SRV}.service\|${XCASH_DPOPS_SRV}.service\|${MONGODB_SRV}.service\|${XCASH_DAEMON_SRV}.service\|${XCASH_WALLET_SRV}.timer\|${XCASH_DPOPS_SRV}.timer")
if (( DISABLED_SERVICES == 6 )); then
echo -e "${COLOR_PRINT_GREEN}done${END_COLOR_PRINT}"
else
echo -e "${COLOR_PRINT_RED}failed${END_COLOR_PRINT}"
fi
}
function check_repositories_status(){
XHOME=$(eval echo "~$USER")
echo
echo "Check if repos are up to date:"
(cd $XHOME/xcash-official/xcash-dpops && [ $(git rev-parse HEAD) = $(git ls-remote $(git rev-parse --abbrev-ref @{u} | sed 's/\// /g') | cut -f1) ] \
&& echo -e ${COLOR_PRINT_GREEN}xcash-dpops is up to date${END_COLOR_PRINT} || echo -e ${COLOR_PRINT_RED}xcash-dpops is not up to date${END_COLOR_PRINT} \
&& cd $XHOME/xcash-official/xcash-core && [ $(git rev-parse HEAD) = $(git ls-remote $(git rev-parse --abbrev-ref @{u} | sed 's/\// /g') | cut -f1) ] \
&& echo -e ${COLOR_PRINT_GREEN}xcash-core is up to date${END_COLOR_PRINT} || echo -e ${COLOR_PRINT_RED}xcash-core is not up to date${END_COLOR_PRINT})
echo
}
function get_overview(){
check_services_status
check_height
get_node_balance
shared_delegates_website_statistics
check_repositories_status
echo
}
while [ "$1" != "" ]; do
case $1 in
-s | --status | --overview ) get_overview
exit
esac
shift
done
select opt in "${options[@]}"; do
case $opt in
"Check blockchain height") check_height ;;
"Get node balance") get_node_balance ;;
"Get node statistics") shared_delegates_website_statistics;;
"Check services status") check_services_status ;;
"Start stopped services") start_stopped_services ;;
"Stop all services") stop_all_services ;;
"Restart all services") restart_all_services ;;
"Enable services autostart") enable_services_autostart ;;
"Disable services autostart") disable_services_autostart ;;
"Get X-Cash DPoPS log") get_xcash_dpops_log ;;
"Get X-Cash Daemon log") get_xcash_daemon_log ;;
"Get X-Cash RPC Wallet log") get_xcash_wallet_log ;;
"Check X-Cash DPoPS log for malfunctioning block verifiers") check_xcash_dpops_log_for_malfunctioning_block_verifiers ;;
"Check X-Cash DPoPS log for shared delegate errors") check_xcash_dpops_log_for_shared_delegate_errors ;;
"Check if repositories are up to date") check_repositories_status ;;
"Quit") break ;;
*) echo && echo "Invalid option \"$REPLY\"";;
esac
done