I'm trying to configure multiple Zope-Instances as daemons in FreeBSD. Each instance gets a start script in /usr/local/etc/rc.d. Starting works fine, but invoking status or stop is problematic because the PIDs of the running instances get confused (although the PIDs are different, the startscript cannot tell them apart).

Here is the template of the rc scripts:



command="${zope}/bin/runwsgi -v /usr/local/www/zope-instances/${instancename}/etc/zope.ini -d"

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

load_rc_config "$name"
run_rc_command $*

The values between "%%" are set differently for each instance.

When I try to get the status or to stop the process (service instancename status or service instancename stop) the PID of the last instance started is used. With processes able to create a pid-file this is not the case, but runwsgi, the script I need, doesn't create a pid-file.

I understand that procname, which defaults to the command variable, is used to tell the processes apart, but I don't know how to set it properly for my needs.

1 Answer 1


I think you are on the right path but that you expect the rc framework to handle more things automatically than it actually does.

It looks like you might be familiar with Practical rc.d scripting in BSD as you touch upon:

For instance, stop must know the PID of the process to terminate it. In the present case, rc.subr(8) will scan through the list of all processes, looking for a process with its name equal to $procname. The latter is another variable of meaning to rc.subr(8), and its value defaults to that of command. In other words, when we set command, procname is effectively set to the same value.

Your life will become easier if you accept that you do not have a "simple" daemon and look through the next section with the "advanced" daemon. So rather than setting procname to the correct name so it can scan for the PID - simply set the PID file. pidfile is a known entity which rc.subr(8) understands.

You are using daemon to detach from the terminal and that handles pid files nicely.

So if you add:


And change your start_cmd:

start_cmd="/usr/sbin/daemon -P ${pidfile} -u myuser $command"

Then you should be good to go.

Another nice article outlining a simple rc script is Supervised FreeBSD rc.d script for a Go daemon - the gist of it is as simple as:

# PROVIDE: goprogram
# REQUIRE: networking

. /etc/rc.subr

command_args="-P ${pidfile} -r -f ${goprogram_command}"

load_rc_config $name
: ${goprogram_enable:=no}

run_rc_command "$1"

Notice how the main difference is that they control the pid file rather than relying on $procname

  • Thank you! In the meantime I had figured it out, having found exactly the web pages you mention. I should have read the man-page about daemon before asking the question... Feb 27, 2019 at 15:53

You must log in to answer this question.

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