#!/sbin/sh
#
# @(#) $Revision: 78.1 $
#
# NOTE:    This script is not configurable!  Any changes made to this
#          scipt will be overwritten when you upgrade to the next
#          release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
#          is unbootable.  Do not modify this script.
#

#
# Syncer helps minimize file system damage in the event
# of a power failure or other system crash.
#

PATH=/sbin:/usr/sbin:/usr/bin
export PATH

rval=0
set_return() {
	x=$?
	if [ $x -ne 0 ]; then
		echo "EXIT CODE: $x"
		rval=1
	fi
}

case $1 in
start_msg)
	echo "Start syncer daemon"
	;;

stop_msg)
	echo "Stop syncer daemon"
	;;

'start')
	if [ -f /etc/rc.config.d/syncer ] ; then
		. /etc/rc.config.d/syncer
	else
		echo "ERROR: /etc/rc.config.d/syncer defaults file MISSING"
	fi
	
	if [ "$SYNCER" -eq 1 -a -x /usr/sbin/syncer ]; then
		/usr/sbin/syncer && echo syncer started
		set_return
	else
		rval=2
	fi
	;;

'stop')
        #
	# Determine PID of process(es) to stop
	#
	pid=`ps -el | awk '( ($NF ~ /syncer/) && ($4 != mypid) && ($5 != mypid)  ){ print $4 }' mypid=$$ `
	if [ "X$pid" != "X" ]; then
		if kill $pid; then
			echo "Syncer stopped"
		else
			set_return
			echo "Unable to stop syncer"
		fi
	fi
	;;

*)
	echo "usage: $0 {start|stop}"
	rval=1
	;;
esac

exit $rval
