Skip to content

Instantly share code, notes, and snippets.

@wwwdata
Forked from jellea/gist:6510897
Last active January 12, 2024 17:46
Show Gist options
  • Save wwwdata/11217377 to your computer and use it in GitHub Desktop.
Save wwwdata/11217377 to your computer and use it in GitHub Desktop.
FreeBSD service script for NodeJS with Forever
#!/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