3

I've installed an npm package / script in a JAIL on FreeNAS 9.10. (FreeBSD based) It works perfectly if I run "npm start" in the directory where the scripts are installed.

However, I need this to be auto-starting when the jail starts. I don't know now to do that. Do I need to create an rc script?

Basically all I need to do is give the "npm start" in the correct directory on start up. How do I do that?

thanks

bobomoreno
  • 2,848
  • 5
  • 23
  • 42

2 Answers2

3

Don't know about npm start, but for node.js I made such RC srcipt:

#!/bin/sh

# $FreeBSD: 340872 2014-01-24 00:14:07Z mat $
#
# PROVIDE: SERVICENAME
# REQUIRE: NETWORKING
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable SERVICENAME:
#
# SERVICENAME_enable="YES"
#

. /etc/rc.subr

name="SERVICENAME"
rcvar=SERVICENAME_enable
pidfile=${SERVICENAME_pidfile:-"/var/run/SERVICENAME.pid"}
command="/usr/sbin/daemon"
#command_args="-r -u USERNAME -P /var/run/SERVICENAME.pid /usr/local/bin/node /home/USERNAME/PROGDIR" # cjayho: restart if crashed
command_args="-u USERNAME -P /var/run/SERVICENAME.pid /usr/local/bin/node /home/USERNAME/PROGDIR"

load_rc_config $name
: ${SERVICENAME_enable:="NO"}

run_rc_command "$1"

name this file something like SERVICENAME and put to /usr/local/etc/rc.d

to enable automatic startup run command as root:

sysrc SERVICENAME_enable="YES"

do not forget to replace SERVICENAME, USERNAME and PROGDIR to your values, and add

process.chdir('/home/USERNAME/PROGDIR')

to your entry js file.

cjayho
  • 31
  • 2
2

Yes, you can place an rc script within the jail and enable it using the jail's /etc/rc.conf file.

But, for a quick and dirty solution, you could create a /etc/rc.local script (also within the jail's environment) and put your startup commands in there.

See the manual page here.

Richard Smith
  • 45,711
  • 6
  • 82
  • 81