Skip to content

Instantly share code, notes, and snippets.

@capynet
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capynet/2de13de81ef8a71f2b2f to your computer and use it in GitHub Desktop.
Save capynet/2de13de81ef8a71f2b2f to your computer and use it in GitHub Desktop.
Nodejs systemd daemon template
#!/bin/bash
# This service requires you have forever app installed in your system.
### CONFIG ZONE
# This is the service name. It cant have any special char or space.
serviceName="my-service"
# Where is located your app
appFilePath="/var/node/my-service-node-app"
# Whats the name of your main app file.
appIndex="app.js"
enviroment=production
### END CONFIG ZONE
###### DO NOT EDIT BELOW THIS LINE ######
# Source function library.
. /lib/lsb/init-functions
pidFile="/var/run/$serviceName.pid"
logFile="/var/run/$serviceName.log"
command="node"
nodeApp="$appFilePath/$appIndex"
foreverApp="forever"
start() {
echo "Starting $serviceName"
PATH=/usr/local/bin:$PATH
export NODE_ENV=$enviroment
$foreverApp start --pidFile $pidFile -l $logFile -a -d -c "$command" $nodeApp
RETVAL=$?
}
restart() {
echo -n "Restarting $serviceName"
$foreverApp restart $nodeApp
RETVAL=$?
}
stop() {
echo -n "Shutting down $serviceName"
$foreverApp stop $nodeApp
RETVAL=$?
}
status() {
echo -n "Status $serviceName"
$foreverApp list
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVAL
@capynet
Copy link
Author

capynet commented Sep 13, 2014

This systemd service file works with https://gist.github.com/capynet/c7aa09a996fe909a0960

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment