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

Alex Trull alex at trull.org
Sun Oct 4 14:35:59 UTC 2009

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.

However, I'd seen the daemontools and wasn't a fan - too 
much to configure with weird directories and so forth and 
while monit is very powerful it also takes too much effort 
to do what could be so much simpler.

So why not just (ab)use the rcng system with a script ? 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 :

# 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

Performance is not stunning, thankfuly my cpus are quite 

real    0m1.198s
user    0m0.610s
sys     0m0.877s

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

Initialy I used it purely for the /usr/local/etc/rc.d but I 
had a base ntpd die on me one evening so decided to throw in 
/etc/rc.d/ too. This script has also caught a few other 
failures in port-installed daemons in addition to the 
ever-common mysqld-upgraded one.

Of course it is relatively inefficient executing all those 
scripts on a regular basis - but it works - has anyone 
thought of cleaner/more efficient ways of doing this and 
getting more out of the rcng framework ? Or simpler for that 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20091004/a6d7598f/attachment.pgp

More information about the freebsd-hackers mailing list