Last active
August 29, 2015 14:06
-
-
Save capynet/2de13de81ef8a71f2b2f to your computer and use it in GitHub Desktop.
Nodejs systemd daemon template
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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This systemd service file works with https://gist.github.com/capynet/c7aa09a996fe909a0960