Friday, July 11, 2008

rc.local trick

PuffyThis is really just a quick tip for (re-)starting daemons. Many converts from other operating systems complain about OpenBSD's lack of an rc.d or init.d structure to quickly re-start/stop daemons. Admittedly, it was a slight annoyance when I switched years ago. But, I've gotten used to either looking up a daemon's PID and killing it or using pkill(1). Then looking at /etc/rc.local to find the commands (and possibly /etc/rc.conf* for variables) to re-start the daemon.

Lately, I've started adding something like this in my /etc/rc.local:

## OpenLDAP Server
if [ "$1" = "" -o "$1" = "openldap" ]; then
slapd_flags="-u _openldap"
if [ "$slapd_flags" != "NO" -a -x /usr/local/libexec/slapd ]; then
      install -d -o _openldap /var/run/openldap
      /usr/local/libexec/slapd $slapd_flags
      echo -n ' slapd'

That way, I can stop OpenLDAP by running `sudo pkill slapd` and restart it with `sudo sh /etc/rc.local openldap`. The boot process is not affected because $1 == "" so, all daemons in my rc.local are started.

No comments:

Post a Comment