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

From: Hiroki Sato <hrs_at_FreeBSD.org>
Date: Mon, 01 Jul 2013 06:29:53 +0900 (JST)
Hi,

 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_at_ and -rc_at_, but
 please reply to freebsd-rc_at_ 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_enable="YES"
  named_instances="cache1 cache2"
  named_conf="/etc/namedb/named.conf"
  named_cache1_enable="YES"
  named_cache1_conf="/etc/namedb/named_cache1.conf"
  named_cache2_enable="NO"
  named_cache2_conf="/etc/namedb/named_cache2.conf"

  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
  $named_foo.

  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_enable="YES"
   routed_instances="hoge fuga"
   routed_hoge_desc="hogehoge"
   routed_fuga_enable="NO"
   routed_fuga_flags=""

  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

RC.D/ROUTED(8)		FreeBSD System Manager's Manual 	RC.D/ROUTED(8)

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

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

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

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

CONFIGURATION VARIABLES
     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)
			   daemon.

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

HISTORY
     The routed script appeared in FreeBSD 8.0.

AUTHORS
     This manual page was written by Hiroki Sato <hrs_at_FreeBSD.org>.

FreeBSD 10.0		       January 26, 2012 		  FreeBSD 10.0

Received on Sun Jun 30 2013 - 19:31:51 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:39 UTC