2017-01-10 4 views
0

이와 비슷한 솔루션을 사용하여 Restarting ffmpeg process using monit과 같은 이유로 ffmpeg 스트림을 다시 시작하면 어떤 이유로 실패합니다. 문제/질문이 중복되지 않는다는 것을 기억하십시오. 예제 질문/솔루션 Restarting ffmpeg process using monit과 달리 다른 문제가 있기 때문에 아래에서 설명 드리겠습니다. 여기 TOTAL CPU가 1 % 미만인 경우 monit을 사용하여 ffmpeg 프로세스 다시 시작

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는 파일을 시작할 수 있지만이 조건 "TOTAL CPU가 1보다 작 으면, 그래서 여기 내 MONIT 구성입니다 10 사이클 동안 %를 다시 시작한 후 "가 monit 구성과 일치하면 다시 시작하려고 시도하지만 프로세스가 실행되고 있지 않다는 오류가 발생합니다. 그러나 실제로 ffmpeg 프로세스는 백그라운드에서 계속 실행되며 스트림이 내 웹 사이트에 게시 된 것을 볼 수 있습니다. 여기 MONIT 로그입니다 :

[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이 프로세스를 다시 시작하려고 유지하고 각 재 시도에, 그것은 경로에 파일/streampid.pid에 새로운 PID 덤프하지만, 내가 말한대로 어떻게 든 그것을 보인다 백그라운드에서 계속 실행중인 실제 ffmpeg 스트림/PID를 중지 할 수 있습니다.

+0

nice 또는 cgroup을 사용하지 않는 이유는 무엇입니까? –

+0

내 문제는 CPU를 처리하지 않습니다, 내 문제는 프로세스가 다시 시작되지 않거나 적어도 실행되지 않은 후에는 monit에서 시작된 것으로 표시되지 않습니다. CPU 사용량은 프로세스가 작동하지 않거나 ffmpeg가 인코딩 또는 관련 문제인지를 파악하는 데 사용됩니다. nice 또는 cgroup을 사용하는 것이 이치에 맞지 않습니다. – user2201239

답변

0

폴링주기/데몬 점검 간격이 5 초로 매우 짧습니다.

FFMpeg가 5 초 이내에 시작되지 않으므로 monit은 계속해서 루프를 반복하여 시작하려고합니다. 사고, 시계의 MONIT의 방법을 이해하는

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

이 정말 날 수 있습니다 : 당신이 그런 낮은 확인 간격을 원한다면

, 당신의 라인을 따라, 시작 명령에 제한 시간을 설정해야 monit이 일을하는 동안 터미널 창에 실시간 로그인 :

tail -f /var/log/monit.log 
+0

또 다른 것은, monit/monit webif는 최근에 시작한 프로세스에서 CPU 사용을 탐지하고 업데이트하는 속도가 매우 느립니다. 인내심을 갖고 몇 분 만주세요! 프로세스가 시작되었고 예를 들어 CPU가 10 % 인 monit webif는 프로세스가 여전히 0 %를 사용 중이며 때로는 끝이없는 루프에서 프로세스를 다시 시작 함을 나타냅니다. – Paul