Skip to content
Advertisement

Restart ffmpeg process using monit if TOTAL CPU is less than 1%

I have used kind of similar solution like this Restarting ffmpeg process using monit to restart my ffmpeg stream in case it fails for some reason. Remember its not duplicate problem/question, because I have other issues unlike the example question/solution Restarting ffmpeg process using monit, which I’m gonna explain below. So here is my monit configuration:

JavaScript

Here is my streambash.sh file:

JavaScript

Monit can start the bash file successfully, but when this condition “if TOTAL CPU is less than 1% for 10 cycles then restart” is matched in monit configuration, it tries to restart, it gives error that process is not running. But in actual the ffmpeg process still runs in the background and I can see that the stream is live on my website. Here is monit logs:

JavaScript

Monit keeps trying to restart the process and on each retry, it dumps a new pid to the PATH-to-file/streampid.pid, but as I said it seems, it somehow can stop the actual ffmpeg stream/pid, which keep running in the background.

Advertisement

Answer

Your poll cycle / daemon check interval is very low, 5 seconds?

FFMpeg isn’t starting within 5 seconds so monit tries to start it again, constantly in a loop.

If you want to have such a low check interval, you need to set a timeout on the start command, along the lines of:

JavaScript

This really helps me to understand monit’s way of thinking, watch the live log in a terminal window while monit is doing things:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement