forked from open-falcon-archive/gateway
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontrol
executable file
·188 lines (160 loc) · 3.63 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
WORKSPACE=$(
cd $(dirname $0)/
pwd
)
cd $WORKSPACE
mkdir -p var
module=gateway2
app=octopux-$module
conf=cfg.json
dist=$(rpm --showrc | grep dist | grep el | awk '($2=="dist"){print $3 }' | awk -F . '{print $2}')
logfile=/var/log/supervisor/${app}.log
iteration=3
progpath="usr/local/octopux/${app}/"
file_list="control cfg.example.json ${app} perfcounter.json"
function check_pid() {
running=$(ps -C $app | grep -v "PID TTY" | wc -l)
return $running
}
function supervisorconf() {
cat <<EOF >${app}.conf
[program:${app}]
command=/${progpath}${app}
numprocs=1
directory=/${progpath}
autostart=true
autorestart=true
startsecs=1
startretries=1000000
exitcodes=0
stopsignal=SIGTERM
stopwaitsecs=300
user=root
redirect_stderr=true
stdout_logfile=/var/log/supervisor/${app}.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stdout_events_enabled=true
stderr_logfile=/var/log/supervisor/${app}.err.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
stderr_events_enabled=true
EOF
cat << EOF > postinsl.in
supervisorctl reread
supervisorctl update
EOF
echo "OK"
echo ""
}
function run() {
check_pid
running=$?
if [ ${running} -gt 0 ]; then
echo -n "${app} now is running already, pid="
ps -C $app | grep -v "PID TTY" | awk '{print $1}'
stop
sleep 1
fi
if ! [ -f ${conf} ]; then
echo "Config file $conf doesn't exist, creating one."
cp cfg.example.json ${conf}
fi
ulimit -HSn 65536
./$app -c ${conf} >>${logfile} 2>&1
}
function start() {
check_pid
running=$?
if [ $running -gt 0 ]; then
echo -n "${app} now is running already, pid="
ps -C ${app} | grep -v "PID TTY" | awk '{print $1}'
return 1
fi
if ! [ -f $conf ]; then
echo "Config file $conf doesn't exist, creating one."
cp cfg.example.json $conf
fi
ulimit -HSn 65536
nohup ./${app} -c ${conf} >>${logfile} 2>&1 &
sleep 1
running=$(ps -C ${app} | grep -v "PID TTY" | wc -l)
if [ ${running} -gt 0 ]; then
echo "${app} started..., pid=" $(ps -C ${app} | grep -v "PID TTY" | awk '{print $1}')
else
echo "${app} failed to start."
return 1
fi
}
function stop() {
pid=$(ps -C ${app} | grep -v "PID TTY" | awk '{print $1}')
kill $(pidof ${app})
echo "${app} (${pid}) stoped..."
}
function restart() {
stop
sleep 1
start
}
function status() {
check_pid
running=$?
if [ $running -gt 0 ]; then
echo started
else
echo stoped
fi
}
function tailf() {
tail -f ${logfile}
}
function build() {
go build -o ${app}
if [ $? -ne 0 ]; then
exit $?
fi
./$app -v
}
function rpm() {
build
if [ "$dist" == "" ]; then
echo "cant build rpm on this os!"
exit 1
fi
version=$(./${app} -v)
supervisorconf
mkdir -p "rpm/${progpath}"
mkdir -p rpm/etc/supervisor/conf.d/
cp -R ${file_list} rpm/${progpath}
cp cfg.example.json rpm/${progpath}cfg.json
cp ${app}.conf rpm/etc/supervisor/conf.d
fpm -s dir -t rpm -n ${app} -m dotwoo_test -v ${version} --iteration ${iteration} --rpm-dist ${dist} --after-install postinsl.in --after-upgrade postinsl.in --after-remove postinsl.in -C rpm --config-files etc/supervisor/conf.d/${app}.conf --config-files ${progpath}cfg.json -f --url http://www.baishancloud.com/ --provides dotwoo@baishancloud.com --vendor dotwoo@baishancloud.com
rm -fr rpm
}
function help() {
echo "$0 build|start|stop|restart|status|tail|run|rpm"
}
if [ "$1" == "" ]; then
help
elif [ "$1" == "stop" ]; then
stop
elif [ "$1" == "start" ]; then
start
elif [ "$1" == "restart" ]; then
restart
elif [ "$1" == "status" ]; then
status
elif [ "$1" == "tail" ]; then
tailf
elif [ "$1" == "run" ]; then
run
elif [ "$1" == "build" ]; then
build
elif [ "$1" == "rpm" ]; then
rpm
else
help
fi