-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Service script example for managing production server
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
# | ||
# description: SourceJS service, for managing production server, using node-forever. | ||
# processname: node | ||
# | ||
# Based on https://gist.github.com/jinze/3748766 | ||
# | ||
# To use it as service on Ubuntu: | ||
# sudo cp source.sh /etc/init.d/source | ||
# sudo chmod a+x /etc/init.d/source | ||
# sudo update-rc.d source defaults | ||
# | ||
# Then use commands: | ||
# sudo service source <command (start|stop|etc)> | ||
|
||
NAME=SourceJS # Unique name for the application | ||
USER=user # User for process running | ||
HOME_DIR=/home/user # User home dir | ||
SOUREC_DIR=$HOME_DIR/Source # Location of the application source | ||
COMMAND=node # Command to run | ||
APP_PATH=$SOUREC_DIR/app.js # Application entry point script | ||
NODE_ENVIRONMENT=production # Node environment | ||
|
||
FOREVER=forever | ||
|
||
start() { | ||
echo "Starting $NAME node instance : " | ||
|
||
sudo -H -u $USER NODE_ENV=$NODE_ENVIRONMENT $FOREVER start -a -c $COMMAND $APP_PATH | ||
|
||
RETVAL=$? | ||
} | ||
|
||
restart() { | ||
echo "Restarting $NAME node instance : " | ||
sudo -H -u $USER $FOREVER restart $APP_PATH | ||
RETVAL=$? | ||
} | ||
|
||
status() { | ||
echo "Status for $NAME : " | ||
sudo -H -u $USER $FOREVER list | ||
RETVAL=$? | ||
} | ||
|
||
stop() { | ||
echo "Shutting down $NAME node instance." | ||
sudo -H -u $USER $FOREVER stop $APP_PATH | ||
RETVAL=$? | ||
} | ||
|
||
case "$1" in | ||
start) | ||
start | ||
;; | ||
stop) | ||
stop | ||
;; | ||
status) | ||
status | ||
;; | ||
restart) | ||
restart | ||
;; | ||
*) | ||
echo "Usage: {start|stop|status|restart}" | ||
exit 1 | ||
;; | ||
esac | ||
exit $RETVAL |