how to rc.conf in FreeBSD 8

Of course, read manuals and messages, but try reading the rc scripts. It is the best way to get to know the startup system, and you really don't need to know exactly what happens in each of the script to get the feeling of it.

For example, when I first installed FreeBSD (about a year ago) I had some trouble getting samba to run, as I assumed Samba would start if I put
Code:
samba_enabled="YES"
in rc.conf, since that was the name of the RC script. It didn't, because samba actually started with two separate daemons smbd and nbmd, which I found out after reading the rc script in /usr/local/etc/rc.d/.

Sometimes it is faster to just cat or less the rc script. They mostly aren't rocket science, anyway.
 
Hi again

I am trying to run an rc script (below) to start Red5 but it doesn't seem to be working.

The script is placed in /usr/local/etc/rc.d and I have added
Code:
red5_enable="YES"
to rc.conf. I have created an account named red5 and installed it into /home/red5.

I am advised that the script does work on another system and red5 works for me in standalone mode by running ~/red5.sh but I need it to run as a service when I boot. I am inclined to think it may have something to do with the fact that the media server is jailed but only the host's dmesg is available and it does not mention red5 at all.

Where else can I look for clues?


Code:
#!/bin/sh
export RED5_HOME=/home/red5/
export JAVA_HOME=/usr/local/diablo-jdk1.6.0

red5_user="${red5_user:-"red5"}"
red5_pidfile="${red5_pidfile-"/var/run/red5.pid"}"
red5_chdir=$RED5_HOME
. "/etc/rc.subr"

name="red5"
rcvar=`set_rcvar`
command="$RED5_HOME/${name}.sh"
command_args=" > /dev/null 2>&1&"
pidfile="${red5_pidfile}"

start_postcmd=start_postcmd
stop_cmd="echo \"Stopping ${name}.\"; ${RED5_HOME}/red5-shutdown.sh"

start_postcmd() {
    local seconds
    for seconds in 1 2 3; do
      sleep 1
    done
    ps -U red5 -a | grep 'red5.root' | cut -d ' ' -f1 | tr -d '\n' > ${pidfile}
}

load_rc_config "${name}"

run_rc_command "$1"


Thanks :)
 
Code:
    for seconds in 1 2 3; do
      sleep 1
    done
Seriously? Try "sleep 3" instead of this.

Code:
ps -U red5 -a | grep 'red5.root' | cut -d ' ' -f1 | tr -d '\n' > ${pidfile}

This is more readable and works if you've changed the user:
Code:
pgrep -U ${red5_user} -f red5.root > ${pidfile}

One way to trace it is to start it with the -x option:
# sh -x /usr/local/etc/rc.d/red5 start
 
SirDice said:
One way to trace it is to start it with the -x option:
# sh -x /usr/local/etc/rc.d/red5 start

Thanks :)

I got the error below with both versions but I will have to look it up tomorrow, I assume it's just a permissions thing.


Code:
eval: cannot create /var/run/red5.pid: Permission denied
 
Yes, your red5 user doesn't have permission to write there, only root does. Simple solution is to create a /var/run/red5/ directory and give the red5 user permission on that. Store the pid file in the directory.
 
Thanks :)


Changing the pid location worked when I first ran
Code:
# sh -x /usr/local/etc/rc.d/red5 start
as the user red5! :)


But after I rebooted, red5 had not started at all and now it will not start manually as user red5 anymore, there are no errors printed out and top shows a java service running it just doesn't actually work. Though when I run it from root it works perfectly.

Odd.. but at least it works, albeit manually. :)
 
phoenix said:
Oh, and for those wanting to use service(1), it's just a shell script, so it can be "backported" to any FreeBSD release that uses RCng. IOW, it should work on any release since 5.2. I've tested it no 6.3 and it works quite nicely.

Ha I though I had missed something over the years when I first learned of service in the last month or so. I imagine I will be typing paths to /usr/local/etc/rc.d/service {start|stop} for some time until I can recondition my fingers.

service seems like a nice shell wrapper.
 
Back
Top