Created
October 10, 2014 05:49
-
-
Save orctom/8faa2431a5425e2ceeb2 to your computer and use it in GitHub Desktop.
Node.js forever service /etc/init.d/app_name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
### BEGIN INIT INFO | |
# Provides: Teamate | |
# Required-Start: $local_fs $remote_fs | |
# Required-Stop: $local_fs $remote_fs | |
# Should-Start: $local_fs | |
# Should-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Teamate | |
# Description: Teamate | |
### END INIT INFO | |
# | |
### BEGIN CHKCONFIG INFO | |
# chkconfig: 2345 50 50 | |
# description: Teamate | |
### END CHKCONFIG INFO | |
APPLICATION_NAME="Teamate" | |
APPLICATION_ID="teamate" | |
APPLICATION_PATH="/home/wsadmin/workspaces/teamate/app.js" | |
PORT="3000" | |
MIN_UPTIME="5000" | |
SPIN_SLEEP_TIME="2000" | |
PIDFILE_DIR="/var/run/$APPLICATION_ID" | |
PIDFILE_PATH="$PID_DIR/$APPLICATION_ID.pid" | |
LOGFILE_DIR="/var/log/$APPLICATION_ID" | |
LOGFILE_PATH="$LOGFILE_DIR/$APPLICATION_ID.log" | |
start() { | |
echo "Starting $APPLICATION_NAME" | |
mkdir -p "$PIDFILE_DIR" | |
mkdir -p "$LOGFILE_DIR" | |
export PORT="$PORT" | |
forever \ | |
--pidFile $PIDFILE_PATH \ | |
-a \ | |
-l $LOGFILE_PATH \ | |
--minUptime $MIN_UPTIME \ | |
--spinSleepTime $SPIN_SLEEP_TIME \ | |
start $APPLICATION_PATH 2>&1 > /dev/null & | |
RETVAL=$? | |
} | |
stop() { | |
if [ -f $PIDFILE_PATH ]; then | |
echo "Shutting down $APPLICATION_NAME" | |
# Tell Forever to stop the process. | |
forever stop $APPLICATION_PATH 2>&1 > /dev/null | |
# Get rid of the pidfile, since Forever won't do that. | |
rm -f $PIDFILE_PATH | |
RETVAL=$? | |
else | |
echo "$APPLICATION_NAME is not running." | |
RETVAL=0 | |
fi | |
} | |
restart() { | |
stop | |
start | |
} | |
status() { | |
echo `forever list` | grep -q "$APPLICATION_PATH" | |
if [ "$?" -eq "0" ]; then | |
echo "$APPLICATION_NAME is running." | |
RETVAL=0 | |
else | |
echo "$APPLICATION_NAME is not running." | |
RETVAL=3 | |
fi | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
restart) | |
restart | |
;; | |
*) | |
echo "Usage: {start|stop|status|restart}" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment