Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Mar 2016 12:36:03 -0700
From:      Jim Long <list@museum.rain.com>
To:        freebsd-questions@freebsd.org
Subject:   Seeking a solid startup script for node.js/forever
Message-ID:  <20160318193603.GA20566@ns.umpquanet.com>

next in thread | raw e-mail | index | archive | help
I have found the following rc.d script for running node.js/forever apps
under FreeBSD.  I'm not an expert, but the script looks fairly
well-structured.

The problem is, it doesn't fork the process into the background.  And
since this runs in a jail, that means that 'service jail start' never
completes.

Here's the script (which I found at https://gist.github.com/jellea/6510897), 
along with a dialog showing how I enable it, and what happens when I
attempt to start it (along with a ^T and a ^C at the end).

The only work-around I have at this time is to leave the service
disabled in /etc/rc.conf, and start it manually from the jail's
/etc/rc.local with '/usr/local/etc/rc.d/iws onestart &' so that the
start-up script is forced into the background.

How can I modify this script so that it will start cleanly in the
background?

Thank you!  Please cc: me on any replies sent to the list.

Jim


# cat /usr/local/etc/rc.d/iws
#!/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/IWS4"
#script="web.js"
#script="app.js"
script="${workdir}/app.js"

rcvar=iws_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=/usr/local/IWS4
start()
{
  NODE_ENV=production
  su -m www -c "exec ${forever} start -a -l ${HOME}/forever.log -o ${HOME}/output.log -e ${HOME}/error.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"
# echo 'iws_enable="YES"' >> /etc/rc.conf
# time service iws start
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: /usr/local/IWS4/app.js
load: 0.11  cmd: node 24068 [uwait] 125.56r 0.26u 0.01s 0% 33384k
^C
real    2m56.348s
user    0m0.268s
sys     0m0.039s
# 






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160318193603.GA20566>