mjpg-streamer on bootup


4 posts
by myminimonster » Sat Jan 26, 2013 5:50 pm
Hi all,

I was wondering if someone can help me out?

I have mjpg-streamer installed that i normally start manually using
./mjpg-streamer.sh start


I am wanting to make mjpg-streamer start on boot up.

I followed this link initially but with no joy.
http://www.phillips321.co.uk/2012/11/05 ... ream-cctv/

The program is running after boot but only for a few seconds then i get no response from the page http://x.x.x.x:8081/?action=stream
When i say running i can see the process in netstat -lp -tu and for a few seconds the webcam stream works.
If i start it manually i get the response that its already runnning.
If I kill it first then start it manually the above url link working and video is streamed ok.

These are the actions i have taken to get this far.

I have created a file called mjpg-streamer.sh in /etc/init.d/ directory. The contents are
Code: Select all
#!/bin/sh
# /etc/init.d/mjpg_streamer.sh
# v0.2 phillips321.co.uk
### BEGIN INIT INFO
# Provides:          mjpg_streamer.sh
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mjpg_streamer for webcam
# Description:       Streams /dev/video0 to http://IP/?action=stream
### END INIT INFO

f_message(){
        echo "[+] $1"
        echo "space here"
}

# Carry out specific functions when asked to by the system
case "$1" in
        start)
                f_message "Starting mjpg_streamer"
                /home/pi/mjpg-streamer/mjpg-streamer.sh start
                #mjpg_streamer -b -i "/usr/lib/input_uvc.so -d /dev/video0" -o "/usr/lib/output_http.so -p 8081 -w /var/www/mjpg_streamer -n"
                sleep 2
                f_message "mjpg_streamer started"
                ;;
        stop)
                f_message "Stopping mjpg_streamer."
                /home/pi/mjpg-streamer/mjpg-streamer.sh stop
                f_message "mjpg_streamer stopped"
                ;;
        restart)
                f_message "Restarting mjpg_streamer"
                /home/pi/mjpg-streamer/mjpg-streamer.sh stop
                #killall mjpg-streamer
                /home/pi/mjpg-streamer/mjpg-streamer.sh start
                 #mjpg-streamer -b -i "/usr/lib/input_uvc.so -d /dev/video0" -o "/usr/lib/output_http.so -p 8081 -w /var/www/mjpg_streamer -n"
                sleep 2
                f_message "Restarted mjpg_streamer"
                ;;
        status)
                pid=`ps -A | grep mjpg-streamer | grep -v "grep" | grep -v mjpg-streamer. | awk .{print $1}. | head -n 1`
                if [ -n "$pid" ];
                then
                        f_message "mjpg_streamer is running with pid ${pid}"
                        f_message "mjpg_streamer was started with the following command line"
                        cat /proc/${pid}/cmdline ; echo ""
                else
                        f_message "Could not find mjpg_streamer running"
                fi
                ;;
        *)
                f_message "Usage: $0 {start|stop|status|restart}"
                exit 1
                ;;
esac
exit 0


you can see that i commented out the line
Code: Select all
mjpg-streamer -b -i "/usr/lib/input_uvc.so -d /dev/video0" -o "/usr/lib/output_http.so -p 8081 -w /var/www/mjpg_streamer -n"

as this was the only way to get it working manually, by putting the direct path to the program and adding the start/stop parameter on the end instead.

After creating the above I made the file and path to it executable using chmod +X <xxx> and chmod 777 <name>.

I then did as per the instructions and made it runnable from boot with
Code: Select all
sudo update-rc.d mjpg-streamer.sh defaults


Watching the streaming url on bootup, it starts the webpage streaming but then it stops(light goes out on webcam/url stops responding) even though the process (netstat -lp -tu) still shows it as running.

My thoughts were that there was a problem with the symbolic links and one of these was killing the program but there again it still showing in netstat- -lp -tu.
To try it anyway I manually added these
ln -s /etc/init.d/mjpg-streamer.sh /etc/rc0.d/K01mjpg-streamer.sh
ln -s /etc/init.d/mjpg-streamer.sh /etc/rc1.d/K01mjpg-streamer.sh
ln -s /etc/init.d/mjpg-streamer.sh /etc/rc2.d/S03mjpg-streamer.sh
ln -s /etc/init.d/mjpg-streamer.sh /etc/rc3.d/S03mjpg-streamer.sh
ln -s /etc/init.d/mjpg-streamer.sh /etc/rc4.d/S03mjpg-streamer.sh
ln -s /etc/init.d/mjpg-streamer.sh /etc/rc5.d/S03mjpg-streamer.sh
ln -s /etc/init.d/mjpg-streamer.sh /etc/rc6.d/K01mjpg-streamer.sh


So in all i think the process is running from boot but there is a problem with the actual streaming working, but as mentioned only when asking it to do it from boot, works ok when manually executing the program with
/etc/init.d/mjpg-streamer.sh start


I maybe off the track completely so maybe useful to try and diagnose why it starts and works ok and then a few seconds after, further into the bootup, it stops again.

If anyone has any ideas or tips they would be much appreciated.

Thanks in advance
Adrian
Newbie
Posts: 33
Joined: Sun Dec 30, 2012 11:08 pm
Location: Midlands UK
by bblood » Tue Feb 05, 2013 2:32 pm
Not to hijack a thread, but I have a similar problem with mjpg-streamer... I have also set it to start on boot and run as a service....this works fine, but only for a short while. In fact, it doesn't matter how i start mjpg-streamer. It olny streamer for a short time. When the stream stops, the service is still running, I just lose the video. To get it running again I simply restart the service. In my case, the light on the webcam stays on even though the stream has stopped. I made a workaround for this by using a php script in my webpage to allow me to reset the service from within the browser...not pretty, but it works...

I have a feeling this problem is rooted in the very problematic USB driver/hardware we are stuck with....if anyone out there has a suggestion, please help!

Bill
Posts: 40
Joined: Sat Sep 22, 2012 1:54 am
by myminimonster » Tue Feb 05, 2013 6:10 pm
Hi,

That is interesting as to why it is stopping whatever way you choose to start it.

Before i mentioned that mine would start for a few seconds during boot and then stop.

I found during my investigations that I may have been confusing the system by having mjpg-streamer installed in my own directory with its own mjpg-streamer.sh file and also having a copy of the for-mentioned mjpg-streamer.sh script created in my etc/init.d/ directory. This along with my start and stop symbolic links i think it was getting killed somewhere.

I got around this by removing all the symbolic links from the rcX.d directories, removing the mjpg-streamer.sh script from the /etc/init.d/ directory.

I now simply call the mjpg-streamer.sh file once from its original install directory by placing the code i would use to call it manually into my etc/rc.local file.

here is a snippet of how my rc.local files looks.

Code: Select all
case "$1" in
    start)
        do_start
        /home/pi/mjpg-streamer/mjpg-streamer.sh start


Hope this helps others in the future.

when you say yours in running, do you see the process in ps aux? I was using netstat -lp -tu to check if mjpg-streamer was running initially until i realized that by doing ps aux | grep mjpg I could see the script had been started from within my install directory and from where my symbolic links were pointing.


Adrian
Newbie
Posts: 33
Joined: Sun Dec 30, 2012 11:08 pm
Location: Midlands UK
by sa10dra » Thu Oct 17, 2013 7:19 pm
Hi initially faced problems like you. The streamer would start at boot but then drop dead.
However I just had a hunch that this could be related to power supply as I had read on multiple threads about problems attributed to bad supply. I was using a 5.5 V 500 mA power supply. I replaced that by my Galaxy S4 charger 5V 2A. And my problem was resolved without doing anything of the sort mentioned by you. I haven't had a single crash of mjpg streamer since then. It starts with every boot and works for hours at a stretch.

Cheers!
Posts: 1
Joined: Thu Oct 17, 2013 6:54 pm