-
-
Save wwwdata/11217377 to your computer and use it in GitHub Desktop.
FreeBSD service script for NodeJS with Forever
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 | |
# PROVIDE: forever | |
# REQUIRE: NETWORKING SERVERS DAEMON | |
# BEFORE: LOGIN | |
# KEYWORD: shutdown | |
# Taken from http://habrahabr.ru/post/137857/ | |
. /etc/rc.subr | |
name="ghost" | |
forever="/usr/local/bin/node /usr/local/bin/forever" | |
workdir="/home/nodejs/projectName" | |
script="index.js" | |
rcvar=ghost_enable | |
extra_commands="status" | |
start_cmd="start" | |
status_cmd="status" | |
stop_cmd="stop" | |
restart_cmd="restart" | |
load_rc_config $name | |
eval "${rcvar}=\${${rcvar}:-'NO'}" | |
HOME=/var/run/forever | |
start() | |
{ | |
su -m nodejs -c "NODE_ENV=production exec ${forever} start -a -l /var/log/forever/projectName.log -o /dev/null -e /var/log/forever/projectName.log -p /var/run/forever --sourceDir ${workdir} ${script}" | |
} | |
status() | |
{ | |
su -m nodejs -c "exec ${forever} list" | |
} | |
stop() | |
{ | |
su -m nodejs -c "exec ${forever} --sourceDir ${workdir} stop ${script}" | |
} | |
restart() | |
{ | |
su -m nodejs -c "exec ${forever} --sourceDir ${workdir} restart ${script}" | |
} | |
run_rc_command "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment