Skip to content

Instantly share code, notes, and snippets.

@Philzen
Created July 28, 2014 23:38
Show Gist options
  • Save Philzen/2e8df8eca45f4f1808be to your computer and use it in GitHub Desktop.
Save Philzen/2e8df8eca45f4f1808be to your computer and use it in GitHub Desktop.
Daemonize uptime with forever on FreeBSD
#!/bin/sh
# PROVIDE: node_uptime
# REQUIRE: NETWORKING SERVERS DAEMON
# BEFORE: LOGIN
# KEYWORD: shutdown
. /etc/rc.subr
name="node_uptime"
forever="/usr/local/bin/node /usr/local/bin/forever"
workdir="/WHERE/UPTIME.JS/FILES/RESIDE"
script="monitor.js"
script1="app.js"
rcvar=`set_rcvar`
start_cmd="start"
stop_cmd="stop"
restart_cmd="restart"
load_rc_config $name
eval "${rcvar}=\${${rcvar}:-'NO'}"
start()
{
HOME=/root
NODE_ENV=production
${forever} start -a -l /var/log/forever.log -o /dev/null -e ${workdir}/logs/node_err.log --sourceDir ${workdir} ${script} &
${forever} start -a -l /var/log/forever.log -o /dev/null -e ${workdir}/logs/node_err.log --sourceDir ${workdir} ${script1}
}
stop()
{
${forever} stop ${script1}
${forever} stop ${script}
}
restart()
{
${forever} restart ${script1}
${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