Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to execute a script when monit is restarted. For my case, this mostly applies to the restart of the whole server.

How can I achieve this? Is there a way beside monit to do this?

Background: The server, where I need this, is a virtual server. It seems, that firewall rules in iptables are not persistant, so I need to set them on server start.

share|improve this question
Perhaps you should ask how to make the iptables firewall rules persistent, then, instead of this question? – Michael Hampton Jul 30 '12 at 5:32
This would be an approach. But I'm using monit to start all services and check some things, so I would like to do this in there to keep things together. – Martin Jul 30 '12 at 6:54
The Linux system will already have a "standard" way of persisting iptables, and it's usually best to use the normal ways. Otherwise you will end up with confusion later. – Michael Hampton Jul 30 '12 at 7:12

By default, you should receive an alert that the Monit daemon restarted. Something like:

Monit instance changed Service localhost

    Date:        Sun, 29 Jul 2012 13:09:28
    Action:      start
    Description: Monit started

Your faithful employee,

If you need something to run at boot, have you considered wrapping it in an init script? With Monit, there's a level of uptime testing, but it only applies to processes.

You could also choose to take an action on a change in Monit's PID... But I think it would help to get a better understanding of what you need to execute.

share|improve this answer
I added some background information. I hope, this helps understanding my problem. – Martin Jul 30 '12 at 5:22

Your Answer


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.