#!/bin/sh
#     reboot.sh  - script to reboot in Linux
#
logfile=/reboot.log
# ADDLOG=addLogRecord
ADDLOG=echo

# init the logfile
date >$logfile
init -? 2>&1 |grep "test mode" >/dev/null
if [ $? -eq 0 ]
then
    # using Anaconda that restricts shutdown
    # use alternative method (SIGINT) to main process (linuxrc) or init for el5
    for mainproc in linuxrc init ; do
	mainPID=`ps -e | grep $mainproc | head -n1 | cut -c0-6`
	if [ "$mainPID" != "" ] ; then    
	    echo $mainproc pid = $mainPID  >>$logfile
	    echo "kill -2 $mainPID" >>$logfile
	    kill -2 $mainPID
	    exit $?
	fi
    done
    if [ "$mainPID" = "" ] ; then
 	echo Running in "test mode", but could not identify main init process. >>$logfile
	ps -aef>>$logfile
	exit 1
    fi
else
    # do an OS shutdown & reboot
    echo "shutdown -r now"  >>$logfile
    shutdown -r now  >>$logfile
    exit $?
fi



# Could use this instead if S5000 (with IPMI), which
# does a soft shutdown with an IPMI watchdog reset if
# it does not complete.
# echo "ipmiutil reset -o"  >>$logfile
# ipmiutil reset -o  >>$logfile

exit $ret

