FreeBSD rc.d脚本在启动时不起作用

我正在尝试编写一个rc.d脚本来在计算机启动时启动FreeBSD上的fastcgi-mono-server4,以便使用nginx运行它。

当我在服务器上login时执行脚本时,脚本就起作用 – 但是在启动时,我收到以下消息:

eval: -applications=192.168.50.133:/:/usr/local/www/nginx: not found 

该脚本如下所示:

 #!/bin/sh # PROVIDE: monofcgid # REQUIRE: LOGIN nginx # KEYWORD: shutdown . /etc/rc.subr name="monofcgid" rcvar="monofcgid_enable" stop_cmd="${name}_stop" start_cmd="${name}_start" start_precmd="${name}_prestart" start_postcmd="${name}_poststart" stop_postcmd="${name}_poststop" command=$(which fastcgi-mono-server4) apps="192.168.50.133:/:/usr/local/www/nginx" pidfile="/var/run/${name}.pid" monofcgid_prestart() { if [ -f $pidfile ]; then echo "monofcgid is already running." exit 0 fi } monofcgid_start() { echo "Starting monofcgid." ${command} -applications=${apps} -socket=tcp:127.0.0.1:9000 & } monofcgid_poststart() { MONOSERVER_PID=$(ps ax | grep mono/4.0/fastcgi-m | grep -v grep | awk '{print $1}') if [ -f $pidfile ]; then rm $pidfile fi if [ -n $MONOSERVER_PID ]; then echo $MONOSERVER_PID > $pidfile fi } monofcgid_stop() { if [ -f $pidfile ]; then echo "Stopping monofcgid." kill $(cat $pidfile) echo "Stopped monofcgid." else echo "monofcgid is not running." exit 0 fi } monofcgid_poststop() { rm $pidfile } load_rc_config $name run_rc_command "$1" 

如果还不是很清楚的话,我对FreeBSD和sh脚本都是相当新的,所以对于我忽略的一些明显的细节,我有所准备。

我非常想知道为什么这样做是失败的,如何解决这个问题,如果有人有更好的办法来解决这个问题的话,那么我都是有想法的。

你所说的问题可能与你作为login用户执行脚本时的PATH不同以及在启动时执行脚本有关。

“哪个”的输出取决于PATH。 因此,如果您的可执行文件所在的地方不在PATH上,它将不会返回任何内容。

我build议你明确指定$命令中的可执行文件的path。 或者像这样修改这个脚本的PATH:

 PATH="${PATH}:/path/to/where/daemon/lies" 

使用rcvariablescommand_args代替apps 。 RC以某种方式对command_args进行筛选,以筛选特殊符号进行评估。

事实certificate,真正的问题是在以下行:

 command=$(which fastcgi-mono-server4) 

我猜测发生了什么事是在启动时这导致了空string,这意味着“应用程序…”被评估为一个命令。