]> git.donarmstrong.com Git - bin.git/commitdiff
update getmail to handle failed offlineimaps
authorDon Armstrong <don@donarmstrong.com>
Mon, 8 Sep 2008 06:29:47 +0000 (06:29 +0000)
committerDon Armstrong <don@donarmstrong.com>
Mon, 8 Sep 2008 06:29:47 +0000 (06:29 +0000)
getmail

diff --git a/getmail b/getmail
index 28233e82b570947743e63505f39478ebb59263cf..94808dde6dc6cf5c8ea8251f40d70f58b836250f 100755 (executable)
--- a/getmail
+++ b/getmail
@@ -16,12 +16,23 @@ if [ -z "$HOSTNAME" ]; then
     HOSTNAME="$(hostname)"
 fi;
 
-# See if the server exists
+# if we're not running under cron or there is a mailserver running
 if [ -z "$CRON" ] || kill -0 `pgrep -U $(id -u) -x $MUA` 2>/dev/null; then
+    # and we can ping the imap host
     if ping -q -c 3 $IMAPHOST >/dev/null 2>&1; then
+       # source the ssh info if it exists
        if [ -e ~/.ssh/"ssh_agent_info_$HOSTNAME" ]; then
            . ~/.ssh/"ssh_agent_info_$HOSTNAME" > /dev/null;
        fi;
+       PID="$(pgrep -U $(id -u) offlineimap)";
+       if [ -n "$PID" ]; then
+           # if offlineimap has been running for more than 20 minutes
+           if [ $(( $(date +'%s') - $(stat -c '%Y' /proc/$PID/cmdline) )) -gt 1200 ]; then
+               kill "$PID" >/dev/null 2>&1 || true;
+               sleep 1
+               kill -0 "$PID" >/dev/null 2>&1 && kill -9 "$PID" >/dev/null 2>&1;
+           fi;
+       fi;
        if nice -n 19 offlineimap -o -u Noninteractive.Basic 2>&1 |grep validity| \
            perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/;
                       next unless defined $account and length $account;