#! /bin/sh
# 
# Copyright 2005 Peter Poeml <poeml at cmdline dot net>
# License: GPL
#
#
### BEGIN INIT INFO
# Provides:                     motion
# Required-Start:               $local_fs $remote_fs $network
# Required-Stop:                $local_fs $remote_fs $network
# Should-Start:                 $named $time greylistd
# Should-Stop:                  $named $time greylistd
# Default-Start:                3 5
# Default-Stop:                 0 1 2 6
# Short-Description:            motion video-surveillance system
# Description:                  Start motion
### END INIT INFO

#set -x

MOTION_PID=/var/run/motion.pid
MOTION_BIN=/usr/bin/motion

if [ -s /etc/sysconfig/motion ]; then

        . /etc/sysconfig/motion

fi

. /etc/rc.status
rc_reset

case "$1" in
    start)
        echo -n "Initializing motion"
        if [ -e $MOTION_PID ]; then
                startproc -p $MOTION_PID $MOTION_BIN $MOTION_ARGS
        else
                $MOTION_BIN $MOTION_ARGS
        fi
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down motion"
        killproc -p $MOTION_PID -TERM $MOTION_BIN
        rc_status -v
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    status)
        echo -n "Checking for service motion: "
        checkproc -p $MOTION_PID $MOTION_BIN
        rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac
rc_exit

