Last active
August 29, 2015 14:07
-
-
Save timemachine3030/8105335f72eaaecb153a to your computer and use it in GitHub Desktop.
Nodejs init.d script
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/bash -e | |
SERVICE=node_server | |
INIT_LOCATION=/etc/init.d/${SERVICE} | |
npm install -g forever | |
mkdir /var/run/forever | |
touch $INIT_LOCATION | |
chmod a+x $INIT_LOCATION | |
update-rc.d $SERVICE defaults | |
curl https://gist.githubusercontent.com/timemachine3030/8105335f72eaaecb153a/raw/init-script.bash >> /etc/init.d/${SERVICE} | |
service $SERVICE start |
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 | |
export PATH=$PATH:/usr/local/bin | |
export NODE_ENV=${NODE_ENV:="production"} | |
export NODE_PATH=$$NODE_PATH:/usr/local/lib/node_modules | |
. /lib/lsb/init-functions | |
RETVAL=0 | |
NAME=server.js | |
DIR=/var/apps/current | |
APP=${DIR}/${NAME} | |
## We want the correct procwss.cwd() when out server starts | |
cd ${DIR} | |
## Test if server is running | |
running() { | |
forever list 2>/dev/null | grep ${NAME} 2>&1 >/dev/null | |
return $? | |
} | |
case "$1" in | |
start) | |
log_progress_msg "Starting server" | |
forever -p /var/run/forever start --sourceDir=${DIR} ${NAME} 2>&1 >/dev/null | |
;; | |
stop) | |
log_progress_msg "Stopping server" | |
forever stop --sourceDir=${DIR} ${NAME} 2>&1 >/dev/null | |
;; | |
restart) | |
log_progress_msg "Restarting server" | |
forever restart --sourceDir=${DIR} ${NAME} 2>&1 >/dev/null | |
;; | |
status) | |
if running; then | |
log_progress_msg "Server is running." | |
else | |
log_progress_msg "Server is stopped." | |
fi | |
;; | |
*) | |
echo "Usage: ${0} {start|stop|restart|status}" | |
RETVAL=1 | |
;; | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
curl https://gist.githubusercontent.com/timemachine3030/8105335f72eaaecb153a/raw/forever-setup.bash | bash