问题
I am trying to use monit for monitoring the ffmpeg process. For this I first created a bash script that has 3 arguments(start, stop and restart). When I run the script manually from the terminal (./thisBashScript start, ./thisBashScript stop and ./thisBashScript restart )
everything works perfectly how it was designed. The process starts, creates and saves the current procees id into a pid file. After if I want to stop the process it takes the current pid file and and kills the process with the given pid. Restarts also works fine, first it stops and after starts the process.
The problem
I installed monit for monitoring the process in case it goes down. I configured to check the process in the exact manner as I configured nginx that excellent works with monit.
After, when I start the process with the command ./thisBashScript start
monit starts monitoring. In monit status the process ffmpeg is showing as running. After I kill the process manually using the pid of ffmpeg process to test if monit restarts the process, it fails to do so. Even though the new pid is created and saved in /var/run/ffmpeg.pid
.
Here are the monit logs:
[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
I have the following bash script:
#!/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
This bash script can accept 3 arguments (start, restart and stop)
start (it starts the ffmpeg command that streams a video on an nginx rtmp server);
stop (it stops the ffmpeg command);
restart (it stops and then starts ffmpeg command);
Here is my monit configuration
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:
The problem was solved by creating a symlink:
ln -s /opt/intel/mediasdk/lib64/iHD_drv_video.so /usr/local/lib/dri/i965_drv_video.so
来源:https://stackoverflow.com/questions/36128450/restarting-ffmpeg-process-using-monit