-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathctrl.sh
More file actions
executable file
·87 lines (73 loc) · 1.59 KB
/
ctrl.sh
File metadata and controls
executable file
·87 lines (73 loc) · 1.59 KB
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
#!/bin/bash
# @describe:
# @author: Jerry Yang(hy0kle@gmail.com)
#set -x
server_conf="conf/server.json"
if [[ ! -f "$server_conf" ]]
then
echo "Can NOT find $server_conf"
echo "Please see README.md and fix it."
exit -1
fi
bin_name="api-server"
server_port=`grep port $server_conf | head -n 1 | awk '{split($2, cntr, ","); print cntr[1]}'`
prog="$bin_name:$server_port"
#echo $prog
work_pid=""
function get_work_pid()
{
work_pid=$(ps aux | grep $prog | grep -v grep | awk '{print $2}' | xargs)
}
get_work_pid
case "$1" in
start)
if ((work_pid > 0))
then
echo "$prog is working... pid: $work_pid"
exit 1
else
cmd="./$bin_name"
nohup $cmd &
echo "$prog start work."
fi
;;
stop)
if ((work_pid > 0))
then
kill -9 "$work_pid"
echo "stop $prog success, pid: $work_pid"
else
echo "Can find $prog, please check it out."
fi
;;
restart)
$0 stop
$0 start
;;
status)
if ((work_pid > 0))
then
echo "$prog is working, pid: $work_pid"
else
echo "$prog is not working..."
fi
;;
rebuild)
git pull origin master
$0 stop
make && $0 start
ret=$?
if ((0 == ret))
then
echo "rebuild success"
else
echo "rebuild fail..."
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status|rebuild}"
exit 11
;;
esac
exit 0
# vim:set ts=4 sw=4 et fdm=marker: