From owner-freebsd-rc@FreeBSD.ORG Sun Oct 4 19:30:57 2009 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D0FE6106568B for ; Sun, 4 Oct 2009 19:30:57 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from mail2.fluidhosting.com (mx21.fluidhosting.com [204.14.89.4]) by mx1.freebsd.org (Postfix) with ESMTP id 7D11C8FC17 for ; Sun, 4 Oct 2009 19:30:57 +0000 (UTC) Received: (qmail 15085 invoked by uid 399); 4 Oct 2009 19:30:56 -0000 Received: from localhost (HELO foreign.dougb.net) (dougb@dougbarton.us@127.0.0.1) by localhost with ESMTPAM; 4 Oct 2009 19:30:56 -0000 X-Originating-IP: 127.0.0.1 X-Sender: dougb@dougbarton.us Message-ID: <4AC8F7EF.9010303@FreeBSD.org> Date: Sun, 04 Oct 2009 12:30:55 -0700 From: Doug Barton Organization: http://www.FreeBSD.org/ User-Agent: Thunderbird 2.0.0.23 (X11/20090822) MIME-Version: 1.0 To: Alex Trull References: <20091004141118.GG95662@syndicate.internationalconspiracy.org> In-Reply-To: <20091004141118.GG95662@syndicate.internationalconspiracy.org> X-Enigmail-Version: 0.96.0 OpenPGP: id=D5B2F0FB Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org, freebsd-rc@freebsd.org Subject: Re: (Ab)using rcng's features to keep rc.d-style services running should they fail. X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Oct 2009 19:30:58 -0000 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 suggestions. 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 service=/usr/local/etc/rc.d/$service elif [ -x /etc/rc.d/$service ]; then service=/etc/rc.d/$service else echo "Cannot find $service in /etc/rc.d or /usr/local/etc/rc.d" exit 1 fi $service start | grep -v 'already running' done > (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@freebsd.org. hth, Doug -- This .signature sanitized for your protection