-
Notifications
You must be signed in to change notification settings - Fork 0
/
events-surrey
executable file
·77 lines (68 loc) · 1.89 KB
/
events-surrey
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
#!/bin/sh
# /etc/init.d/events-surrey
# chkconfig: 35 99 99
# description: SailsJS Event Management Service
#
# Save in /etc/init.d
# then "cd /etc/init.d"
# Switch it on: chkconfig --level 345 events-surrey on
# Set the permissions: chmod a+rwx events-surrey
# Confirm: chkconfig --list | grep events-surrey
# should show -> events-surrey 0:off 1:off 2:off 3:on 4:on 5:on 6:off
#
# Start the service using
# service events-surrey start
#
# Stop the service using
# service events-surrey stop
#
#
#
. /etc/rc.d/init.d/functions
USER="root"
DAEMON="/root/local/bin/forever"
ROOT_DIR="/usr/sails/projects/surrey"
OPTS="--prod"
SERVER="$ROOT_DIR/app.js"
LOG_FILE="$ROOT_DIR/app.js.log"
LOCK_FILE="/var/lock/subsys/events-surrey"
do_start()
{
if [ ! -f "$LOCK_FILE" ] ; then
echo -n $"Running $DAEMON start $SERVER $OPTS: "
runuser -l "$USER" -c "$DAEMON start $SERVER $OPTS >> $LOG_FILE &" && echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
else
echo "$SERVER is locked."
RETVAL=1
fi
}
do_stop()
{
echo -n $"Stopping $SERVER: "
# pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'`
#kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure
echo -n $"$DAEMON stop $SERVER "
runuser -l "$USER" -c "$DAEMON stop $SERVER >> $LOG_FILE &" && echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL