From: Robin Bowes <robin-lists@robinbowes.com>
To: supervision@list.skarnet.org
Subject: Generic logging run script
Date: Tue, 15 Apr 2008 17:31:31 +0100 [thread overview]
Message-ID: <fu2l8g$lg3$1@ger.gmane.org> (raw)
In-Reply-To: <fu25ue$oee$1@ger.gmane.org>
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 <robin@robinbowes.com>
#
# 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 <http://www.gnu.org/licenses/>.
# 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}"
next prev parent reply other threads:[~2008-04-15 16:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-13 23:19 Help with chpst -e Robin Bowes
2008-04-13 23:52 ` Robin Bowes
2008-04-14 8:34 ` Andras Korn
2008-04-14 8:40 ` Andras Korn
2008-04-14 13:38 ` Robin Bowes
2008-04-14 13:48 ` Andras Korn
2008-04-14 14:16 ` Charlie Brady
2008-04-14 14:31 ` Robin Bowes
2008-04-14 16:41 ` Andras Korn
2008-04-14 21:00 ` Robin Bowes
2008-04-14 21:09 ` Charlie Brady
2008-04-14 21:16 ` Robin Bowes
2008-04-14 22:17 ` Joan Picanyol i Puig
2008-04-14 22:18 ` Andras Korn
2008-04-14 23:05 ` Robin Bowes
2008-04-15 4:27 ` Andras Korn
2008-04-15 12:10 ` Robin Bowes
2008-04-15 16:31 ` Robin Bowes [this message]
2008-04-15 16:33 ` Andras Korn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='fu2l8g$lg3$1@ger.gmane.org' \
--to=robin-lists@robinbowes.com \
--cc=supervision@list.skarnet.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).