Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jellea
Last active August 28, 2018 05:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jellea/6510897 to your computer and use it in GitHub Desktop.
Save jellea/6510897 to your computer and use it in GitHub Desktop.
Node.js Forever rcng script for FreeBSD
#!/bin/sh
# PROVIDE: forever
# REQUIRE: NETWORKING SERVERS DAEMON
# BEFORE: LOGIN
# KEYWORD: shutdown
# Taken from http://habrahabr.ru/post/137857/
. /etc/rc.subr
name="forever"
forever="/usr/local/bin/node /usr/local/bin/forever"
workdir="/usr/local/www"
script="web.js"
rcvar=forever_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()
{
NODE_ENV=production
su -m www -c "exec ${forever} start -a -l /var/log/forever.log -o /dev/null -e /var/log/node_err.log -p /var/run/forever ${script}"
}
status()
{
su -m www -c "exec ${forever} list"
}
stop()
{
su -m www -c "exec ${forever} stop ${script}"
}
restart()
{
su -m www -c "exec ${forever} restart ${script}"
}
run_rc_command "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment