From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.sysutils.supervision.general/1715 Path: news.gmane.org!not-for-mail From: Robin Bowes Newsgroups: gmane.comp.sysutils.supervision.general Subject: Generic logging run script Date: Tue, 15 Apr 2008 17:31:31 +0100 Message-ID: References: <20080414083428.GK20279@utopia.intra.guy> <20080414164126.GP20279@utopia.intra.guy> <20080414221821.GV20279@utopia.intra.guy> <20080415042737.GW20279@utopia.intra.guy> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1208278584 28379 80.91.229.12 (15 Apr 2008 16:56:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Apr 2008 16:56:24 +0000 (UTC) To: supervision@list.skarnet.org Original-X-From: supervision-return-1950-gcsg-supervision=m.gmane.org@list.skarnet.org Tue Apr 15 18:57:01 2008 connect(): Connection refused Return-path: Envelope-to: gcsg-supervision@gmane.org Original-Received: from antah.skarnet.org ([212.85.147.14]) by lo.gmane.org with smtp (Exim 4.50) id 1Jlo4q-0003MZ-5X for gcsg-supervision@gmane.org; Tue, 15 Apr 2008 18:32:12 +0200 Original-Received: (qmail 22701 invoked by uid 76); 15 Apr 2008 16:31:52 -0000 Mailing-List: contact supervision-help@list.skarnet.org; run by ezmlm List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Archive: Original-Received: (qmail 22692 invoked from network); 15 Apr 2008 16:31:52 -0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 137 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 84-51-160-74.pambow882.adsl.metronet.co.uk User-Agent: Thunderbird 2.0.0.12 (X11/20080226) In-Reply-To: X-Enigmail-Version: 0.95.6 Original-Sender: news Xref: news.gmane.org gmane.comp.sysutils.supervision.general:1715 Archived-At: Hi all, I've taken some of the ideas/suggestions from this thread and come up with this generic logging script. I've written it to use /etc/sysconfig/ for configuration, as I work mainly on RH-flavour distributions and that's what they use. To use: 1. Save the script somewhere and chmod +x 2. symlink the script into your services' log dir By default it will run as user $SVNAME and log to dir /var/log/sv/$SVNAME If you want to change this, either for all services, or for just one service, you'll need to create the following dir structure: mkdir -p /etc/sysconfig/sv/default/log/ Then for each of your services: mkdir -p /etc/sysconfig/sv/$SVNAME/log/ To change something for all services: echo "LOGPARENT=/var/log" > /etc/sysconfig/sv/default/log/settings To change something for just one service: echo "LOGUSER=dnslog" > /etc/sysconfig/sv/dnscache/log/settings echo "LOGUSER=dnslog" > /etc/sysconfig/sv/tinydns/log/settings If you want to use something other than the standard svlogd logging configuration, create a config file: cat > /etc/sysconfig/sv/default/log/config << EOCONFIG s2000000 n20 EOCONFIG Or for a specific service: cat > /etc/sysconfig/sv/tinydns/log/config << EOCONFIG s4000000 n50 EOCONFIG As always, I'd appreciate any comments/suggestions. Here's the script: #!/bin/sh # This is a generic logging script services using runit/svlogd # # The service configuration is taken from the following files: # /etc/sysconfig/sv/$SVNAME/log/settings # /etc/sysconfig/sv/default/log/settings # # The following ENV vars can be set in the "settings" files: # LOGPARENT - log dir will be set to $LOGPARENT/$SVNAME # LOGDIR - full path. If specified, over-rides $LOGPARENT # LOGUSER - user the logging process should run as # # The service-specific files are used in preference to the defaults. # # If no settings files are found, the logging service will run as user # $SVNAME and write to "/var/log/sv/$SVNAME" # # The behaviour of the svlogd is controlled by a file $LOGDIR/config. # This file is copied from: # /etc/sysconfig/sv/$SVNAME/log/config # /etc/sysconfig/sv/default/log/config # # The service-specific files are used in preference to the defaults. # # If no config files are found, svlogd defaults are used. # # Copyright (c) 2008 by Robin Bowes # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Get the name of the service this log belongs to SVNAME=$(basename $(dirname $(readlink -f .))) # Where to look for configuration settings CFGBASE=/etc/sysconfig/sv # cp is aliased to "cp -i" on some distros cp="/bin/cp" # Get defaults for logging and this service log [ -r "${CFGBASE}/default/log/settings" ] && \ . "${CFGBASE}/default/log/settings" [ -r "${CFGBASE}/${SVNAME}/log/settings" ] && \ . "${CFGBASE}/${SVNAME}/log/settings" # Set LOG_PARENT, LOGUSER and LOGDIR to default values if not set already LOGUSER=${LOGUSER:-$SVNAME} LOGPARENT=${LOGPARENT:-/var/log/sv} LOGDIR=${LOGDIR:-"$LOGPARENT/${SVNAME}"} # make sure log parent exists [ -d "${LOGPARENT}" ] || exit 1 ] # Make sure the log dir exists [ -d "${LOGDIR}" ] || mkdir "${LOGDIR}" || exit 1 # Configure logging. Check for sv-specific then default config if [ -r "${CFGBASE}/${SVNAME}/log/config}" ]; then ${cp} "${CFGBASE}/${SVNAME}/log/config}" "${LOGDIR}/config" elif [ -r "${CFGBASE}/default/log/config}" ]; then ${cp} "${CFGBASE}/default/log/config}" "${LOGDIR}/config" fi # Set ownership on the log dir chown -R ${LOGUSER} "${LOGDIR}" # reset perms on log config file, if it exists [ -r "${LOGDIR}/config" ] && chown root "${LOGDIR}/config" # Set perms on the log dir chmod 750 "${LOGDIR}" chmod g+s "${LOGDIR}" # Now run the log process exec chpst -u "${LOGUSER}" svlogd -tt "${LOGDIR}"