From: Andras Korn <korn-supervise@elan.rulez.org>
To: supervision@list.skarnet.org
Subject: Re: Help with chpst -e
Date: Tue, 15 Apr 2008 00:18:21 +0200 [thread overview]
Message-ID: <20080414221821.GV20279@utopia.intra.guy> (raw)
In-Reply-To: <fu0gkg$at1$1@ger.gmane.org>
On Mon, Apr 14, 2008 at 10:00:15PM +0100, Robin Bowes wrote:
>
> This script:
>
> 1. Uses chpst -e to set some vars from ./env (if ./env exists)
> 2. Uses the name of the service dir as the log user and log dir, if
> the are not set in ./env
> 3. Creates the log dir, if it does not exist, and sets permissions
Here is what I use as a generic log/run script, fwiw:
---8<---
#!/bin/sh
SVNAME=$(basename $(dirname $(readlink -f .)))
LOGDIR=/var/log/sv/$SVNAME
LOGUSER=log
SIZE=50000
NUM=15
POSTPROC="gzip -9"
SVLOGDOPTS="-t"
[ -r /etc/default/svlogd ] && . /etc/default/svlogd
[ -r "/etc/default/$SVNAME" ] && . "/etc/default/$SVNAME"
mkdir -p $LOGDIR
chown $LOGUSER $LOGDIR $LOGDIR/lock $LOGDIR/state $LOGDIR/current 2>/dev/null
chmod 1700 $LOGDIR
cd $LOGDIR || exit 1
if [ ! -f config ]; then
cat <<EOF >config
s$SIZE
n$NUM
!tryto -pP $POSTPROC
EOF
fi
exec chpst -u$LOGUSER svlogd $SVLOGDOPTS $LOGDIR
--->8---
This is more "Debianish" in that it gets the configuration from
/etc/default/svlogd, possibly overridden by /etc/default/name-of-service.
These files can override the svlogd config as well (e.g. set a different
postprocessor or retention policy).
I keep /var/log/sv on a separate volume from /var/log because not everything
logs via svlogd and /var/log might be filled.
I went easy on the quoting because I know I don't use LOGDIRs with spaces in
them.
Log directories are sticky and 'config' is owned by root; thus, in the
unlikely event that svlogd were to be compromised, it still couldn't
overwrite its own configuration. Yay!
As for your script, some comments:
> #!/bin/sh
>
> # if we haven't already done so, check for ./env dir
> # if it exists, set some env vars
> if [ "$1" != "have-env" ]; then
> if [ -d ./env ]; then
> exec chpst -e ./env "$0" have-env
> fi
> fi
>
> LOG_PARENT=/var/log
>
> # Get the service name
> logdir=`pwd`
> svcdir=${logdir%/log}
> SERVICE_NAME=${svcdir##*/}
Isn't this a bashism?
> # Set LOGUSER and LOGDIR to default values if not set in ./env
> : ${LOGUSER:=${LOG_PARENT}/${SERVICE_NAME}}
> : ${LOGDIR:=${LOG_PARENT}/${SERVICE_NAME}}
You could use LOGDIR=${LOGDIR:-$LOG_PARENT/$SERVICE_NAME} for no real
benefit. Setting LOGUSER to the name of a directory is probably a
copy-paste mistake, I guess? :)
> # Make sure the log dir exists
> if [ ! -e "${LOGDIR}" ]; then
> mkdir -p "${LOGDIR}"
> fi
This fails if LOGDIR exists but is not a directory. (Of course, that
shouldn't happen.)
> # Set ownership & permissions on the log dir
> chown -R ${LOGUSER} "${LOGDIR}"
This gives ownership of the config file, if it exists, to svlogd. I don't
think that's good.
Andras
--
Andras Korn <korn at chardonnay.math.bme.hu>
<http://chardonnay.math.bme.hu/~korn/> QOTD:
"Meow" ...splat... "Aarf" ...splat... (raining cats and dogs)
next prev parent reply other threads:[~2008-04-14 22:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-13 23:19 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 [this message]
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 ` Generic logging run script Robin Bowes
2008-04-15 16:33 ` Help with chpst -e 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=20080414221821.GV20279@utopia.intra.guy \
--to=korn-supervise@elan.rulez.org \
--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).