/
stop.sh
executable file
·59 lines (54 loc) · 1.05 KB
/
stop.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
#!/bin/bash
# exit on error
set -e
function stop() {
local program=""
case $1 in
all)
program="build/alphabill"
;;
money)
program="build/alphabill money"
;;
tokens)
program="build/alphabill tokens"
;;
evm)
program="build/alphabill evm"
;;
root)
program="build/alphabill root"
;;
*)
echo "error: unknown argument $1" >&2
return 1
;;
esac
PID=$(ps -eaf | grep "$program" | grep -v grep | awk '{print $2}')
if [ -n "$PID" ]; then
echo "killing $PID"
kill $PID
return 0
fi
echo "program not running"
}
usage() { echo "Usage: $0 [-h usage] [-a stop all] [-r stop root] [-p stop partition: money, tokens, evm]"; exit 0; }
# stop requires an argument either -a for stop all or -p to stop a specific partition
[ $# -eq 0 ] && usage
# handle arguments
while getopts "harp:" o; do
case "${o}" in
a) #kill all
stop "all"
;;
r)
stop "root"
;;
p)
stop "${OPTARG}"
;;
h | *) # help.
usage && exit 0
;;
esac
done