From owner-freebsd-questions@freebsd.org Fri Mar 18 19:36:35 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4BEC7AD50D8 for ; Fri, 18 Mar 2016 19:36:35 +0000 (UTC) (envelope-from list@museum.rain.com) Received: from ns.umpquanet.com (ns.umpquanet.com [98.158.10.80]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1990CD25 for ; Fri, 18 Mar 2016 19:36:34 +0000 (UTC) (envelope-from list@museum.rain.com) Received: from ns.umpquanet.com (localhost [127.0.0.1]) by ns.umpquanet.com (8.14.9/8.14.9) with ESMTP id u2IJa3hT025060 for ; Fri, 18 Mar 2016 12:36:03 -0700 (PDT) (envelope-from list@museum.rain.com) Received: (from james@localhost) by ns.umpquanet.com (8.14.9/8.14.9/Submit) id u2IJa3Ov025059 for freebsd-questions@freebsd.org; Fri, 18 Mar 2016 12:36:03 -0700 (PDT) (envelope-from list@museum.rain.com) Date: Fri, 18 Mar 2016 12:36:03 -0700 From: Jim Long To: freebsd-questions@freebsd.org Subject: Seeking a solid startup script for node.js/forever Message-ID: <20160318193603.GA20566@ns.umpquanet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Mar 2016 19:36:35 -0000 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 #