#!/bin/sh # # killpowercheck No service. # # chkconfig: 2345 00 00 # description: this script check for UPS with delayed shutdown \ # and send killpower to it if UPS exist \ # processname: none # config: none # pidfile: none # Do not load RH compatibility interface. WITHOUT_RC_COMPAT=1 # Source function library. . /etc/init.d/functions RETVAL=0 start() { rm -f /etc/powerkilled return 0 } stop() { upscheck RET=$? [ $RET -ne 0 ] || return 100 if [ $[ $RET < 180 ] == 1 ]; then echo "UPS shutdown time too low ($RET sec). Please set 180 sec or more" return 101 fi UPSCTL=/etc/apcupsd/apccontrol if [ -x "$UPSCTL" -a -f /etc/apcupsd/powerfail ]; then action "Attempting to turn the UPS off:" "$UPSCTL" killpower RETVAL=$? [ $RETVAL -ne 0 ] || echo "UPS will be shutdown after $RET sec" touch /etc/powerkilled # или другое место root file system fi UPSCTL=/sbin/upsdrvctl if [ -x "$UPSCTL" -a -f /etc/killpower ]; then action "Attempting to turn the UPS off:" "$UPSCTL" shutdown RETVAL=$? [ $RETVAL -ne 0 ] || echo "UPS will be shutdown after $RET sec" touch /etc/powerkilled fi return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; *) msg_usage "${0##*/} {start|stop}" RETVAL=1 esac exit $RETVAL