#! /bin/sh
#
# ttywatch        This starts and stops the ttywatch device logger
#
# chkconfig: - 50 50
# description: The ttywatch device output logging facility
#
# processname: /usr/sbin/ttywatch
# pidfile: /var/run/ttywatch.pid
# config: /etc/ttywatch.conf
# config: /etc/ttywatch.d/*
### BEGIN INIT INFO
# Provides: ttywatch
# Default-Start: 
# Default-Stop: 
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Short-Description: The ttywatch device output logging facility
# Description: The ttywatch device output logging facility
### END INIT INFO




# Source function library.
. /etc/init.d/functions

[ -f /usr/sbin/ttywatch ] || exit 1

RETVAL=0
CONFIG="--config /etc/ttywatch.conf"
[ -d /etc/ttywatch.d ] && {
	shopt -s nullglob
	GLOBIGNORE="*~ *.bak *.rpm*"
	for file in /etc/ttywatch.d/* ; do
		CONFIG="$CONFIG --config $file"
	done
	shopt -u nullglob
}

start(){
    echo -n "Starting ttywatch: "
    daemon /usr/sbin/ttywatch $CONFIG --pidfile /var/run/ttywatch.pid --daemon
    RETVAL=$?
    echo
    touch /var/lock/subsys/ttywatch
}

stop(){
    echo -n "Stopping ttywatch: "
    killproc /usr/sbin/ttywatch
    RETVAL=$?
    echo
    rm -f /var/lock/subsys/ttywatch
}

restart(){
    stop
    start
}

reload(){
    killproc /usr/sbin/ttywatch -HUP
    RETVAL=$?
}

condrestart(){
    [ -e /var/lock/subsys/ttywatch ] && restart
}


# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
	status /usr/sbin/ttywatch
	;;
    restart)
	restart
	;;
    reload)
	reload
	;;
    force-reload)
	reload
	;;
    condrestart)
	condrestart
	;;
    try-restart)
	condrestart
	;;
    *)
	echo "Usage: ttywatch {start|stop|status|restart|condrestart|reload}"
	RETVAL=1
esac

exit $RETVAL
