Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Obviously I can't send myself an email to tell myself that qmail is not working... at least not using qmail. How would you inform yourself about the fact, that qmail is not running?

share|improve this question

5 Answers 5

up vote 3 down vote accepted

Easiest way is probably an http post or wget to a secondary server that can send the email.

Obviously if your mailbox is on this server it wont work so you would need to use another email address.

For instance, run a cron job every minute to detect if the process qmail is running. If it isn't running then wget http://secondserver/alert.php

cronjob bash script.

#!/bin/sh
SERVICE='qmail'

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
    echo "$SERVICE service running, everything is fine"
else
    echo "$SERVICE is not running"
    wget http://secondserver/alert.php
fi

alert.php

<?php

$to = 'youraddress@example.com';

$subject = 'qmail not running';

$message = "qmail reported down";

$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";

$mail_sent = @mail( $to, $subject, $message, $headers );

echo $mail_sent ? "Mail sent" : "Mail failed";
?>

This solution is a poor mans way of doing it but the simplest. I'd invest in a monitoring solution such as nagios. With a proper monitoring tool you can setup a solution that can sms you when down.

This is also a popular monitoring service: http://www.bijk.com/

share|improve this answer
    
thanks pablo, we're implementing this for the time being! –  markus Feb 14 '11 at 9:32
    
for the future we definitely have to look into monitoring services. –  markus Feb 14 '11 at 9:38

I like pablo's approach; I've used something similar to send IM-style messages tracking IP address movement of my home computer connected to work via a VPN (since it was assigned a different address every time):

import xmpp

xmpp_login  = 'user'
xmpp_domain = 'jabber.com'
xmpp_pwd    = 'content-purged'
xmpp_server = 'www.jabber.com'
xmpp_recp   = 'user@jabber.com'

conn = xmpp.Client(xmpp_domain)
conn.connect(server=(xmpp_server, 5222))
conn.auth(xmpp_login,xmpp_pwd)
conn.send(xmpp.Message(xmpp_recp, "message body"))

Obviously, this requires a XMPP (Jabber) account - you can post messages 'to yourself', so one is sufficient.

share|improve this answer

One possible way could be to setup a monitoring service, like Nagios, and add qmail to be monitored.This way not only can you be notified about a failed qmail service, but, in fact, you can also be warned of an impending failure, so that you can take the necessary actions to prevent the failure from actually happening.

share|improve this answer

Just to add an additional answer- you could test, from another server if the mail port is listening for mail (assuming this is open to this other server)- if it reports that it is blocked, then it could notify you of the fact.

share|improve this answer

DJ Bernstein wrote qmail. I approve of the other answer, but I must comment:

Many people running qmail eventually bite the bullet and set up DJ Bernstein's other late jurassic period project to monitor services called daemontools. It will keep qmail working through almost anything, including zombie invasions, overheated processors and bad memory.

It works really, really well - I suspect that daemontools is the chuck norris of the daemon world. [Daemons = original name for what we now call services]

Regardless of your OS or distribution, there will be a daemon service keepalive program, and you just have to add qmail to it. We don't trust anyone or anything, so we run emails through the mail server and then check to see if they arrived within a reasonable time period. This is THE ONLY WAY to really know if it's working correctly. Monitoring a service is only 50% of a proper health check.

It's worth reading about DJB. I always assumed he was really old, but not so much.

http://en.wikipedia.org/wiki/Daniel_J._Bernstein

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.