(Ab)using rcng's features to keep rc.d-style services running should they fail.

Doug Barton dougb at FreeBSD.org
Sun Oct 4 19:30:58 UTC 2009

Alex Trull wrote:
> Hi all,
> I realised that because portupgrade/portmaster don't always 
> cleanly restart processes that have died due to being 
> upgraded (mysqld, often!) that this was something I wanted 
> to fix.

I can't speak to portupgrade, however for portmaster there is no such
facility whatsoever. The admin is expected to disable things prior to
an upgrade and re-enable them when the upgrade is done. I don't feel
that this is an overwhelming burden. :)

That said I have it in mind to add a facility to handle this feature.
Stay tuned for more news about this.

> So why not just (ab)use the rcng system with a script ?

First, it's rc.d now if you please. Second, I don't think that there
is anything wrong with your concept that would classify it as abuse,
although I'm not sure I would have implemented it in quite the same way.

> the 
> functionality is all there already to do almost everything 
> needed. To check whether something is running and (if not!) 
> start it.
> So this is my dirty hack so far - runs out of cron with 
> "2>/dev/null" every few minutes and mails me about attempted 
> startups as they happen :
> #!/bin/sh
> # start things that should be running
> find /usr/local/etc/rc.d/ /etc/rc.d/ -type f | egrep -v '(newsyslog|devd|sendmail)' | awk '{print $0" status| grep \"is not running\" && "$0" start"}'  | sh

There are a couple of "problems" with this, although please understand
I'm not criticizing, I'm just offering what I hope are constructive

First, (and I consider this to be a bug) there are several scripts in
/etc/rc.d that are not actually 'startup' scripts in the true sense.
Therefore I would not attempt to run them all. Personally if I were
going to do what you're doing I would make an explicit list of scripts
I wanted to test for.

If you are going to continue to use awk you might want to learn how to
avoid piping it to grep, that's an extra subshell that you don't
really need.

Finally I would do something like this (untested):

for service in ntpd mysqld foo bar; do
	if [ -x /usr/local/etc/rc.d/$service ]; then
	elif [ -x /etc/rc.d/$service ]; then
		echo "Cannot find $service in /etc/rc.d or /usr/local/etc/rc.d"
		exit 1

	$service start | grep -v 'already running'

> (devd, newsyslog and sendmail are left out because their 
> scripts don't behave quite right.)

I don't see anything wrong with devd's output from the status command,
sendmail's is a little hard to parse because it's doing a lot of
things in one script. newsyslog is spitting out 'not running' which
arguably it should not do since that script is not for starting a
persistent service, it's just a 'run at boot' thing. In any case, if
you find what you think are bugs in rc.d related stuff feel free to
report them to freebsd-rc at freebsd.org.




    This .signature sanitized for your protection

More information about the freebsd-hackers mailing list