Quantcast
Viewing all articles
Browse latest Browse all 10

Server crashes when running shell script

Image may be NSFW.
Clik here to view.
Question

I have a virtual machine running CentOS 5.5 that I use as a streaming server.

If I open 4 terminals and do this:

terminal 1:

 # mkfifo pipe1.avi
 # mkfifo pipe2.avi
 # ffserver &
 # ffmpeg -probesize 164000 -i pipe1.avi -async 1 -r 25 http://localhost:8090/feed1.ffm

terminal 2:

 # ffmpeg -i pipe2.avi -async 1 -r 25 -vcodec flv -f flv somename.flv

terminal 3:

 # mplayer -dumpstream rtp://someIp:somePort -dumpfile pipe1.avi

terminal 4:

 # mplayer -dumpstream rtp://someIp:somePort -dumpfile pipe2.avi

Everything is working great. No problems nowhere.

Now I’m trying to make a script and run it from a cron. This is the script:

ffserver &
ffmpeg -probesize 164000 -i pipe1.avi -async 1 -r 25 http://localhost:8090/feed1.ffm &
ffmpeg -i pipe2.avi -async 1 -r 25 -vcodec flv -f flv somename.flv &
mplayer -dumpstream rtp://someIp:somePort -dumpfile pipe1.avi &
mplayer -dumpstream rtp://someIp:somePort -dumpfile pipe2.avi &
exit 0

The crontab line is:

10 * * * * script.sh > /dev/null 1>&2

The problem is that when the cron is run, the system crashes Actually, it doesn’t really crash the stream, which I see from another computer and is working perfectly. But, I can’t do anything on the machine. The screen becomes black and I can’t do anything except restart it. I have a script that kills the anterior processes. If I use it the stream stops, but I still don’t regain access to the system (same black screen whatever I do).

Image may be NSFW.
Clik here to view.
Answer

  1. Redirect everything to some log files: use command > /home/username/xxx.log 2>&1 & (don’t use tmp, because at restart tmp is flushed)
  2. Add some sleep 5 between commands, is possible to to have processes that start slowly and that it will give some time to start in given order (you also can use wait command, but to test, sleep should be enough)
  3. Mplayer is doing that (is taking control of your console). Use -vo dummy to see if is working.
    If still not working take a look in logs to see if any “terminal” problems appear.

Viewing all articles
Browse latest Browse all 10

Trending Articles