I have a FreeBSD jail in which I run a server using the command:

/usr/sbin/daemon /path/to/script.py

At the moment I have to run this command every time I restart the machine and the jail starts. I'd like to have this command started from /etc/rc. Is there an easy way to create a FreeBSD rc script for a daemon command?

UPDATE: I read through this BSD documentation about rc scripts, and from that I created the following script in /etc/rc.d/pytivo:


. /etc/rc.subr


command="/usr/sbin/daemon -u jnet $procname"

load_rc_config $name
run_rc_command "$1"

This works to start the python script I am wanting as a daemon when the jail starts... (given pytivo_enable="YES" is in /etc/rc.conf) but the rc script doesn't know if the daemon is running (it thinks it isn't when it is) and it gives a warning when I try to start it:

[root@meryl /home/jnet]# /etc/rc.d/pytivo start
[: /usr/sbin/daemon: unexpected operator
Starting pytivo.
[root@meryl /home/jnet]# 

So it's close, and it works, but I feel like I should be able to get better functionality than this.

  • You need to put this script somewhere(Can't remember now) and put a line XX_enable="YES" in /etc/rc.conf to make it auto start. Start by finding existing scripts
    – daisy
    Oct 10, 2012 at 14:50
  • I'm looking for an easy way to create the script... Is there a good script I can copy and reuse?
    – Josh
    Oct 10, 2012 at 14:52

2 Answers 2


command should not contain multiple words. This is the cause of the [ error you see. You should set any flags separately.

Also, you should use pytivo_user to set the running uid, and not daemon -u. See the rc.subr(8) man page for all these magic variables.

Also, you should let the rc subsystem know that pytivo is a Python script so that it can find the process when it checks to see if it's running.

Finally, you should use the idiomatic set_rcvar for rcvar.

Something like this (I'm not sure this is the right Python path):



. /etc/rc.subr

start_cmd="/usr/sbin/daemon -u $pytivo_user $command"

load_rc_config $name
run_rc_command "$1"
  • The problem is that usr/local/pytivo/pyTivo.py doesn't daemonize, therefore without calling /usr/bin/daemon I will just get the command running in the forground when I run /etc/rc.d/pytivo start
    – Josh
    Oct 15, 2012 at 12:50
  • However this does correct the status and stop commands!
    – Josh
    Oct 15, 2012 at 12:51
  • Oh, the script doesn't daemonize? I think the easiest fix is to set start_cmd before calling load_rc_config: start_cmd="/usr/sbin/daemon -u $pytivo_user $command"
    – aecolley
    Oct 17, 2012 at 19:49
  • This had the magic I needed to get my script running. Thanks! May 29, 2014 at 23:13

If you don't need an rc-script, you could use just /etc/rc.local.

For your rc script you are missing dependenct comments, at least a line


should help, that it is run at the right time.

You also may need to define a pidfile

  • I was hopeful this would help, but it doesn't. I still get : /usr/sbin/daemon: unexpected operator and my rc script still doesn't know if the script is actually running.
    – Josh
    Oct 12, 2012 at 12:31
  • you could try to invoke the script with -x to see which command fails
    – arved
    Oct 12, 2012 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .