Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 255329 - init script for app-admin/swatch
Summary: init script for app-admin/swatch
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Wormo (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-17 23:50 UTC by Phil
Modified: 2012-04-05 17:17 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Phil 2009-01-17 23:50:04 UTC
Hi,

I've written an init script for swatch (the simple logfile watcher).
Hope you like it, I do already. ;)

Greetings, Phil

PS: Sorry for the ugly pasting that follows, but I can't find this "attach
file" button. Shouldn't there be one?

--------- START /etc/conf.d/swatch -------------
# Path to the swatch program. Default should fit.
#SWATCH_BINARY="/usr/bin/swatch"

# Swatchrc to read patterns and actions from.
#SWATCHRC="/etc/swatchrc"

# The actual file to parse.
LOGFILE="/var/log/lighttpd/access.log"

# Where to output the generated script to. Should not be writable by others.
#SWATCH_SCRIPT="/var/run/swatch_script.pl"

# Whether to parse the complete file once at startup. Defaults to "NO".
PARSE_FULL="YES"
--------- END /etc/conf.d/swatch -------------

--------- START /etc/init.d/swatch -----------
#!/sbin/runscript
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# some notes on the swatch init script:
# - Per default, swatch generates a perl script with some random
#   prefix and calls perl internally. To prevent cluttering the
#   filesystem with temporary scripts, the following uses a two
#   step aproach: first output the script to a defined name, and
#   then call perl manually.
# - This init script forcibly uses the option '--use-cpan-file-tail',
#   as otherwise the generated perl script would use system() to
#   call the tail binary, leading to a perl process not reacting on
#   any signal (the tail process has to be killed in that case).

depend() {
	need logger
}

SWATCH_BINARY=${SWATCH_BINARY:-/usr/bin/swatch}
SWATCHRC=${SWATCH_CONFIG:-/etc/swatchrc}
LOGFILE=${LOGFILE:-/var/log/syslog}
SWATCH_SCRIPT=${SWATCH_SCRIPT:-/var/run/swatch_script.pl}

gen_script() { # (-t|-f)
	ebegin "Generating watch script from config"
	${SWATCH_BINARY} --dump-script="${SWATCH_SCRIPT}" \
		--use-cpan-file-tail -c "${SWATCHRC}" \
		$1 "${LOGFILE}"
	eend $?
}

parse_full() {
	gen_script -f
	ebegin "Parsing complete file once"
	/usr/bin/perl ${SWATCH_SCRIPT} 1>/dev/null
	eend $?
}

start() {
	if [ x"$PARSE_FULL" == xYES ]; then
		parse_full
	fi
	gen_script -t
	ebegin "Starting swatch"
	start-stop-daemon --start --quiet --background \
		--make-pidfile --pidfile /var/run/swatch.pid \
		--exec /usr/bin/perl -- ${SWATCH_SCRIPT}
	eend $?
}

stop() {
	ebegin "Stopping swatch"
	start-stop-daemon --stop --exec /usr/bin/perl \
		--pidfile /var/run/swatch.pid --quiet
	eend $?
}
--------- END /etc/init.d/swatch -----------
Comment 1 Wormo (RETIRED) gentoo-dev 2009-01-18 01:05:36 UTC
Thanks for submitting your init script :)

For future reference, the attachment link you were looking for is called "Create a new attachment" and is inside the little table below the "keywords" field in the bug form. 

Since there is currently no maintainer for this package, I'll go ahead and take this bug and give your init script a try.
Comment 2 Phil 2009-01-18 15:14:06 UTC
(In reply to comment #1)
> Thanks for submitting your init script :)

No problem, thanks for taking care of it in return. ;)

> For future reference, the attachment link you were looking for is called
> "Create a new attachment" and is inside the little table below the "keywords"
> field in the bug form. 

Hmm. Seems like the little table you mention exists only when displaying an
existing bug, not in the mask for new ones. (Please note that I used the "Ex"
link under "Actions", but as far as I've checked the wizzard seems not to offer
file attachments, either.

Maybe it's possible to add a note to the bug creation mask, saying that files
can be attached after the bug has been created.

Greetings, Phil
Comment 3 Chema Alonso Josa (RETIRED) gentoo-dev 2011-08-20 12:09:03 UTC
Init script included in app-admin/swatch-3.2.3-r1. Requested stabilization of this version in bug #379961

Thanks for your work!