#! /bin/sh

### BEGIN INIT INFO
# Provides:       likewise-evtlogd
# Required-Start: $local-fs $network $syslog
# Required-Stop:  $local-fs $network $syslog
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Start translation of syslog into eventlog entries
### END INIT INFO

# 
#
#  The contents of this file are subject to the terms of the
#  Common Development and Distribution License, Version 1.0 only
#  (the "License").  You may not use this file except in compliance
#  with the License.
# 
#  You can obtain a copy of the license at 
#  http://www.opensource.org/licenses/cddl1.php
# 
#  When distributing Covered Code, include this CDDL HEADER in each
#  file and include the original License file at src/license.txt.
#  If applicable, add the following below this CDDL HEADER, with the
#  fields enclosed by brackets "[ ]" replaced with your own identifying
#  information: Portions Copyright [yyyy] [name of copyright owner]
# 

#  Copyright (c) 2005 by Centeris, Inc.  All rights reserved.
#  Use is subject to license terms.
#  Initial Developer updates, news, and information may be found at 
#  http://sourceforge.net/projects/likewiseopenagt
#
#

# /etc/init.d/likewise-evtlogd
# 
# likewise location stuff

LIKEWISEDIR=/opt/likewise
LIKEWISEBINDIR=$LIKEWISEDIR/bin
LIKEWISELIBDIR=$LIKEWISEDIR/lib

#
# execute platform specific pieces
#

# some dists (ie: SuSE) contain the UN LSB rc.status file, so we use that one
# otherwise, we will use the one we brought with us.

if [ -e /etc/rc.status ]; then . /etc/rc.status
else                           . $LIKEWISELIBDIR/rc.status
fi

# other dists (ie: RHEL4) contain the functions file
# NB: Note that this is in addition to the rc.status stuff, on machines that
# have this file, we need it for some daemon management functions.
# BUGBUG: this is not so great, and may not hold true for other dists that we
# may wish to work with in the future.

if [ -e /etc/init.d/functions ]; then . /etc/init.d/functions; fi



case "$EVTLOG_DAEMON" in
    *)
	evtlogpl=evtsyslog.pl
	config=/etc/syslog.conf
	perlexe=/usr/bin/perl
	;;
esac

# note that we pass the name of the pid file to the script so that we all agreee on
# which pidfile we should be looking at

evtlog_pid=/var/run/evtlog.pid
evtlog_cmd="$perlexe -I$LIKEWISEBINDIR $LIKEWISEBINDIR/$evtlogpl $evtlog_pid >/dev/null"

# check for scripts and libs
test -s $LIKEWISEBINDIR/$evtlogpl || exit 6
test -x $perlexe || exit 5


rc_reset
case "$1" in
    start)
	echo -n "Starting eventlog translation  "

	if [[ -e $evtlog_pid && ! -z `ps -o state= -p \`/bin/cat $evtlog_pid\`` ]]; then
	    echo "eventlog daemon already running." 
        else
	    $evtlog_cmd
	fi

	rc_status -v
	;;
    stop)
	echo -n "Shutting down eventlog translation services  "

	if [ -e $evtlog_pid ]; then
	    kill `cat $evtlog_pid`
	else
	    echo "no pidfile - already stopped?"
	fi
	
	rc_status -v
	;;
    try-restart)
	$0 stop && $0 start
	rc_status
	;;
    restart)
	$0 stop
	$0 start
	rc_status
	;;
    reload|force-reload)
	echo -n "Not supported for eventlog translation"
	;;
    status)
	echo -n "Checking for eventlog translation service:"

	if [ -e $evtlog_pid ]; then
	    if [ ! -z `ps -o state= -p \`/bin/cat $evtlog_pid\`` ]; then
		rc_failed 0
	    else
		rc_failed 1
	    fi
	else
    	    rc_failed 4
	fi
	rc_status -v
	;;

    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart}"
	exit 1
	;;
esac
rc_exit
