使 npm 脚本在 FreeBSD Jail 中自动启动

Making an npm script auto start in a FreeBSD Jail

我在 FreeNAS 9.10 的 JAIL 中安装了一个 npm 包/脚本。 (基于 FreeBSD) 如果我 运行 "npm start" 在安装脚本的目录中,它会完美地工作。

但是,我需要它在监狱启动时自动启动。我现在不知道该怎么做。我需要创建 rc 脚本吗?

基本上我需要做的就是在启动时将 "npm start" 放在正确的目录中。我该怎么做?

谢谢

是的,您可以在监狱中放置一个 rc 脚本并使用监狱的 /etc/rc.conf 文件启用它。

但是,对于一个快速但肮脏的解决方案,您可以创建一个 /etc/rc.local 脚本(也在监狱环境中)并将您的启动命令放在那里。

参见manual page here

不知道 npm start,但是对于 node.js 我做了这样的 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 ""

将此文件命名为 SERVICENAME 并放入 /usr/local/etc/rc.d

以 root 身份启用自动启动 运行 命令:

sysrc SERVICENAME_enable="YES"

不要忘记将 SERVICENAMEUSERNAMEPROGDIR 替换为您的值,并且添加

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

到你的入口js文件。