FreeBSD rc.d script doesn't work when starting up
Posted
by
kastermester
on Server Fault
See other posts from Server Fault
or by kastermester
Published on 2012-04-01T14:12:30Z
Indexed on
2012/04/01
17:33 UTC
Read the original article
Hit count: 304
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.
© Server Fault or respective owner