forked from UlricQin/falcon-eye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control
executable file
·82 lines (73 loc) · 1.44 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
#!/bin/bash
WORKSPACE=$(cd $(dirname $0)/; pwd)
cd $WORKSPACE
mkdir -p var
app=falcon-eye
conf=cfg.ini
pidfile=var/app.pid
logfile=var/app.log
RELEASE_FILE=falcon-eye.tar.gz
function pack() {
go build
tar zcf $RELEASE_FILE $app $conf control VERSION public templates
echo "target: $RELEASE_FILE"
}
function check_pid() {
if [ -f $pidfile ];then
pid=`cat $pidfile`
if [ -n $pid ]; then
running=`ps -p $pid|grep -v "PID TTY" |wc -l`
return $running
fi
fi
return 0
}
function start() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo -n "$app now is running already, pid="
cat $pidfile
return 1
fi
nohup ./$app -c $conf &> $logfile &
echo $! > $pidfile
echo "$app started..., pid=$!"
}
function stop() {
pgrep $app | xargs kill &>/dev/null
echo "$app stoped..."
}
function restart() {
stop
sleep 1
start
}
function status() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo -n "$app now is running, pid="
cat $pidfile
else
echo "$app is stoped"
fi
}
function help() {
echo "$0 start|stop|restart|status|pack|update"
}
if [ "$1" == "" ]; then
help
elif [ "$1" == "stop" ];then
stop
elif [ "$1" == "start" ];then
start
elif [ "$1" == "restart" ];then
restart
elif [ "$1" == "pack" ];then
pack
elif [ "$1" == "status" ];then
status
else
help
fi