#! /bin/sh
#
# functions	This file contains functions to be used by most or all
#		shell scripts in the /etc/init.d directory.
#
# Version:	@(#) /etc/init.d/functions 2.00 03-Oct-1994
#
# Author:	Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#		Riku Meskanen, <mesrik@jyu.fi>
#

  # First set up a default search path.
  export PATH="/sbin:/usr/sbin:/bin:/usr/bin"

  # Set RUNLEVEL and PREVLEVEL
  if [ "$RUNLEVEL" = "" ]
  then
	levels=`runlevel`
	if [ $? = 0 ]
	then
		eval set $levels
		PREVLEVEL=$1
		RUNLEVEL=$2
	fi
  fi

  # A function to start a program.
  daemon() {
	Usage="Usage: daemon [-n] {program}"
	# Test syntax.
	if [ $# = 0 ]
	then
		echo $Usage
		return 1
	fi
	case "$1" in
	  "-n")	noecho=1
		shift
		if [ -z "$1" ] 
		then  
		   echo $Usage 
		   return 1
		fi
		;;
	    *)  noecho=0
		;;
	esac

	# See if it already runs (must exclude ourselves!)
	[ ! -z "`pidof -o $$ -o %PPID $1`" ]  && return

	# echo basename of the program.
	[ $noecho = 0 ] && echo -n "${1##*/} "

	# And start it up.
	$*
  }

  # A function to stop a program.
  killproc() {
	# Test syntax.
	if [ $# = 0 ]
	then
		echo "Usage: killprog {program}"
		return 1
	fi
	pid=`pidof -o $$ -o %PPID $1`
	if [ "$pid" != "" ]
	then
	   echo -n "Killing $pid "
	   kill -9 "$pid"
	else
	   echo "$1 already down"
	fi
  }

