forked from sxmz/acchain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacchaind
executable file
·111 lines (94 loc) · 2.36 KB
/
acchaind
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
#!/bin/bash
readonly PROG_DIR=$(readlink -m $(dirname $0))
readonly PID_FILE=$PROG_DIR/acchain.pid
function read_port() {
echo `cat $PROG_DIR/config.json |grep '"port"'|head -n 1| awk -F "[:,]" '{print$2}'|tr -d ' '`
}
function is_running() {
test -f $PID_FILE && ps -p $(cat $PID_FILE) > /dev/null
}
function status() {
if is_running; then
echo "Acchain server is running"
else
echo "Acchain server is not running"
fi
}
function start() {
if is_running; then
echo "Acchain server is already started"
else
rm -f $PID_FILE
./bin/node $PROG_DIR/app.js --base $PROG_DIR --daemon $@
fi
}
function stop() {
local pid
if test -f $PID_FILE; then
pid=$(cat $PID_FILE)
fi
if [ -n "$pid" ] && ps -p "$pid" > /dev/null; then
kill $pid
sleep 1
i=1
while ps -p $pid > /dev/null; do
if [ $i == 5 ]; then
kill -9 $pid
echo "Acchain server killed"
fi
echo "Still waiting for accchain server to stop ..."
sleep 1
((i++))
done
echo "Acchain server stopped"
else
echo "Acchain server is not running"
fi
rm -f $PID_FILE
}
function restart() {
stop
start
}
function rebuild() {
cd $PROG_DIR && curl -sL http://upgrade.acchain.org/package/rebuild-mainnet.sh | bash
}
function rebuild_testnet() {
cd $PROG_DIR && curl -sL http://upgrade.acchain.org/package/rebuild-testnet.sh | bash
}
function version() {
node $PROG_DIR/app.js --version
}
function check_os() {
os_num=`cat /etc/os-release | grep '\"Ubuntu\"' | wc -l`
if [ $os_num -ne 1 ];then
echo "Linux is not Ubuntu, please configure manually!" && exit 1
fi
}
function configure() {
check_os
sudo $PROG_DIR/init/install_deps.sh
sudo $PROG_DIR/init/config_ntp.sh
# sudo $PROG_DIR/init/config_monitor.sh
}
function upgrade() {
cd $PROG_DIR && curl -sL http://upgrade.acchain.org/package/upgrade-mainnet.sh | bash
}
function upgrade_testnet() {
cd $PROG_DIR && curl -sL http://upgrade.acchain.org/package/upgrade-testnet.sh | bash
}
function enable() {
local secret="$@"
local port=`read_port`
curl -k -H "Content-Type: application/json" -X POST -d '{"secret":"'"$secret"'"}' localhost:$port/api/delegates/forging/enable
}
function main() {
export PATH=$PROG_DIR/bin:$PATH
local cmdType=`type -t $1`
if [ $cmdType == "function" ]; then
eval $@
else
echo "Command not supported"
fi
}
main $@