-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontrol
122 lines (101 loc) · 1.79 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
115
116
117
118
119
120
121
122
#!/bin/bash
# release version
CWD=$(cd $(dirname $0)/; pwd)
cd $CWD
start()
{
mod="vsphere"
binfile=${mod}-mon
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 "${mod} already started"
return
fi
mkdir -p logs/
nohup $CWD/$binfile &> logs/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 "${mod} started"
return
fi
sleep 0.2
done
echo "cannot start ${mod}"
exit 1
}
stop()
{
mod="vsphere"
binfile=${mod}-mon
if [ $(ps aux|grep -v grep|grep -v control|grep "$binfile" -c) -eq 0 ]; then
echo "${mod} 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 "${mod} stopped"
return
fi
sleep 0.2
done
echo "cannot stop $mod"
exit 1
}
restart()
{
mod="vsphere"
stop $mod
start $mod
status
}
status()
{
ps aux|grep -v grep|grep "vsphere-mon"
}
build()
{
go build
if [ $? -ne 0 ]; then
exit $?
fi
mod="vsphere"
binfile=${mod}-mon
./$binfile -v
}
pack()
{
build
git log -1 --pretty=%h > gitversion
mod="vsphere"
binfile=${mod}-mon
version=`./$binfile -v | cut -d " " -f2`
file_list="control install.sh etc service $binfile"
echo "...tar $binfile-$version.tar.gz <= $file_list"
tar zcf $binfile-$version.tar.gz gitversion $file_list
}
case "$1" in
start)
start $2
;;
stop)
stop $2
;;
restart)
restart $2
;;
status)
status
;;
build)
build
;;
pack)
pack
;;
*)
usage
esac