Proposal: multi-instance and self-contained rc.d script

Hiroki Sato hrs at
Sun Jun 30 21:31:51 UTC 2013


 I am working on rc.d script improvements in terms of the following
 two points.  A prototype is attached.  This still includes some rough
 edges but should be enough to understand the concepts.  I would like
 your comments about them.  (This is posted to -current@ and -rc@, but
 please reply to freebsd-rc@ only)

 1. Multi-instance support

  As you know, an rc.d script invokes ${name}_program with
  configuration variables in /etc/rc.conf.  It works, but it is
  difficult to run multiple instances of a program.  A typical example
  is named---a sysadmin often wants to run two instances of named as a
  caching server and a content DNS server by using different
  named.conf.  In the current framework, two rc.d scripts are needed
  by copying /etc/rc.d/named to /etc/rc.d/named_cache and rewriting
  name= and rcvar=.

  The attached patch allows the following:

  named_instances="cache1 cache2"

  A new variable "{name}_instances" defines instances.  In this
  example, it is named_instances="cache1 cache2".  All of the default
  values of $named_{instname}_foo are automatically set to the same as

  In the implementation, load_rc_config() reads variables for all
  instances and run_rc_command() runs each instance in order.  When
  doing "rc.d/foo stop", run_rc_command() stops the instances in
  reverse order.

  In the patch, killing the processes without pid file does not work
  well yet.  This can be improved.

 2. Self-contained rc.d script

  rc.d scripts depend on /etc/default/rc.conf for the default
  configuration and rc.conf(5) manual page describes the knobs.
  However, it is difficult to understand which variable is related to
  which script.  In addition, /etc/defaults/rc.conf is often out of
  sync with the rc.d scripts.  So, my proposal is as follows:

   a) Define rc.conf variables and the default values in the rc.d
      script which uses them.  "rc.d/foo rcvar" shows the variables
      and the default values.

   b) Make rc.d/foo always have rc.d/foo(8) manual page.

  The attached patch includes an example of rc.d/routed.  The primary
  difference is declaration part of rc.conf variables:

  set_rcvar enable       NO
  set_rcvar program      /sbin/routed
  set_rcvar flags        -q

  These sets the default value of $routed_{enable,program,flags} at
  load_rc_config().  The reason why a simple ": ${routed_enable="NO"}"
  does not work is that it does not work with multi-instance support.

  This is backward-compatible with the current /etc/defaults/rc.conf.
  load_rc_config() sets these values first, and then reads
  /etc/defaults/rc.conf and /etc/rc.conf.d/$name.

  "rc.d/route rcvar" displays the current configuration and available
  variables briefly like the following:

   # routed: network RIP and router discovery routing daemon
   routed_enable="NO"      # (default: "NO")
   routed_program="/sbin/routed"   # (default: "/sbin/routed")
   routed_flags="-q"       # (default: "-q")

  When multi-instance is enabled in rc.conf like this:

   routed_instances="hoge fuga"

  The results of rcvar will be the following:

   # routed: network RIP and router discovery routing daemon
   routed_enable="YES"      # (default: "NO")
   routed_program="/sbin/routed"   # (default: "/sbin/routed")
   routed_flags="-q"       # (default: "-q")

   # routed_hoge: network RIP and router discovery routing daemon: hogehoge
   routed_hoge_enable="YES" # (default: "NO")
   routed_hoge_program="/sbin/routed"      # (default: "/sbin/routed")
   routed_hoge_flags="-q"  # (default: "-q")

   # routed_fuga: network RIP and router discovery routing daemon
   routed_fuga_enable="NO" # (default: "NO")
   routed_fuga_program="/sbin/routed"      # (default: "/sbin/routed")
   routed_fuga_flags=""    # (default: "-q")

 We can remove or comment out all of lines in /etc/defaults/rc.conf,
 and mismatch between /etc/defaults/rc.conf and scripts does not
 occur.  Running "rc.d/foo rcvar" can be used to generate
 /etc/defaults/rc.conf if needed.

 That's all.  Both changes are fully backward compatible and I believe
 they improve flexibility and manageability of rc.d scripts.

 An example of rc.d/routed(8) manual page is also attached.  If these
 changes are acceptable, I would like to split the current (lengthy)
 rc.conf(5) manual page into rc.d/foo(8).

-- Hiroki
-------------- next part --------------
RC.D/ROUTED(8)		FreeBSD System Manager's Manual 	RC.D/ROUTED(8)

     routed -- rc.d script for routed(8) daemon

     routed [fast|force|one]start|stop|restart|rcvar|status|poll

     routed is an rc.d(8) script to control routed(8) daemon.

     The standard rc.d(8) arguments are supported.  For more information, see
     the section of run_rc_command() in the rc(8) manual page.

     The following rc.conf(5) variables are supported.	To show all of the
     supported variables and the default values, use rcvar argument:

     routed_enable	   (bool) Set to ``YES'' to start the routed(8) daemon
			   at boot time.

     routed_flags	   (str) Specify command line flags to the routed(8)

     rc.conf(5), rc(8), routed(8)

     The routed script appeared in FreeBSD 8.0.

     This manual page was written by Hiroki Sato <hrs at>.

FreeBSD 10.0		       January 26, 2012 		  FreeBSD 10.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rc.d_multi_20130701-1.diff
Type: text/x-patch
Size: 8800 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <>

More information about the freebsd-current mailing list