-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctrl.sh
71 lines (64 loc) · 997 Bytes
/
ctrl.sh
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
#!/bin/sh
DIR=`pwd`
NODE=`which node`
# get action
ACTION=$1
PID_FILE='./App/Runtime/Data/app.pid';
# help
usage() {
echo "Usage: ./ctrl.sh {start|stop|restart}"
exit 1;
}
get_pid() {
if [ -f $PID_FILE ]; then
PID=$(cat $PID_FILE);
EXIST=$(ps axu | grep node | awk '{print $2}' | grep $PID | wc -l);
if test $EXIST -gt 0;then
echo `cat $PID_FILE`
fi
fi
}
# start app
start() {
pid=`get_pid`
if [ ! -z $pid ]; then
echo 'server is already running'
else
nohup $NODE $DIR/www/index.js online 2>&1 &
echo 'server is running'
fi
}
# stop app
stop() {
pid=`get_pid`
if [ -z $pid ]; then
echo 'server not running'
else
echo "server is stopping ..."
kill -15 $pid;
if [ -f $PID_FILE ];then
rm -rf $PID_FILE;
fi
echo "server stopped !"
fi
}
restart() {
stop
sleep 0.5
echo =====
start
}
case "$ACTION" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
usage
;;
esac