start-stop daemon

Michael A. Peters mpeters at mac.com
Mon Apr 21 20:49:00 PDT 2003


If anyone is interested - here is the statusproc() function I wrote to
replace the LFS one. It works both the different pidof binaries - I
haven't tried it with a daemon that spits out a bunch of forks, but it
should work with those too. When I get around to installing apache I'll
try with that.

I guess if you have the pidof from sysVinit then the scripts don't need
to modified - but I'm a little leery of something as important as boot
scripts being so dependent on a particular version of a binary -
especially on a system like LFS that doesn't have a package manager to
make sure the "correct one" doesn't get replaced by something else.

Anyway - my statusproc() function is attached.
This with the Debian start-stop-daemon eliminates dependency upon a
particular version of pidof. So if you guys want it, here it is.


-- 
Michael A. Peters <mpeters at mac.com>
-------------- next part --------------
statusproc()
{
	# This function takes two arguements.
	# The first is the name of the pid file.
	# The second is the executable.

	# Needs function syntax check added.

	PIDFILE="/var/run/$1"
		# Depends upon a compliant daemon with pid file where it is SUPPOSE to be - /var/run
		# Daemons that have their PID file elsewhere are incorrect.
	FULLPATH="`/usr/bin/which $2 2> /dev/null`"
	if [ $? -ne 0 ]; then
		echo "I do not know about $2. It is not in my path."
		echo "My path is $PATH"
		exit 1
	fi
	PROCESSID="`pidof $FULLPATH 2> /dev/null`"
	if [ $? -eq 0 ]; then
		# We are running
		if [ ! -f $PIDFILE ]; then
			# Ouch - somehow we lost our PID file
			echo "$FULLPATH is running with PID(s) $PROCESSID but does not have a PID file at $PIDFILE"
			exit 1
		else
			# OK - We have a PID file
			PIDID=`sed -e 's?^[ \t]*??;s?[ \t]*$??' $PIDFILE`
			MATCHING_PID=0
			for a in `echo $PROCESSID`; do
				if [ `echo $a |grep -c "^$PIDID$"` -eq 1 ]; then
					MATCHING_PID=1
				fi
			done;    
			if [ $MATCHING_PID -eq 1  ]; then
				# Good - everything is dandy
				echo "$FULLPATH is running with PID(s) $PROCESSID"
				exit 0
			else
				# Ouch - Our PID and PID file don't match
				echo "$FULLPATH is running with PID(s) $PROCESSID but the PID file $PIDFILE contains a different possibly stale PID."
				exit 1
			fi
		fi
	else
		# We are not running
		if [ -f $PIDFILE ]; then
			echo "$FULLPATH is not running but has a PID file $PIDFILE which is probably stale."
			exit 1
		else
			echo "$FULLPATH is not running."
			exit 0
		fi
	fi
}



More information about the lfs-dev mailing list