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.
Asked
Active
Viewed 1,549 times
1
![](../../users/profiles/335412.webp)
ubi
- 131
- 4
-
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 07:05
1 Answers
2
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.
![](../../users/profiles/58024.webp)
Khaled
- 35,688
- 8
- 69
- 98
-
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 07: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