]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
Bug 523: add WEDGED_EMAIL_INTERVAL and WEDGED_DISABLE_FAXGETTY options
authorLee Howard <faxguy@howardsilvan.com>
Wed, 7 Apr 2004 03:52:28 +0000 (03:52 +0000)
committerLee Howard <faxguy@howardsilvan.com>
Wed, 7 Apr 2004 03:52:28 +0000 (03:52 +0000)
man/wedged.1m
util/wedged.sh.in

index 1e11d10be9b42dfb74c4f6706caedf1902c88472..4c5396b299e44fcc6c7f14a5050405d52a5e8ff9 100644 (file)
@@ -43,8 +43,15 @@ configuration parameter described in
 .IR hylafax-config (${MANNUM4_5}).
 The default
 .I wedged
-script sends electronic mail to the FaxMaster alias and attempts
-to disable any getty processes spawned by the 
+script sends electronic mail to the FaxMaster alias. The interval at which
+emails are sent can be configured in the
+.B etc/FaxDispatch
+file by setting the WEDGED_EMAIL_INTERVAL variable to the desired number
+of minutes (emails will be sent no more than every WEDGED_EMAIL_INTERVAL
+minutes, until the wedged condition persists).
+If the variable WEDGED_DISABLE_FAXGETTY is set in
+.B etc/FaxDispatch
+then the script will attempt to disable any getty processes spawned by the
 .IR init (${MANNUM1_8})
 process.
 In addition the
index de54f4002e9492000b9db40f669f8738569b43ec..19ba589735bf365132e37d2e56823684499c3d3d 100644 (file)
@@ -53,47 +53,149 @@ EOF
 }
 . etc/setup.cache
 
+#
+# Command line params
+#
 devID=$1
 device=$2
+
+#
+# Variables customizable through etc/FaxDispatch
+#
+TOADDR=FaxMaster
+FROMADDR=fax
+WEDGED_EMAIL_INTERVAL=5                # minutes: at most 1 wedged email every X mins
+WEDGED_DISABLE_FAXGETTY=       # if set, faxgetty disabled from inittab
+
+if [ -f etc/FaxDispatch ]; then
+    . etc/FaxDispatch  
+fi
+
+#
+# Internal variables
+#
+
+# unix secs since epoch for systems without GNU date +%s extension
+unixtime() {
+    TZ=GMT date "+%Y %j %H %M %S" | $SED 's/ 0*/ /g' | {
+    read year yday hour min sec
+    expr  $sec + $min \* 60 + $hour \* 3600 \
+       + \(  \( $year - 1969 \) / 4 \
+           - \( $year / 100 - 19 \) \
+           + \( $year / 400 - 4  \) \
+           + $yday - 1 \
+          \) \* 86400 \
+       + \( $year - 1970 \) \* 31536000
+    }
+}
+
 tty=`basename $device`
+wedged_last_time=0             # seconds: unix timestamp
+wedged_interval=0              # minutes
+wedged_log_file="tmp/${devID}_last_wedged_email"
+wedged_current_time=`date +%s` # seconds: unix timestamp
+# If it's not a number (no GNU date), fallback to internal function
+wedged_current_time=`expr "$wedged_current_time" + 0 2>/dev/null || unixtime`
+
+
+#
+# Read last time 'wedged modem' email was sent
+#
+if [ -r $wedged_log_file ]; then
+    # read stored timestamp
+    read wedged_last_time < $wedged_log_file 2>/dev/null
+    # Set it to 0 if it's not a number
+    wedged_last_time=`expr "$wedged_last_time" + 0 2>/dev/null || echo 0`
+    # shouldn't happen, just in case...
+    if [ $wedged_last_time -gt $wedged_current_time ]; then
+       wedged_last_time=0
+    fi
+fi
+
+#
+# Minutes since last 'wedged modem' email was sent
+#
+wedged_interval=`expr \( $wedged_current_time - $wedged_last_time \) / 60`
+
+#
+# Send 'wedged modem' email if either is true:
+# 1. there's no log file (email was never sent before or someone deleted it)
+# 2. email was sent longer than WEDGED_EMAIL_INTERVAL minutes ago
+# Cases like 'modem was wedged 1 year ago, and is now again wedged for the
+# first time', fall into #1 if someone deleted the log file, into #2 if
+# log file was left in place.
+#
+if [ ! -r $wedged_log_file \
+       -o $wedged_interval -gt $WEDGED_EMAIL_INTERVAL ]; then
+
+    #
+    # Write current timestamp into logfile under tmp/
+    #
+    if [ $wedged_current_time -gt 0 ]; then
+       $RM -f $wedged_log_file # symlink? :-)
+       $CAT<<EOF > $wedged_log_file
+$wedged_current_time
+
+This is a temp file written and read by bin/wedged to rate-limit
+the emails it sends about the wedged status of device $device.
+
+The first line contains a timestamp for when the last email was sent.
 
-($CAT<<EOF
-To: FaxMaster
-From: The HylaFAX Receive Agent <fax>
+This file is never deleted automatically, there's no need to do it
+and it may be useful to know when/if a device had last a problem.
+However, you can safely delete it at any time if you wish, it will
+be recreated when needed.
+
+last modified: `date`
+
+EOF
+    fi
+
+    #
+    # Send 'modem is wedged' email
+    #
+    ($CAT<<EOF
+To: $TOADDR
+From: The HylaFAX Receive Agent <$FROMADDR>
 Subject: modem on $device appears wedged
 
 The HylaFAX software thinks that there is a problem with the modem
 on device $device that needs attention; repeated attempts to
 initialize the modem have failed.
+
+Consult the server trace logs for more information on what is happening.
+
+You will be notified again after $WEDGED_EMAIL_INTERVAL minutes if the problem persists.
+
 EOF
 
-#
-# NB: this is for an System V-style system.
-#
-if [ -f /etc/inittab ]; then
-    ed - /etc/inittab<<EOF
+    #
+    # Disable faxgetty
+    # NB: this is for an System V-style system.
+    #
+    if [ -f /etc/inittab -a -n "$WEDGED_DISABLE_FAXGETTY" ]; then
+       ed - /etc/inittab<<EOF
 /^[^#].*:respawn:.*faxgetty .*$tty/s/respawn/off/
 w
 q
 EOF
-    #
-    # ed doesn't appear to have consistent exit
-    # status under SysV-style systems (does under BSD);
-    # this means checking if the above succeeded is
-    # problematic.
-    #
-    if [ $? -ne 0 ] && /bin/kill -1 1; then
-       cat<<EOF
+       #
+       # ed doesn't appear to have consistent exit
+       # status under SysV-style systems (does under BSD);
+       # this means checking if the above succeeded is
+       # problematic.
+       #
+       if [ $? -ne 0 ] && /bin/kill -1 1; then
+           cat<<EOF
 
 The $tty entry in /etc/inittab that spawns faxgetty on $device has
 been disabled.  After you have figured out what is wrong you may
 want to restart this process.
 EOF
+       fi
     fi
-fi
 
-echo ""
-echo "Consult the server trace logs for more information on what is happening."
-) | 2>&1 $SENDMAIL -t -ffax -oi
+    ) | 2>&1 $SENDMAIL -f$FROMADDR -oi $TOADDR
+fi
 
 exit 0