Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

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"
share|improve this answer
add comment

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.

share|improve this answer
    
Just like I supposed :) –  Vadym S. Khondar Apr 1 '12 at 15:02
    
I just saw the answer after I posted this - thanks alot :) –  kastermester Apr 1 '12 at 15:02
add comment

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

share|improve this answer
    
Thanks for the answer although this didn't help - it got me in the right direction –  kastermester Apr 1 '12 at 14:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.