linux - 使用monit重启ffmpeg进程

标签 linux bash ffmpeg monitoring monit

我正在尝试使用 monit 来监控 ffmpeg 进程。为此,我首先创建了一个具有 3 个参数(开始、停止和重新启动)的 bash 脚本。当我从终端 (./thisBashScript start, ./thisBashScript stop and ./thisBashScript restart ) 手动运行脚本时,一切都按照设计的方式完美运行。该进程启动、创建并将当前进程 id 保存到 pid 文件中。如果我想停止进程,它会获取当前 pid 文件并使用给定的 pid 终止进程。重新启动也能正常工作,首先它停止,然后启动该过程。

问题

我安装了 monit 以监控进程以防它出现故障。我配置为以与我配置的 nginx 完全相同的方式检查进程,该 nginx 与 monit 配合得很好。

之后,当我使用命令 ./thisBashScript start 启动进程时,monit 开始监视。在监控状态下,进程 ffmpeg 显示为正在运行。在我使用 ffmpeg 进程的 pid 手动终止进程以测试 monit 是否重新启动进程后,它没有这样做。即使新的 pid 已创建并保存在 /var/run/ffmpeg.pid 中。

这是监控日志:

[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 命令);

  • 重新启动(它停止然后启动 ffmpeg 命令);

这是我的监控配置

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" 

最佳答案

问题已通过创建符号链接(symbolic link)解决:

ln -s /opt/intel/mediasdk/lib64/iHD_drv_video.so /usr/local/lib/dri/i965_drv_video.so

关于linux - 使用monit重启ffmpeg进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36128450/

相关文章:

linux - bash 记录器 : Cannot find a way to add MaxBackupIndex to this logger implementation

bash - 在函数 Bash : how to check if an argument is a set variable? 中

batch-file - 使用 ffmpeg 进行 Nginx 实时转码

c - 文件段错误(核心转储)(C-linux)

c - 像 "bpf_map_update_elem"这样的bps API map 助手的详细过程是什么?

linux - Kubernetes与Linux之间的兼容性

python - 在 shell 中使用 python 脚本(如 fabric)

linux - 如何比较两个文本文件,同时忽略从一个实例到下一个实例的更改字段?

video - 使用 FFMPEG 在视频上叠加视频时如何包含两个音频

php - 为什么 FFMPEG 在终端中工作但在带有 exec() 的 php 中不工作?