-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnode
executable file
·113 lines (103 loc) · 1.91 KB
/
node
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
#!/bin/sh
export NAME=box
export DIR_WORKSPACE="$(pwd)"
export DIR_OUTPUTS="${DIR_WORKSPACE}"
export BIN="${DIR_OUTPUTS}/${NAME}"
if [[ ! -f ${BIN} ]]; then
echo "${BIN} doesn't exist."
exit 1
fi
showUsage()
{
cmd=`basename "$0"`
echo "Usage:"
echo "\tStart node #1 or #2 or #3:"
echo "\t\t${cmd} 1|2|3|4|5|6"
echo
echo "\tStart all nodes(1, 2, 3, 4, 5, 6):"
echo "\t\t${cmd} start"
echo
echo "\tStop all nodes:"
echo "\t\t${cmd} stop"
echo
echo "\tRemove database and logs of all nodes, rebuild and restart:"
echo "\t\t${cmd} cleanStart"
}
clean()
{
for i in {1..6};
do
rm -fr .devconfig/ws${i}/database
rm -fr .devconfig/ws${i}/logs
echo "Database and log of node ${i} deleted"
done
}
build()
{
echo "Building project"
make fullnode
}
stopAll()
{
kill `cat pids.txt`
rm -fr pids.txt
}
isRunning()
{
if [[ -f "pids.txt" ]];
then
echo "true"
else
echo "false"
fi
}
startAll()
{
rm -fr ./pids.txt
for i in {1..6};
do
${BIN} start --config=./.devconfig/.box-${i}.yaml > ./outputs/box${i}.log 2>&1 & echo $! >> ./pids.txt
echo "Node: ${i} started"
done
}
startNode()
{
${BIN} start --config=./.devconfig/.box-${1}.yaml
exit $?
}
if [[ "$#" -ne 1 ]]
then
showUsage
else
if [[ "$1" == "clean" ]]
then
clean
exit 0
elif [[ "$1" == "start" ]]
then
running=$( isRunning )
if [[ "$running" == "true" ]]
then
echo "Node is already running"
exit 1
fi
startAll
exit 0
elif [[ "$1" == "cleanStart" ]]
then
stopAll
clean
build
startAll
elif [[ "$1" == "stop" ]]
then
stopAll
exit 0
elif [[ "$1" -ge "1" && "$1" -le "6" ]]
then
startNode $1
exit $?
else
showUsage
fi
fi