0

Is it possible to configure monit to restart an application periodically? I'm using monit to check the application health and restart it if it has died. I also want to periodically restart it. Prefer to do it with monit rather than having a cron job separately.

  • Why not configure a cron job to do what you want? Usually, you want your application(s) to be always running not restart them periodically! – Khaled Aug 10 '17 at 7:05
1

I don't feel like this is the right way to use monit. Anyway, you can try the following snippet of configuration:

check process dummy with pidfile /var/lib/dummy.pid
  start program = "/path/to/restart/script.sh" with timeout 60 seconds

Here, we just define any dummy process that does not exist. Every time monit will check it, it will fail to start and so the script is executed. This way you will get the restart script executed every time monit checks the service plus the timeout.

If monit is configured to check services every 2 minutes, you will get the script executed every 2 + 1 (timeout 60 seconds) = 3 minutes.

I prefer a simple cron job to do it, but this is to answer your question.

  • Thanks and I agree - right tool for the right job. My question was mostly around use monit if it can do it – ubi Aug 10 '17 at 7:33
  • Also, btw I'm not trying to restart every few mins but once a day or few days.. – ubi Aug 10 '17 at 12:06
  • @ubi: As I said before, cron is the right solution to this. This post is written to answer your question about using monit. – Khaled Aug 10 '17 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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