#! /bin/sh # Author: Petter Reinholdtsen # License: GNU General Public License v2 or later # ### BEGIN INIT INFO # Provides: megaide-statusd # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 1 0 6 # Short-Description: Check megaide-status values in the background. ### END INIT INFO set -e PATH=/sbin:/bin:/usr/sbin:/usr/bin DESC="megaide-status monitor" NAME=megaide-statusd PIDFILE=/var/run/$NAME.pid STATUSFILE=/var/run/$NAME.status SCRIPTNAME=/etc/init.d/$NAME # Do not touch you can configure this in /etc/default/megaide-statusd MAILTO=root # Where to report problems PERIOD=600 # Seconds between each check (default 10 minutes) REMIND=7200 # Seconds between each reminder (default 2 hours) RUN_DAEMON=yes [ -e /etc/default/megaide-statusd ] && . /etc/default/megaide-statusd # Gracefully exit if the package has been removed. test -x /usr/sbin/megaide-status || exit 0 . /lib/lsb/init-functions [ -e /etc/default/rcS ] && . /etc/default/rcS if [ $RUN_DAEMON = "no" ] ; then log_begin_msg "megaide-statusd is disabled in /etc/default/megaide-statusd, not starting." log_end_msg 0 exit 0 fi check_megaide() { echo $$ > $PIDFILE.new && mv $PIDFILE.new $PIDFILE while true ; do # Check ever $PERIOD seconds, send email on every status # change and repeat ever $REMIND seconds if the raid is still # bad. if (megaide-status) |grep -q 'NOT OPTIMAL' ; then BADRAID=true logger -t megaide-statusd "detected non-optimal RAID status" else BADRAID=false fi STATUSCHANGE=false if [ true = "$BADRAID" ] ; then # RAID not OK (megaide-status) > $STATUSFILE.new if [ ! -f $STATUSFILE ] ; then # RAID just became broken STATUSCHANGE=true mv $STATUSFILE.new $STATUSFILE elif cmp -s $STATUSFILE $STATUSFILE.new ; then # No change. Should we send reminder? LASTTIME="`stat -c '%Z' $STATUSFILE`" NOW="`date +%s`" SINCELAST="`expr $NOW - $LASTTIME`" if [ $REMIND -le "$SINCELAST" ]; then # Time to send reminder STATUSCHANGE=true mv $STATUSFILE.new $STATUSFILE else rm $STATUSFILE.new fi else STATUSCHANGE=true mv $STATUSFILE.new $STATUSFILE fi else # RAID OK if [ -f $STATUSFILE ] ; then rm $STATUSFILE STATUSCHANGE=true fi fi if [ true = "$STATUSCHANGE" ]; then hostname="`uname -n`" ( cat <&2 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0