2013-03-22 Update: I've had this monit script disabled for the past few weeks and haven't ran into this problem since. Perhaps something got fixed somewhere.
I've got this weird thing going on with gamin and courier-imap where sometimes, for no apparent reason, I'll get "Connection dropped by IMAP server" after logging in. When that happens, I need to SSH in, kill gamin and I then can log in. ...Until it happens again. For no apparent reason. At random intervals.
This got annoying pretty quickly, but I don't have the energy to look into it at the moment. There are a couple of work-arounds (replacing gamin with FAM, replacing courier with dovecot, disabling the IDLE/gamin feature from courier-imap, etc.), but again: can't be bothered. I'm the only one using the server anyway.
At the same time, I've been wanting to play with monit for a while (I bet you can see where this is going now). So now I have monit setup to try to login to the mail server, and if we get an unexpected response (dropped connection, for example), it kills gamin.
It's a dirty, lazy work-around... but it works. And I've learned a few things about monit along the way.
Here's a simplified version of the script:
check process imap with pidfile /var/run/courier/imapd.pid
if failed host mail.example.org port 143
expect ".*" # Ignore announcement of supported protocols
send "10 LOGIN user@example.org password\r\n" # Login
expect "10 OK LOGIN Ok.\r\n" # Expect ok
send "c logout\r\n" # Logout
then exec "/bin/bash -c 'killall -u vmailer gam_server'" # Kill gamin if something didn't go right |
You'll need to change the host, username and maybe the port, perhaps make it an ssl connection ("TCPSSL") and/or use a hash of your password instead of plain text, etc. All depending on how you have things setup.
Finding a proper fix is still on my todo list. I might get to it ...someday :)
2013-03-22 Update: I've had this monit script disabled for the past few weeks and haven't ran into this problem since. Perhaps something got fixed somewhere. I've got this weird thing...