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
:
#!/bin/sh
. /etc/rc.subr
name=pytivo
rcvar=pytivo_enable
procname="/usr/local/pytivo/pyTivo.py"
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.
XX_enable="YES"
in /etc/rc.conf to make it auto start. Start by finding existing scripts