-
Notifications
You must be signed in to change notification settings - Fork 21
/
control
executable file
·114 lines (97 loc) · 1.52 KB
/
control
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
#!/bin/bash
binfile=wechat-sender
cwd=$(cd $(dirname $0)/; pwd)
cd $cwd
usage()
{
echo $"Usage: $0 {start|stop|restart|status|build|pack}"
exit 0
}
start()
{
if [ ! -f $binfile ]; then
echo "file[$binfile] not found"
exit 1
fi
if [ $(ps aux|grep -v grep|grep -v control|grep "$binfile" -c) -gt 0 ]; then
echo "${binfile} already started"
return
fi
mkdir -p logs/$binfile
nohup $cwd/$binfile &> logs/${binfile}/stdout.log &
for((i=1;i<=15;i++)); do
if [ $(ps aux|grep -v grep|grep -v control|grep "$binfile" -c) -gt 0 ]; then
echo "${binfile} started"
return
fi
sleep 0.2
done
echo "cannot start ${binfile}"
exit 1
}
stop()
{
if [ $(ps aux|grep -v grep|grep -v control|grep "$binfile" -c) -eq 0 ]; then
echo "${binfile} already stopped"
return
fi
ps aux|grep -v grep|grep -v control|grep "$binfile"|awk '{print $2}'|xargs kill
for((i=1;i<=15;i++)); do
if [ $(ps aux|grep -v grep|grep -v control|grep "$binfile" -c) -eq 0 ]; then
echo "${binfile} stopped"
return
fi
sleep 0.2
done
echo "cannot stop ${binfile}"
exit 1
}
restart()
{
stop
start
status
}
status()
{
ps aux|grep -v grep|grep ${binfile}
}
build()
{
go build
}
reload()
{
build
restart
}
pack()
{
v=$(date +%Y-%m-%d-%H-%M-%S)
tar zcvf $binfile-$v.tar.gz control $binfile etc/wechat.tpl etc/wechat-sender.yml etc/wechat-sender.service
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
build)
build
;;
reload)
reload
;;
pack)
pack
;;
*)
usage
esac