fswebcam
#!/bin/sh
### BEGIN INIT INFO
# Provides: fswebcam
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: Starts fswebcam capture.
### END INIT INFO
 
#fswebcam service
FSWEBCAM_USER="fswebcam"
#picture name
FSWEBCAM_PICTURE="jericho.jpg"
FSWEBCAM_TITLE="Rose of Jericho"
 
DAEMON=/usr/bin/fswebcam
 
start() {
   echo "Starting fswebcam..."
   HOMEDIR=`getent passwd $FSWEBCAM_USER | cut -d: -f6`
   if [ -x $DAEMON ]; then
       HOME="$HOMEDIR" start-stop-daemon --start -c $FSWEBCAM_USER --pidfile $HOMEDIR/fswebcam.pid --make-pidfile --exec $DAEMON --background -- -r 320x240 --jpeg 95 --title "$FSWEBCAM_TITLE" --save $HOMEDIR/$FSWEBCAM_PICTURE -l 1 -q
   fi
}
 
stop() {
   echo "Stopping fswebcam..."
   HOMEDIR=`getent passwd $FSWEBCAM_USER | cut -d: -f6`
   if [ -x $DAEMON ]; then
       start-stop-daemon -o -c $FSWEBCAM_USER -K -u $FSWEBCAM_USER --pidfile $HOMEDIR/fswebcam.pid -x $DAEMON -- -r 320x240 --jpeg 95 --title \'$FSWEBCAM_TITLE\' --save $HOMEDIR/$FSWEBCAM_PICTURE -l 1 -q
   fi
}
 
status() {
 
   dbpid=`pgrep -u $FSWEBCAM_USER fswebcam`
   if [ -z $dbpid ] ; then
       echo "fswebcam for USER $FSWEBCAM_USER: not running."
   else
       echo "fswebcam for USER $FSWEBCAM_USER: running (pid $dbpid)"
   fi
 
}
 
case "$1" in
 
   start)
       start
       ;;
   stop)
       stop
       ;;
   restart|reload|force-reload)
       stop
       start
       ;;
   status)
       status
       ;;
   *)
       echo "Usage: /etc/init.d/fswebcam {start|stop|reload|force-reload|restart|status}"
       exit 1
 
esac
 
exit 0