2

I am trying to write a rc.d script to startup the fastcgi-mono-server4 on FreeBSD when the computer starts up - in order to run it with nginx.

The script works when I execute it while being logged in on the server - but when booting I get the following message:

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

The script looks as follows:

#!/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" 

In case it is not already super clear, I am fairly new to both FreeBSD and sh scripts, so I'm kind of prepared for some obvious little detail I overlooked.

I would very much like to know exactly why this is failing and how to solve it, but also if anyone has a better way of accomplishing this, then I am all open to ideas.

3 Answers 3

4

The problem you've stated is possibly related to difference in PATH of you when you execute script as logged-in user and when script is executed at startup.

The output of 'which' depends on PATH. So if place where your executable resides is not on PATH, it will return nothing.

I'd advice you to specify path to executable in $command explicitly. Or modify PATH on top of this script like this:

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

Use rc variable command_args instead apps. RC treat command_args in certain way screening special symbols in it for evaluation.

1
  • Thanks for the answer although this didn't help - it got me in the right direction Commented Apr 1, 2012 at 14:57
0

It turns out the real issue was in the following line:

command=$(which fastcgi-mono-server4) 

I am guessing what happened is that under startup this resulted in the empty string, which meant that "-applications..." was evaluated as a command.

2
  • Just like I supposed :) Commented Apr 1, 2012 at 15:02
  • I just saw the answer after I posted this - thanks alot :) Commented Apr 1, 2012 at 15:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.