gpt4 book ai didi

linux - 如果 TOTAL CPU 小于 1%,则使用 monit 重启 ffmpeg 进程

转载 作者:太空宇宙 更新时间:2023-11-04 12:36:33 25 4
gpt4 key购买 nike

我用过类似的解决方案 Restarting ffmpeg process using monit重新启动我的 ffmpeg 流,以防它因某种原因失败。请记住它不是重复的问题/问题,因为我还有其他问题不同于示例问题/解决方案 Restarting ffmpeg process using monit ,我将在下面解释。所以这是我的监视器配置:

    check process FFMPEGStream with pidfile PATH-to-file/streampid.pid
start program = "PATH-to-file/streambash.sh restart"
stop program = "PATH-to-file/streambash.sh stop"
if TOTAL CPU is less than 1% for 10 cycles then restart

这是我的 streambash.sh 文件:

    #!/bin/bash
pid_file="PATH-to-file/streampid.pid"

case "$1" in
restart)
PATH-to-file/streambash.sh stop
PATH-to-file/streambash.sh start
;;

start)
rm $pid_file
/usr/bin/ffmpeg -i "INPUT-PATH" -c:v libx264 -b:v 900k -preset ultrafast -aspect 16:9 -s 640x376 -strict experimental -c:a aac -b:a 96k -f flv "RTMP-PATH" &> /dev/null &
ch_pid=$!
echo "Start Stream1: ffmpeg = $ch_pid";
echo $ch_pid > $pid_file
;;

stop)
echo "Stop ffmpeg Stream1";
kill `cat $pid_file` &> /dev/null
;;

*)
echo "Usage: PATH-to-file/streambash.sh {start|stop|restart}"
exit 1
;;

esac
exit 0
echo $pid_file

Monit 可以成功启动 bash 文件,但是当这个条件 "if TOTAL CPU is less than 1% for 10 cycles then restart" 在 monit 配置中匹配时,它会尝试重新启动,它给出进程未运行的错误。但实际上 ffmpeg 进程仍在后台运行,我可以看到流在我的网站上是实时的。这是监控日志:

    [CET Jan 10 12:55:02] error    : 'FFMPEGStream' total cpu usage of 0.4% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:07] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:12] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:17] error : 'FFMPEGStream' total cpu usage of 0.4% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:22] error : 'FFMPEGStream' total cpu usage of 0.9% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:27] error : 'FFMPEGStream' total cpu usage of 0.9% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:32] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:37] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:42] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:47] error : 'FFMPEGStream' total cpu usage of 0.4% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:50] info : 'FFMPEGStream' trying to restart
[CET Jan 10 12:55:50] info : 'FFMPEGStream' stop: PATH-to-file/streambash.sh
[CET Jan 10 12:55:51] info : 'FFMPEGStream' start: PATH-to-file/streambash.sh
[CET Jan 10 12:55:56] error : 'FFMPEGStream' process is not running
[CET Jan 10 12:55:58] info : 'FFMPEGStream' trying to restart
[CET Jan 10 12:55:58] info : 'FFMPEGStream' start: PATH-to-file/streambash.sh
[CET Jan 10 12:56:04] error : 'FFMPEGStream' process is not running
[CET Jan 10 12:56:04] info : 'FFMPEGStream' trying to restart
[CET Jan 10 12:56:04] info : 'FFMPEGStream' start: PATH-to-file/streambash.sh
[CET Jan 10 12:56:09] error : 'FFMPEGStream' process is not running
[CET Jan 10 12:56:09] info : 'FFMPEGStream' trying to restart
[CET Jan 10 12:56:09] info : 'FFMPEGStream' start: PATH-to-file/streambash.sh

Monit 不断尝试重新启动进程,并且在每次重试时,它都会将一个新的 pid 转储到 PATH-to-file/streampid.pid,但正如我所说,它似乎可以以某种方式停止实际的 ffmpeg 流/pid,继续在后台运行。

最佳答案

您的轮询周期/守护进程检查间隔很短,只有 5 秒?

FFMpeg 未在 5 秒内启动,因此 monit 尝试再次启动它,不断循环。

如果你想要这么低的检查间隔,你需要在启动命令上设置一个超时,按照以下行:

start program = "PATH-to-file/streambash.sh restart" with timeout 30 seconds

这确实有助于我理解 monit 的思维方式,在 monit 做事的同时在终端窗口中观看实时日志:

 tail -f /var/log/monit.log

关于linux - 如果 TOTAL CPU 小于 1%,则使用 monit 重启 ffmpeg 进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41568610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com