-
Notifications
You must be signed in to change notification settings - Fork 0
/
walletcontrol.sh
executable file
·142 lines (124 loc) · 2.86 KB
/
walletcontrol.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
#!/bin/bash
if [ ! "$BASH_VERSION" ] ; then
/bin/bash $0 $@
exit 1
fi
set -e
#ALL PATH VARIABLES SHOULD HAVE A TRAILING SLASH
#PATHS
DAEMONPATH=./daemons/
#VARS
LOOPLIMIT=5
DAEMONCOUNT=0
NICEBIN=`which nice`
NICENESS=3
source "./inc.logger.sh"
list_all_daemons() {
local list=`echo ${DAEMONS}`
log_info "Detected $DAEMONCOUNT daemons on this platform."
log_info "List: $list"
}
is_daemon_running() {
local daemon=$1
local status=`pgrep ${daemon}`
if [ "${status:-null}" == null ]; then
echo 0
else
echo 1
fi
}
start_daemon() {
local daemon=$1
local coinname=${daemon:0:-1}
if [ "$(is_daemon_running ${daemon})" == "1" ] ; then
log_warn "$daemon is already running."
return
fi
if [ -f "$daemon" ] ; then
if [ ! -d ".$daemon" ] ; then
log_warn "Data directory for $daemon not found. Creating new configuration."
mkdir .$daemon
cat > .${daemon}/${coinname}.conf <<EOF
rpcallowip=127.0.0.1
rpcuser=lifestyleninetycoinrpc
rpcpassword=***REMOVED***
EOF
fi
./$daemon -datadir=.$daemon -daemon
if [ "$(is_daemon_running ${daemon})" == 1 ] ; then
log_info "$daemon is running."
else
log_warn "Cannot start $daemon"
fi
else
log_warn "Daemon $daemon does not exist."
fi
}
stop_daemon() {
local daemon=$1
local loop=0
local running=1
if [ ! "$(is_daemon_running ${daemon})" == "1" ] ; then
log_warn "$daemon is not running."
return
fi
./$daemon -datadir=.$daemon stop || :
while [ $loop -lt $LOOPLIMIT ]; do
loop=$[loop+1]
log_info "Checking if $daemon is running..."
if [ "$(is_daemon_running ${daemon})" == "1" ] ; then
log_warn "Attempt $loop : $daemon is not dead. Retrying after 1 second.."
sleep 2
else
log_info "$daemon is not running."
running=0
loop=$[LOOPLIMIT+1]
fi
done
if [ $running == 1 ]; then
log_warn "Force killing $daemon"
killall $daemon || :
sleep 5
if [ "$(is_daemon_running ${daemon})" == "1" ]; then
log_warn "Cannot kill $daemon"
fi
fi
}
start_all() {
local loop=0
for i in ${DAEMONS[*]}; do
loop=$[loop+1]
log_info "Starting daemon $loop/$DAEMONCOUNT ($i)..."
start_daemon $i
done
}
stop_all() {
local loop=0
for i in ${DAEMONS[*]}; do
loop=$[loop+1]
log_info "Stopping daemon $loop/$DAEMONCOUNT ($i)..."
stop_daemon $i
done
}
log_info "Initializing script"
cd $DAEMONPATH && DAEMONS=`find . -maxdepth 1 -type f -name "*d" | awk '{ sub(/\.\//,""); print }'`
for i in ${DAEMONS[*]}; do
DAEMONCOUNT=$[DAEMONCOUNT+1]
done
list_all_daemons
if [ "$1" == "restart" ]; then
log_info "Restarting all daemons."
stop_all
start_all
elif [ "$1" == "stop" ]; then
log_info "Stopping all daemons."
stop_all
elif [ "$1" == "start" ]; then
log_info "Starting all daemons."
start_all
else
log_fatal "Unknown action. Syntax: scriptname.sh <start|stop|restart>"
exit 1
fi
log_info "All done"
RP_LOGGER_DONE