Rcd /

Daemon control and mangement system (rcctl)

The rcctl utility can enable or disable a base system service or a base system or package daemon in rc.conf.local or display its configuration and status. For a daemon, it can also change the command line arguments, the user to run as, the rc.d action timeout or call its rc.d daemon control script.

The /etc/rc.d directory contains shell scripts to start, stop, and reconfigure daemon programs (“services”).

  • Services installed from packages may be started at boot time in the order specified by the pkg_scripts variable from rc.conf the order will be reversed during shutdown. Services comprising OpenBSD base are started by rc.**

The options are as follows:

-d........Setting this option will print the function names as they are called and prevent the rc.subr framework from redirecting stdout and stderr to /dev/null. This is used to allow debugging of failed actions.

-f.........This option only affects the start action. It will forcibly start the daemon whatever value daemon_flags is set to. If daemon_flags is set to “NO”, execution will continue with the script's own defaults unless other flags are specified.

Each such script responds to the following actions:

start...........-Start the service, if not already running.
stop...........-Stop the service.
reload.......-Tell the daemon to reload its configuration.
restart.......-Perform a stop, then a start.
check.........-Return 0 if the daemon is running or 1 if it is not.

Run a process as system daemon

  * This topic shows how to run a simple process as priviledged system daemon which enable it be started/stopped/enabled by rcctl daemon control  system
  * Here we'll use hopm process to explain how to launch it into system daemon.
  * For this to work , we'll first install hopm as user hopm, group hopm  as usual refer more of it hopm
  * Then we'll create a rc.d script in /etc/rc.d dir by name of "hopm"
  * Then We'll lauch the process by calling "rcctl start hopm" with root priviledge

Creating rc.d file for process (hopm)

Now give following commands -

doas  cd /etc/rc.d
doas  nano hopm

In nano editor add the following code daemon should be set equal to "/path/to/daemon"

#!/bin/ksh
daemon="/home/hopm/hopm/bin/hopm"
. /etc/rc.d/rc.subr
rc_cmd $1

save the file and run the following command.

$ chmod +x hopm
$ doas rcctl start hopm
$ doas rcctl enable hopm

First command will start the processs(hopm) with root priviledge system daemon and second command will enable it to be restarted automatically at booting up.