The script basically uses telnet to check port 25. I didn't bother with the telnet commands because what I discovered was that if hmailserver is either STOPPED or PAUSED, the return value will be a timeout (actively refused connection on ip.ad.dr.ess:25). I figure this way, it doesn't matter what caused the malfunction because we're looking for the outcome to tell us that something is wrong.

It checks status 3 times with 5 minutes inbetween before taking action. If after the third try, its still not possible to communicate with port 25, it will attempt to restart the service and also send a notification. Then it will wait 60 seconds and check service status. If the service is not running, it will send another notification.

Obviously, if there is a problem with hmailserver, you won't be able to send an email via hmailserver, so notifications will be sent via outside smtp service. I tested it with gmail. I also send notifications via my sms gateway. Just delete that part if you don't want to use it.

Thanks, looks like a useful script.
There is a small tool here (free & portable):http://www.den4b.com/products/shutter
once it helped me to restart a server which randomly lost network connection every few days (never been able to find out what the problem was), if ping fails.
it does a number of other things.

Thanks, looks like a useful script.
There is a small tool here (free & portable):http://www.den4b.com/products/shutter
once it helped me to restart a server which randomly lost network connection every few days (never been able to find out what the problem was), if ping fails.
it does a number of other things.

Cool. I just looked. Winamp LOL. I had a winamp radio station a long time ago. All Johnny Cash all the time. He has such a YUUUGE discography you could listen for a week without hearing the same song.

I actually have a version of this script for all the major services on my server. They run every 15 minutes. This one for hmailserver is different. I run it only once a day at 12:15 am, 15 minutes after my hmailserver backup script (Jimi's backup & clear down).

I have a peculiar issue where sometimes hmailserver hangs on shutdown. So checking for service status = not running doesn't work because the service is running, but it's not working. That's why instead i check for communication by telnet. I found a powershell script that communicates by telnet. I stripped out all the unnecessary stuff so it just looks to make a connection. If no communication then it means hmailserver got hung.

In the version that gets run every 15 minutes with all the other services, it simply notifies me without taking any action (it looks for service status, not telnet). I set it up that way so it doesn't attempt to restart during a backup. And anyway, hmailserver is so rock solid, if it weren't for this one single issue that only happens during backup, i really wouldn't need to check anything at all. That one has never been triggered in the few months I've been using it. I doubt it will ever be triggered.

But I'll have a closer look at the one you posted. The ping thing could be very useful.

For some reason, hmailserver got hung up last night and my telnet script didn't work. I suspect that's because it possibly successfully connected, but didn't act. Instead of just true/false on connection, this version looks at the output of connecting, which should be 220 mail.example.com. If connection fails, or if your smtp banner doesn't come up, then it goes through the same routine of restarting, etc.