Subject: Managing identical multiple daemons with a single rc.d script?
To: None <tech-pkg@netbsd.org>
From: Marc Tooley <netbsdMLpostNO@spam.quake.ca>
List: tech-pkg
Date: 01/18/2007 10:53:01
--Boundary-00=_NI8rFhv6MSG0OZP
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


There are some projects that would probably be much better-served if 
they could all be administered from a single rc.d script, and for which 
setting up a new rc.d script each time you run a new instance of the 
daemon is difficult and painful.

For one such creature (the Perforce server daemon,) I've written an rc.d 
script which is basically an extension to the rc.subr mechanism so that 
a single rc.d script can manage an unlimited number of slave servers 
simultaneously.

I'm attaching it to this note.

The criticisms I've received so far (all quite valid) are:

1. It uses hard-coded default locations.
2. It uses some extension logic which would of course break if rc.subr 
ever changes significantly.

Can someone tell me what direction this *should* go to do things 
correctly? Is an rc.d which is aware of the rc.subr and over-rides some 
of the rc.subr mechanisms the right way to go about extending the 
logic? Each daemon (Perforce for example) is unique enough to require 
some fairly complex logic to handle things anyway. I have trouble 
envisioning a generic framework which could be used to extend rc.subr 
in a way that would be useful to people like me, and I suspect that 
we'd end up re-writing large chunks of it anyway.

The primary problem is that in some cases (mine for example) you 
actually do need to run twelve, thirteen, or twenty instances 
simultaneously and the ability to run:

/etc/rc.d/p4d checkpoint

... without additional arguments is *so* useful. Or, if you want to run 
it against just a single one:

/etc/rc.d/p4d checkpoint test_2001.1

Overview of Features

/etc/rc.d/p4d                   
Usage: /etc/rc.d/p4d [fast|force|one](start stop restart rcvar 
checkpoint upgrade refresh verifydb status poll) [main test992 test011 
test012 test021 test022 test031 test032 test042 test051 test052 test061 
test061_104454]

. Can checkpoint cleanly.
. Is aware of unclean shutdowns (machine crashes for example.)
. Can upgrade cleanly.
. Can refresh the db.* files which repacks them optimally for space and 
read-speed purposes.
. Can run a verification -xv to check db.* consistency.
. Is pretty smart about killing and restarting its daemons.
. Additional daemons can be instantly configured or destroyed with 
rc.conf.d.

Comments much appreciated.

P.S. Please reply only to the list; my MX is a little finnicky about 
incoming mail.

--Boundary-00=_NI8rFhv6MSG0OZP
Content-Type: application/x-tgz;
  name="rc.d_extended_example.tar.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="rc.d_extended_example.tar.gz"

H4sIABnAr0UAA+07/XPURrL8av0Vg7wVEor9MoZUOWeuHGw458DmLTa5qzhlZqVZr2KtpOjDax/w
/vbXHzPSSCstJhVyVa+sugteTU9/TU9PT3cr2fYHXhzNBv5AXctFEqp7f/ozGo9GT548uTfip/nv
9mjr8b3x6Mn21ni8tf1kC96PH49H2/dGfz4rq0+R5TIV4l4ax/k6uOVcqfCvYOivfTY3xck8yAT8
Two0hOCiSGUexJGYBaESszgV+VyJNyqFPz0lXsgsF2/jWb6UqRLP7RkOIHt7k+VqMWCkS5mJhZJR
LvJYTJUoMuWLIEI6vxWRR1SWQT4nCm6y7bsCVyMvEkSVeWmQ5GKZBnmuIjG9Ea9l6omTOA7VDTEG
+BAdzo7UUhyp/Me3+/0sUV4wCzyReohmoby5jIJsIYAbXyHWKbPxqrhU4rVaTos0epAJde2pMFTA
berBdkj8mUhkotJHiEVeySCUU9CIzHeEmOd5sjMcLpfLgZcN0kWQD5RfDGQx/N8QsC6GNDMbGkwO
4ji+UqkMQ5GpFP4CnUcgLVD0RYxCgMIW0psHkUL1KdCuJyNU26II8wB2JimF5z4SCkAtcUA7UmRB
dAEcJmkQ5cTrMk59ISMfpiUSFkn5iANgs0R6Khs4oPNzRnkeyYXKdt2FDCKX2H0ZxlMZAo1ZEAW4
VhkpHSWAaUAlBhSZygAY+UVACZxqFkGdyiuYDZx2ExdpZUVaDKLvxYsF8Hh+QfR23d6HN5ODF4f/
+jTMpkE0RLNokpgcH5+IMPbI7LSxvT59e4LaigFxGvg+mAwsQV9zE8yQA0CDVgvqAfWCoZIZpEUU
geLEIoahHGwFlsNwiCtDnJuVcfR+McRx4yxpsUrZkiLPSEsB/DtNQZ9a0ehiSimHVzIdJnpOKeDJ
8zciidMc+cjr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