#!/bin/sh
# /etc/init.d/mjpg_streamer

### BEGIN INIT INFO
# Provides:          mjpg_streamer
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: MJPG_Streamer_autostart
### END INIT INFO

start()
{
 modprobe bcm2835-v4l2
 sleep 2
 echo "Starting mjpg-streamer..."
 /usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -d /dev/video0 -n -r 1024x768 -f 24 –q 80" -o "/usr/local/lib/output_http.so -n -w /usr/local/www -p 9000" >/dev/null 2>&1 &
}

stop()
{
 echo "Stopping mjpg-streamer..."
 kill -9 $(pidof mjpg_streamer) >/dev/null 2>&1
}

case "$1" in
 start)
   start
   ;;
 stop)
   stop
   ;;
 restart)
   stop
   start
   ;;
 *)
   echo "Usage: $0 {start|stop|restart}"
   ;;
esac

exit 0
