home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20101108.etc.tar.gz / bradford.20101108.etc.tar / etc / init.d / powerfail < prev    next >
Text File  |  2003-09-01  |  2KB  |  99 lines

  1. #! /bin/sh
  2. # Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany.
  3. # All rights reserved.
  4. #
  5. # Author: Florian La Roche, 1996
  6. #      Werner Fink <werner@suse.de>, 1996,2000
  7. #
  8. # Please send feedback to http://www.suse.de/feedback
  9. #
  10. # /etc/init.d/powerfail
  11. #
  12. # This script is run when the UPS tells the system
  13. # the power has gone. Tell everybody, sync the disks
  14. # and drop into single user mode within two minutes.
  15. # This script is also being run when the power comes
  16. # up again (if it does in time!)
  17. #
  18.  
  19. trap "echo" SIGINT SIGSEGV SIGTERM
  20.  
  21. POWERFAIL='THE POWER IS FAILED! SYSTEM GOING DOWN! PLEASE LOG OFF NOW!'
  22. POWERFAILNOW='THE POWER IS FAILED! LOW BATTERY - EMERGENCY SYSTEM SHUTDOWN!'
  23. POWERISBACK='THE POWER IS BACK'
  24.  
  25. case "$1" in
  26.     start)
  27.     # don't allow users to login and go into single-user
  28.     shutdown    +2  "$POWERFAIL"    <> /dev/console 1>&0 2>&0  &
  29.     sync &
  30.     ;;
  31.     now)
  32.     # tell init to immediatelly halt the system
  33.     shutdown -h now "$POWERFAILNOW" <> /dev/console 1>&0 2>&0  &
  34.     sync &
  35.     ;;
  36.     stop)
  37.     # Stop any running shutdown
  38.     shutdown -c now "$POWERISBACK"  <> /dev/console 1>&0 2>&0
  39.  
  40.     # allow users to log in
  41.     rm -f /etc/nologin
  42.  
  43.     # if we're not single user, don't try to restore
  44.     test "$RUNLEVEL" != "S" && exit 0
  45.  
  46.     # go back to previous runlevel
  47.     if test -n "$PREVLEVEL" -a \
  48.            "$PREVLEVEL" != 0 -a "$PREVLEVEL" != 6
  49.     then
  50.         init $PREVLEVEL
  51.     else
  52.         # may not happen, but...
  53.         init -t5 S
  54.     fi
  55.  
  56.     # allow users to log in
  57.     rm -f /etc/nologin
  58.     ;;
  59.     killups)
  60.     POWERD_UPSPORT=""
  61.     KILL_UPS_CMD=""
  62.     if test -r /etc/powerd.conf -a -x /sbin/genpowerd ; then
  63.         while read key value ; do
  64.         case "$key" in
  65.         \#*|"")     ;;
  66.         disabled)   echo 'powerd is disabled in /etc/powerd.conf!' | wall
  67.                 break ;;
  68.         serialline) POWERD_UPSPORT=${value} ; break ;;
  69.         esac
  70.         done < /etc/powerd.conf
  71.         test -c $POWERD_UPSPORT || POWERD_UPSPORT=""
  72.         if test -n "$POWERD_UPSPORT" ; then
  73.         KILL_UPS_CMD="/sbin/genpowerd -k $POWERD_UPSPORT eff-shutup"
  74.         fi
  75.         POWER_STATUS=/var/run/powerstatus
  76.     fi
  77.     #
  78.     # Kill UPS inverter (in the case of genpowerd)
  79.     #
  80.     if test -n "$KILL_UPS_CMD" -a -r $POWER_STATUS ; then
  81.         read STATUS < $POWER_STATUS
  82.         case "$STATUS" in
  83.         F|FAIL)
  84.             echo "Trying to kill UPS inverter"
  85.             $KILL_UPS_CMD
  86.             ;;
  87.         esac
  88.     else
  89.         echo "Not implemented"
  90.     fi
  91.     ;;
  92.     *)
  93.     echo "Usage: $0 {start|now|killups|stop}"
  94.     exit 1
  95.     ;;
  96. esac
  97.  
  98. exit 0
  99.