Skip to content

Instantly share code, notes, and snippets.

@julianrendell
Created February 18, 2015 20:24
Show Gist options
  • Save julianrendell/a86869ed401ec55ca5c9 to your computer and use it in GitHub Desktop.
Save julianrendell/a86869ed401ec55ca5c9 to your computer and use it in GitHub Desktop.
tweaked mjpg-streamer init.d script for Raspberry Pi (based on https://github.com/meinside/rpi-mjpg-streamer/blob/master/init/mjpg-streamer.sample)
#!/bin/sh
# /etc/init.d/mjpg-streamer
### BEGIN INIT INFO
# Provides: mjpg-streamer
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mjpg-streamer
# Description: Streams video to http://localhost/?action=stream on Raspberry Pi
### END INIT INFO
# referenced: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=31212&p=439248
#
# last update: 2014.01.24.
################
# customize these:
# mjpg_streamer's install location
MJPG_STREAMER_INSTALL="/usr/local"
# mjpg_streamer excutable's location
MJPG_STREAMER="$MJPG_STREAMER_INSTALL/bin/mjpg_streamer"
# streaming port
MJPG_STREAMER_PORT="80"
# htmls and related files' location
MJPG_STREAMER_WWW="$MJPG_STREAMER_INSTALL/www"
# video device
DEVICE_IN="/dev/video0"
# video settings
RESOLUTION="1920x1080"
FPS=15
# authentication
USERNAME=""
PASSWORD=""
if [ ! -z $USERNAME ] && [ ! -z $PASSWORD ]; then
AUTH="-c $USERNAME:$PASSWORD"
else
AUTH=""
fi
# LED blink
LED="auto" # on/off/blink/auto (may not work on rpi camera modules)
# plugin
PLUGIN_IN="$MJPG_STREAMER_INSTALL/lib/input_uvc.so -d $DEVICE_IN -r $RESOLUTION -f $FPS -l $LED"
PLUGIN_OUT="$MJPG_STREAMER_INSTALL/lib/output_http.so -p $MJPG_STREAMER_PORT -w $MJPG_STREAMER_WWW $AUTH"
# run
run_exec(){
$MJPG_STREAMER -i "$PLUGIN_IN" -o "$PLUGIN_OUT" -b
}
case "$1" in
start)
echo "Starting mjpg_streamer"
run_exec
echo "Started mjpg_streamer"
;;
stop)
echo "Stopping mjpg_streamer."
killall mjpg_streamer
echo "Stopped mjpg_streamer"
;;
restart)
echo "Restarting mjpg_streamer"
killall mjpg_streamer
run_exec
sleep 5
echo "Restarted mjpg_streamer"
;;
status)
pid=`ps -A | grep mjpg_streamer | grep -v "grep" | awk .{print $1}. | head -n 1`
if [ -n "$pid" ]; then
echo "mjpg_streamer is running with pid ${pid}"
echo "mjpg_streamer was started with the following command line"
cat /proc/${pid}/cmdline ; echo ""
else
echo "Could not find mjpg_streamer running"
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment