web stats OS X Client Server » Blog Archive » Monitor and Keep Postfix Running on OS X



Monitor and Keep Postfix Running on OS X


For some reason my postfix mail server kept crashing and would not stay up longer then one day. This got really annoying and made it impossible to use my server for any sites that had any email aspect to them. This week I found a really good way to monitor and keep postfix up and running at all times.

To do this you will need Webmin installed so if you dont already go install it now. Here are the instructions: Install Webmin on OS X

To set up a Postfix monitoring system:

1. Open Webmin

Webmin

2. Click the “others” tab

Webmin Others tab

3. Click the “System and Server Status” icon

Webmin System and Server Status

4. In the drop down box select “Postfix Server” and click “Add monitor of type”

Monitor Postfix email server
5. Now you will now see on screen a bunch of options for your postfix monitor. The first setting you should change is “Check on schedule?”. Select in the drop down menu “Yes and report when going down”.

The next thing do is type your email address in the “Also send email for this service to” field. That section didn’t work for me so we will also send the email alerts with a different method. If they both work for you you can disable one of them.

6. Now comes the really cool part. Towards the bottom of the screen you will see an option under “Commands to run” called “If monitor goes down, run command”. This section allows you to run custom commands if postfix crashes. What we will do here is run a command that restarts Postfix then one to email you and tell you that Postfix has crashed.

In the “If monitor goes down, run command” field type:

sudo postfix start; tail -20 /var/log/mail.log | mail -s”mail log from postfix crash” youremail@youremailhost.com; tail -20 /var/log/system.log | mail -s”Postfix has crashed” youremail@youremailhost.com

Now as soon as your monitor detects a crash this system will restart postfix with the sudo postfix start; command and email you to tell you. It will also send you the last 20 entry’s in your mail log. The mail log entry’s will help you determine what went wrong. Make sure you replace youremail@youremailhost.com with your email address.
If you want in the “If monitor comes up, run command” type: echo ” Postfix back up ” | mail -s youremail@youremailhost.com youremail@youremailhost.com

That will send you an email that tells you that postfix was successfully restarted.

Postfix monitor settings

7. Click Save

Thats it your done. Now Postfix will monitor its self and restart if it crashes. If you the monitor is working right, on the System and Server Status page you will see this:

Postfix monitor
If Postfix is down you will see an X instead of the check mark.

You can also add any other custom commands to the “If monitor goes down, run command” just make sure you separate them by a ; Another command that might be useful is:

tail -20 /var/log/system.log | mail -s”system log from apache crash” youremail@youremailhost.com;

That will mail you the last 20 entry’s from your system log just before the crash. That will help you figure out what caused the crash.

Before doing this my Postfix server did not stay up longer then one day. Now Postfix has been running for over a week. It did crash a few times but my monitor started it right back up. I know I should probably figure out why it is crashing in the first place but until I do at least it works!