#!/bin/sh
# $Id: pidstatd,v 1.7 2004/09/03 12:56:45 wsnyder Exp $
# DESCRIPTION: Sample file to place in /etc/init.d to start the daemon
# Distributed with IPC::Locker
#
# Copyright 1999-2003 by Wilson Snyder.  This program is free software;
# you can redistribute it and/or modify it under the terms of either the GNU
# General Public License or the Perl Artistic License.
#
# chkconfig: 23456 99 10
# description: Pidstatd provides process information services for IPC::PidStat
# processname: pidstatd

state=$1
prog=/usr/local/bin/pidstatd

# Source site start file
if [ -x /import/nauticus/common/etc/profile.d/site.sh ] ; then
    . /import/nauticus/common/etc/profile.d/site.sh
fi

case $state in
  start)
        echo starting $prog if present
	if [ $EUID != 0 ]; then
	    echo "Run as root, only root can do kill 0's"  
	    exit 10
	fi
        [ -f $prog ] && $prog &
        ;;
  stop)
        if test "x`pidof -o $$ -o $PPID -x pidstatd`" != x; then
                echo -n $"Stopping pidstatd: "
                kill `pidof -o $$ -o $PPID -x pidstatd`
                echo
        fi
	exit 0
        ;;
  restart|reload)
	$0 stop
	$0 start
	exit 0
	;;
  status)
        if test "x`pidof -o $$ -o $PPID -x pidstatd`" != x; then
  	        ps f -ww `pidof -o $$ -o $PPID -x pidstatd`
        fi
	exit 0
	;;
*)
	echo $"Usage: $0 {start|stop|restart|reload|status}"
	exit 1
esac
