From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.sysutils.supervision.general/1711 Path: news.gmane.org!not-for-mail From: Andras Korn Newsgroups: gmane.comp.sysutils.supervision.general Subject: Re: Help with chpst -e Date: Tue, 15 Apr 2008 00:18:21 +0200 Message-ID: <20080414221821.GV20279@utopia.intra.guy> References: <20080414083428.GK20279@utopia.intra.guy> <20080414164126.GP20279@utopia.intra.guy> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 X-Trace: ger.gmane.org 1208211511 29250 80.91.229.12 (14 Apr 2008 22:18:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Apr 2008 22:18:31 +0000 (UTC) To: supervision@list.skarnet.org Original-X-From: supervision-return-1946-gcsg-supervision=m.gmane.org@list.skarnet.org Tue Apr 15 00:19:04 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 1JlX0x-0006P3-2c for gcsg-supervision@gmane.org; Tue, 15 Apr 2008 00:19:03 +0200 Original-Received: (qmail 26814 invoked by uid 76); 14 Apr 2008 22:18:44 -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 26807 invoked from network); 14 Apr 2008 22:18:44 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-11) Xref: news.gmane.org gmane.comp.sysutils.supervision.general:1711 Archived-At: 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 <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 QOTD: "Meow" ...splat... "Aarf" ...splat... (raining cats and dogs)