我正在尝试使用monit来监视ffmpeg进程 . 为此,我首先创建了一个包含3个参数(启动,停止和重启)的bash脚本 . 当我从终端 (./thisBashScript start, ./thisBashScript stop and ./thisBashScript restart )
手动运行脚本时,一切都完美无瑕 . 该过程启动,创建当前过程id并将其保存到pid文件中 . 如果我想要停止进程,它将获取当前的pid文件并使用给定的pid终止进程 . 重新启动也很好,首先它停止并在启动过程后 .
The problem
我安装了monit来监控进程,以防它发生故障 . 我配置为以确切的方式检查过程,因为我配置了nginx,这非常适合使用monit .
之后,当我用 ./thisBashScript start
命令启动进程时,monit开始监控 . 在监控状态下,进程ffmpeg显示为正在运行 . 在我使用ffmpeg进程的pid手动终止进程以测试monit是否重新启动进程后,它无法执行此操作 . 即使新的pid已创建并保存在 /var/run/ffmpeg.pid
中 .
这是monit日志:
[EET Mar 21 12:12:37] error : 'ffmpeg' process is not running
[EET Mar 21 12:12:37] info : 'ffmpeg' trying to restart
[EET Mar 21 12:12:37] info : 'ffmpeg' start: /etc/init.d/iptv/thisBashScript
我有以下bash脚本:
#!/bin/sh
pid_file="/var/run/ffmpeg.pid"
case "$1" in
restart)
/etc/init.d/iptv/thisBashScript stop
/etc/init.d/iptv/thisBashScript start
;;
start)
rm $pid_file
ffmpeg -i udp://@someIp:1234 -acodec libmp3lame -ac 1 -ar 44100 -ab 64k -s 640x360 -deinterlace -vcodec h264_qsv -vb 700k -f flv rtmp://someIp/applicationName/360 &
ch_pid=$!
echo "Start HLS: ffmpeg = $ch_pid";
echo $ch_pid > $pid_file
;;
stop)
echo "Stop transcoding";
kill `cat $pid_file`
;;
*)
echo "Usage: /etc/init.d/thisBashScript {start|stop|restart}"
exit 1
;;
esac
exit 0
echo $pid_file
这个bash脚本可以接受3个参数(启动,重启和停止)
-
start(它启动在nginx rtmp服务器上流式传输视频的ffmpeg命令);
-
停止(它停止ffmpeg命令);
-
restart(它停止然后启动ffmpeg命令);
这是我的monit配置
check process ffmpeg with pidfile /var/run/ffmpeg.pid
start program = "/etc/init.d/iptv/thisBashScript start"
stop program = "/etc/init.d/iptv/thisBashScript stop"
1 回答
通过创建符号链接解决了这个问题: