offlineimap daemon (auto-kill and restart)

James Stapley james.stapley at asclme.org
Mon Feb 14 06:56:14 GMT 2011


Hi,

I use a couple of scripts called by Cron, one of which checks for a 
running offlineimap process; if it's not there, it restarts (once a 
minute).
I've occasionally see offlineimap "lock up" totally; in the interests of 
working around this (e.g. in case I'm away from the office for some 
time, and AFK for longer), I "hard reset" offlineimap once a day at 7am 
by killing the process and restarting it with the other script.

This may not be the most elegant solution, but it seems to work :)

Check if running, if not, restart:

#!/bin/bash
SERVICE='offlineimap'
ps -ef | grep -v grep | grep -v sh | grep -v SCREEN | grep 
/usr/bin/$SERVICE > /dev/null 2>&1
if [ $? -eq 1 ]
then
echo "`date` $SERVICE is not running! Panic!" >> /var/log/offlineimapsh.log
# echo "$SERVICE is not running!" | mail -s "$SERVICE down" root
/usr/bin/offlineimap -c /home/discus/.offlineimaprc >> 
/var/log/offlineimapsh.log 2>&1
echo "`date` $SERVICE restarted" >> /var/log/offlineimapsh.log
else
echo "`date` eq 0 - $SERVICE is running. Life is peachy." >> 
/var/log/offlineimapsh.log
fi

Hard reset:

#!/bin/bash
echo "`date` killing offlineimap" >> /var/log/offlineimaphardreset7amsh.log
/usr/bin/pkill offlineimap 2>&1
echo "`date` offlineimap killed" >> /var/log/offlineimaphardreset7amsh.log
/etc/cron.hourly/offlineimap.sh 2>&1
echo "`date` offlineimap restarted" >> 
/var/log/offlineimaphardreset7amsh.log
exit


I use offlineimap to sync the Inboxes of about 8 users between our 
in-office mail server and an off-site one (we're at the end of an ADSL 
line, which makes life a little painful otherwise); I'm using Ubuntu Server.

Best regards,

James Stapley.

On 2011/02/14 04:23 AM, Ng Oon-Ee wrote:
> Hi all,
>
> I've been thinking about an idea for 'offlineimapd' or something
> similar, but am not sure if the functionality is planned for offlineimap
> itself.
>
> Firstly, I'm on 64-bit Arch Linux, offlineimap is at 6.3.1 currently.
>
> Since the 6-series release back-in-the-day, offlineimap has given random
> hangs with gmail on spotty connections. This probably has more to do
> with gmail's sucky IMAP implementation than any inherent offlineimap
> fault (since the same does not occur on another gmail account I sync
> with), but the net result is that I have conky display the
> last-synced-time for offlineimap on my desktop, and when I realize its
> been a long time ago (maybe 20 minutes or so) I restart offlineimap.
>
> I thought it'd be useful to have a simple script (offlineimapd for want
> of a better name) which monitors the main offlineimap process to restart
> it if it hangs. How I've done it manually is to have a hook activate
> after every successful sync.
>
> Its not something very complicated, I could probably whip up a simple
> bash script which handles that. Would it be a good idea, though? Or
> would this sort of logic be best implemented within offlineimap (which
> is already multi-threaded, after all).
>
>
> _______________________________________________
> OfflineIMAP-project mailing list
> OfflineIMAP-project at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/offlineimap-project
>
> OfflineIMAP homepage: http://software.complete.org/offlineimap
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/offlineimap-project/attachments/20110214/28336272/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: james_stapley.vcf
Type: text/x-vcard
Size: 409 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/offlineimap-project/attachments/20110214/28336272/attachment-0003.vcf>


More information about the OfflineIMAP-project mailing list