1

I've tried to modify this script to start Motion using the following libraries.

I start the script by entering the following command into terminal:

sudo /etc/init.d/motion start

Which Gives:

start-stop-daemon: user '/etc/motion/motion.conf' not found
Starting motion detection daemon: motion failed!

I've triple checked that the motion.conf file has the correct permissions and is in the /etc/motion/ directory.

If I enter the following command into terminal, Motion starts correctly.

LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so motion -c /etc/motion/motion.conf

The script is in /etc/init.d and called motion.

#!/bin/sh -e
#
# /etc/init.d/motion: Start the motion detection
#
### BEGIN INIT INFO
# Provides:   motion
# Required-Start: $local_fs $syslog $remote_fs
# Required-Stop: $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Motion detection
# Description: loads motion and assigns privileges
### END INIT INFO

# Ported to new debian way using sh and /lib/lsb/init-functions
# by Angel Carpintero <ack@telefonica.net>
# Modified by : Juan Angulo Moreno <juan@apuntale.com>
# eddy Petrisor <eddy.petrisor@gmail.com>
# ArAge <ArAge@gmx.co.uk>


NAME=motion
PATH_BIN=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/bin/motion
PIDFILE=/var/run/$NAME.pid
DEFAULTS=/etc/default/$NAME
DESC="motion detection daemon"
export "LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so" 

###########################################################################################################
### this above command is what is needed to be entered into terminal to run motion from command prompt ####
###########################################################################################################
ENV="env -i LANG=C PATH=$PATH_BIN"

. /lib/lsb/init-functions

test -x $DAEMON || exit 0

RET=0

[ -r "$DEFAULTS" ] && . "$DEFAULTS" || start_motion_daemon=yes


check_daemon_enabled () {
    if [ "$start_motion_daemon" = "yes" ] ; then
        return 0

    else
        log_warning_msg "Not starting $NAME daemon, disabled via /etc/default/$NAME"
        return 1
    fi

}


case "$1" in

  start)
    if check_daemon_enabled ; then
        if ! [ -d /var/run/motion ]; then
                mkdir /var/run/motion
        fi
        chown motion:motion /var/run/motion
        chmod 777 /var/run/motion
        # this is the fix we've added to allow the network share to be connected first before we try to start motion:

        sleep 30

        log_daemon_msg "Starting $DESC" "$NAME" 
        if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion $DAEMON -c /etc/motion/motion.conf ; then
            log_end_msg 0
         else
            log_end_msg 1
            RET=1
        fi
    fi
    ;;

  stop)
    log_daemon_msg "Stopping $DESC" "$NAME"
    if start-stop-daemon --stop --oknodo --exec $DAEMON --retry 30 ; then
        log_end_msg 0
    else
        log_end_msg 1
        RET=1
    fi
    ;;

  reload|force-reload)
    log_daemon_msg "Reloading $NAME configuration"
    if start-stop-daemon --stop --signal HUP --exec $DAEMON ; then
        log_end_msg 0
    else
        log_end_msg 1
        RET=1
    fi
    ;;

  restart-motion)
    if check_daemon_enabled ; then
        log_action_begin_msg "Restarting $NAME"
        if $0 stop && $0 start ; then
            log_action_end_msg 0
        else
            log_action_cont_msg "(failed)"
            RET=1
        fi
    fi
    ;;

  restart)
    $0 restart-motion
    ;;

  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload}"
    RET=1
    ;;
esac


exit $RET

following Anthon's and Mikeserv help, here is some more information:

1) command: ls -lrt /var/log

Gives:

-rw-r----- 1 root adm 122336 Oct 12 08:10 auth.log

2) auth.log entry gives:

08:10:26 raspberrypi sudo: pam_unix(sudo:session): session closed for user root

  • Why export =...? that's probably not what you want. Maybe export "LD_PRELOAD=..." would work better... – mikeserv Oct 12 '14 at 7:10
  • @mikeserv tried that, see updated question :( – reggie Oct 12 '14 at 8:19
2

Replace the lines LOAD_LIBRARIES.... with:

export LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so

This makes the LD_PRELOAD setting available to commands/programs called from the script (like motion

And the line if start-stop-daemon --start ....

if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion $DAEMON -c /etc/motion/motion.conf ; then

The start-stop-daemon option --chuid takes as parameter a username, so I expect motion to be that name. That leaves no command on the original line, that is why you should insert $DAEMON (the full path to motion) and its commandline parameter there.

  • Thanks for the answer; sorry about the tabs, I copied the script from source, without modification. – reggie Oct 11 '14 at 12:26
  • 1
    @reggie Unfortunately there is no search and replace when editing/improving content, I could have had copied the content out into an editor, edit and the paste back in. So it is much easier to fix that before pasting it in. The more readable your Q, the more chance for a (quick) answer. ;-) – Anthon Oct 11 '14 at 12:36
  • 1
    @reggie I already did in my updated answer, after --chuid motion (scroll to the right). – Anthon Oct 11 '14 at 19:25
  • 1
    Have you looked in the log files after issuing the command, somewhere the program must complain if it cannot start for some reason. – Anthon Oct 11 '14 at 20:00
  • 1
    @reggie Depends on your system, run the start motion then do ls -lrt /var/log to see the latest file(s) written to. – Anthon Oct 11 '14 at 21:15
0

After many hours of frustration and lots of help from forum members I've managed to get it working. I'm by no means taking the credit for this, by posting an answer, and appreciate all the help people have given me; but just fore completeness, this is how I did it.

I added the line export LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so in the script /etc/init.d/motion and made sure the folder that I was saving my pictures to, had the permissions so that user motion could write to it -opps!

#!/bin/sh -e
#
# /etc/init.d/motion: Start the motion detection
#
### BEGIN INIT INFO
# Provides:   motion
# Required-Start: $local_fs $syslog $remote_fs
# Required-Stop: $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Motion detection
# Description: loads motion and assigns privileges
### END INIT INFO

# Ported to new debian way using sh and /lib/lsb/init-functions
# by Angel Carpintero <ack@telefonica.net>
# Modified by : Juan Angulo Moreno <juan@apuntale.com>
# eddy Petrisor <eddy.petrisor@gmail.com>
# ArAge <ArAge@gmx.co.uk>


NAME=motion
PATH_BIN=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/bin/motion
PIDFILE=/var/run/$NAME.pid
DEFAULTS=/etc/default/$NAME
DESC="motion detection daemon"


ENV="env -i LANG=C PATH=$PATH_BIN"

. /lib/lsb/init-functions

test -x $DAEMON || exit 0

RET=0

[ -r "$DEFAULTS" ] && . "$DEFAULTS" || start_motion_daemon=yes


check_daemon_enabled () {
    if [ "$start_motion_daemon" = "yes" ] ; then
        return 0

    else
        log_warning_msg "Not starting $NAME daemon, disabled via /etc/default/$NAME"
        return 1
    fi

}

case "$1" in

  start)
    if check_daemon_enabled ; then
        if ! [ -d /var/run/motion ]; then
                mkdir /var/run/motion
        fi
        chown motion:motion /var/run/motion
        #=================insert this line to  load the uv4l libraries====
        export LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so
        #=================================================================
        chmod 777 /var/run/motion
        sleep 30

        log_daemon_msg "Starting $DESC" "$NAME" 
        if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion ; then
            log_end_msg 0
         else
            log_end_msg 1
            RET=1
        fi
    fi
    ;;

  stop)
    log_daemon_msg "Stopping $DESC" "$NAME"
    if start-stop-daemon --stop --oknodo --exec $DAEMON --retry 30 ; then
        log_end_msg 0
    else
        log_end_msg 1
        RET=1
    fi
    ;;

  reload|force-reload)
    log_daemon_msg "Reloading $NAME configuration"
    if start-stop-daemon --stop --signal HUP --exec $DAEMON ; then
        log_end_msg 0
    else
        log_end_msg 1
        RET=1
    fi
    ;;

  restart-motion)
    if check_daemon_enabled ; then
        log_action_begin_msg "Restarting $NAME"
        if $0 stop && $0 start ; then
            log_action_end_msg 0
        else
            log_action_cont_msg "(failed)"
            RET=1
        fi
    fi
    ;;

  restart)
    $0 restart-motion
    ;;

  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload}"
    RET=1
    ;;
esac


exit $RET

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.