offlineimap daemon (auto-kill and restart)

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


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 
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:

ps -ef | grep -v grep | grep -v sh | grep -v SCREEN | grep 
/usr/bin/$SERVICE > /dev/null 2>&1
if [ $? -eq 1 ]
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
echo "`date` eq 0 - $SERVICE is running. Life is peachy." >> 

Hard reset:

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/ 2>&1
echo "`date` offlineimap restarted" >> 

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
> OfflineIMAP homepage:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: james_stapley.vcf
Type: text/x-vcard
Size: 409 bytes
Desc: not available
URL: <>

More information about the OfflineIMAP-project mailing list