#!/bin/bash
#
# tkl-web-harvester	Start/Stop the tklite web harvester daemon.
# 			Modified for Solaris OS
#
# Kasper Lvschall - 2003/12/12
#
# place this script in /etc/init.d/tkl-web-harvester or make a symlink
#
# register runlevel using symlink (only one is really needed)
# ln -s /etc/init.d/tkl-web-harvester /etc/rc2.d/S91tkl-web

# configuration values

# location of web daemon
daemon=/usr/local/tkl/bin/tkl-web-harvester
daemonlib=/usr/local/tkl/lib/libtclrobot.so

tkl_spool_dir=/var/spool/tkl
tkl_tmp_dir=/tmp
pid=$tkl_spool_dir/tkl-web.pid
log=$tkl_spool_dir/tkl-web.log

# check for web daemon
test -x $daemon || exit 0

case "$1" in
  start)
	echo "Starting tkl-web daemon: "
	if [ ! -f $pid ] ; then
	    $daemon -o $log -p $pid -T $tkl_tmp_dir -D $tkl_spool_dir -L $daemonlib &
	    sleep 2
	    if [ -f $pid ] ; then
		echo -n "started (`cat $pid`)"
	    else
		echo -n "error"
	    fi
	else
	    echo -n "running (`cat $pid`)"
	fi
	echo
	;;

  stop)
	echo -n "Stopping tkl-web daemon: "
	if [ -f $pid ] ; then
	    kill `cat $pid`
	    sleep 1
	    rm $pid
	    echo -n "stopped"
	else
	    echo -n "not running"
	fi
	echo
	;;

  restart)
	echo -n "Restarting tkl-web daemon: "
	$0 stop
	sleep 1
	$0 start
	;;

  status)
	echo -n "Status of tkl-web daemon: "
	if [ -f $pid ] ; then
	    echo -n "running (`cat $pid`)"
	    pidno=`cat $pid`
	    running=`ps -p $pidno -o pid | tail -1`
	    if [ $running != "PID" ] ; then
		echo " checked ok"
	    else
		echo " dead"
	    fi
	else
	    echo "no-pid found"
	fi
	;; 

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

exit 0
