-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol
78 lines (68 loc) · 1.29 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
#!/bin/bash
WORKSPACE=$(
cd "$(dirname "$0")"/ || exit
pwd
)
cd "$WORKSPACE" || exit
pid_file=app.pid
app_name="stream-server"
function help() {
echo "$0 help|stop|start|status|restart"
}
function stop() {
pid=$(cat $pid_file)
kill -9 "$pid"
echo "$app_name stopped..."
}
function start() {
check_pid
running=$?
if [ $running -gt 0 ]; then
echo -n "$app_name now is running already, pid="
cat $pid_file
return 1
fi
nohup ./stream-server >/dev/null 2>&1 &
echo $! >$pid_file
sleep 1
echo "$app_name starting..."
}
function status() {
check_pid
running=$?
if [ $running -gt 0 ]; then
echo -n "$app_name now is running, pid="
cat $pid_file
echo "app_status:running"
else
echo "$app_name is stopped"
echo "app_status:stopped"
fi
}
function restart() {
stop
sleep 3
start
}
function check_pid() {
if [ -f $pid_file ]; then
pid=$(cat $pid_file)
if kill -0 "$pid"; then
return 1
fi
fi
return 0
}
if [ "$1" == "" ]; then
help
elif [ "$1" == "stop" ]; then
stop
elif [ "$1" == "start" ]; then
start
elif [ "$1" == "status" ]; then
status
elif [ "$1" == "restart" ]; then
restart
else
help
fi