#! /bin/sh

. /etc/rc.config

# The echo return value for success (defined in /etc/rc.config).
return=$rc_done

PIDFILE=/home/logsurfer/logsurfer.pid
if [ -f $PIDFILE ]; then
   pid=`/bin/cat /home/logsurfer/logsurfer.pid`
fi

case "$1" in
   start)
      echo -n "Starting service logsurfer"

      /bin/su - logsurfer -c "/usr/bin/logsurfer \
         -c /etc/logsurfer.conf \
         -d /home/logsurfer/dumpfile \
         -p $PIDFILE \
         -l `wc -l < /var/log/syslog/messages` \
         -f /var/log/syslog/messages \
         >>   /home/logsurfer/ls-error 2>&1 & " || return=$rc_failed

	echo -e "$return"
	;;
    stop)
	echo -n "Shutting down service logsurfer"

        kill -TERM $pid && \
        rm -f $PIDFILE || return=$rc_failed

	echo -e "$return"
	;;
    restart)
	$0 stop  &&  $0 start  ||  return=$rc_failed
	;;
    reload)
	kill -HUP $pid  ||  return=$rc_failed
	;;
    status)
	echo -n "Checking for service logsurfer: "
	## Check status with checkproc(8), if process is running
	## checkproc will return with exit status 0.

	checkproc /usr/bin/logsurfer && echo OK || echo No process
	;;
    probe)
	## Optional: Probe for the necessity of a reload,
	## give out the argument which is required for a reload.

	test /etc/logsurfer.conf -nt /var/run/logsurfer.pid && echo reload
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|reload[|probe]}"
	exit 1
	;;
esac

# Inform the caller not only verbosely and set an exit status.
test "$return" = "$rc_done" || exit 1
exit 0

