forked from ralyodio/node-startup
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode-app
More file actions
executable file
·70 lines (62 loc) · 1.72 KB
/
node-app
File metadata and controls
executable file
·70 lines (62 loc) · 1.72 KB
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
#/bin/sh
NODE_EXEC=/usr/local/bin/node
NODE_ENV="production"
NODE_APP='app.js'
APP_DIR='/var/www/example.com';
PID_FILE=$APP_DIR/pid/app.pid
LOG_FILE=$APP_DIR/log/app.log
CONFIG_DIR=$APP_DIR/config
###############
# REDHAT chkconfig header
# chkconfig: - 58 74
# description: node-app is the script for starting a node app on boot.
### BEGIN INIT INFO
# Provides: node
# Required-Start: $network $remote_fs $local_fs
# Required-Stop: $network $remote_fs $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop node
# Description: Node process for app
### END INIT INFO
case "$1" in
start)
if [ -f $PID_FILE ]
then
echo "$PID_FILE exists, process is already running or crashed"
else
echo "Starting node app..."
NODE_ENV=$NODE_ENV NODE_CONFIG_DIR=$CONFIG_DIR $NODE_EXEC $APP_DIR/$NODE_APP 1>$LOG_FILE 2>&1 &
echo $! > $PID_FILE;
fi
;;
stop)
if [ ! -f $PID_FILE ]
then
echo "$PID_FILE does not exist, process is not running"
else
echo "Stopping $APP_DIR/$NODE_APP ..."
echo "Killing `cat $PID_FILE`"
kill `cat $PID_FILE`;
rm $PID_FILE;
echo "Node stopped"
fi
;;
restart)
if [ ! -f $PID_FILE ]
then
echo "$PID_FILE does not exist, process is not running"
else
echo "Restarting $APP_DIR/$NODE_APP ..."
echo "Killing `cat $PID_FILE`"
kill `cat $PID_FILE`;
rm $PID_FILE;
NODE_ENV=$NODE_ENV NODE_CONFIG_DIR=$CONFIG_DIR $NODE_EXEC $APP_DIR/$NODE_APP 1>$LOG_FILE 2>&1 &
echo $! > $PID_FILE;
echo "Node restarted"
fi
;;
*)
echo "Usage: /etc/init.d/node-app {start|stop|restart}"
;;
esac