#!/bin/bash # # swatch # # chkconfig: 2345 90 35 # description: swatch start/stop script # # origial script by http://centossrv.com/swatch.shtml # # $Revision: 4 $ # $Date:: 2009-12-03 18:08:11 #$ System House ACT ($Author: tyamaguchi $) # Source function library. . /etc/rc.d/init.d/functions PATH=/sbin:/usr/local/bin:/bin:/usr/bin PROG="swatch" LOCKFILE="/var/lock/subsys/swatch" start() { # Start daemons. ls /var/run/swatch_*.pid > /dev/null 2>&1 if [ $? -ne 0 ]; then echo -n $"Starting $PROG: " PNO=0 for CONF in /etc/swatch/*.conf do PNO=`expr $PNO + 1` WATCHLOG=`grep "^# logfile" $CONF | awk '{ print $3 }'` swatch --config-file $CONF \ --tail-file $WATCHLOG \ --script-dir=/tmp \ --awk-field-syntax \ --use-cpan-file-tail \ --daemon \ --pid-file /var/run/swatch_$PNO.pid \ >> /var/log/swatch/swatch.log 2>&1 RETVAL=$? [ $RETVAL != 0 ] && return $RETVAL done if [ $RETVAL = 0 ]; then echo_success touch $LOCKFILE else echo_failure fi echo return $RETVAL else echo "$PROG is already started" fi } stop() { # Stop daemons. ls /var/run/swatch_*.pid > /dev/null 2>&1 if [ $? -eq 0 ]; then echo -n $"Stopping $PROG: " for PID in /var/run/swatch_*.pid do kill $(cat $PID) rm -f $PID done echo_success rm -f $LOCKFILE /tmp/.swatch_script.* echo else echo "$PROG is not running" fi } status() { ls /var/run/swatch_*.pid > /dev/null 2>&1 if [ $? -eq 0 ]; then echo -n "$PROG (pid" for PID in /var/run/swatch_*.pid do echo -n " `cat $PID`" done echo ") is running..." else echo "$PROG is stopped" fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo "Usage: $PROG {start|stop|restart|status}" exit 1 esac exit $RETVAL