我嘗試修改此腳本以使用以下庫啟動 Motion。
我透過在終端機中輸入以下命令來啟動腳本:
sudo /etc/init.d/motion start
這使:
start-stop-daemon: user '/etc/motion/motion.conf' not found
Starting motion detection daemon: motion failed!
我已經三次檢查了motion.conf 檔案是否具有正確的權限並且位於/etc/motion/ 目錄中。
如果我在終端機中輸入以下命令,Motion 會正確啟動。
LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so motion -c /etc/motion/motion.conf
劇本已經進入/etc/init.d
並被稱為“動作”。
#!/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 <[email protected]>
# Modified by : Juan Angulo Moreno <[email protected]>
# eddy Petrisor <[email protected]>
# ArAge <[email protected]>
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
在 Anthon 和 Mikeserv 的幫助下,以下是更多資訊:
1)命令:ls -lrt /var/log
給出:
-rw-r----- 1 root adm 122336 十月 12 日 08:10 auth.log
2) auth.log 條目給出:
08:10:26 raspberrypi sudo:pam_unix(sudo:session):使用者 root 的會話已關閉
答案1
將這些行替換 LOAD_LIBRARIES....
為:
export LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so
這使得 LD_PRELOAD 設定可用於從腳本呼叫的命令/程式(例如motion
還有那條線if start-stop-daemon --start ....
if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion $DAEMON -c /etc/motion/motion.conf ; then
該start-stop-daemon
選項--chuid
將使用者名稱作為參數,因此我希望motion
是該名稱。這在原始行上沒有留下任何命令,這就是為什麼您應該在motion
其中插入 $DAEMON ( 的完整路徑)及其命令列參數。
答案2
經過幾個小時的挫折和論壇成員的大量幫助後,我終於讓它工作了。我絕不是透過發布答案來獲得此榮譽,並感謝人們給我的所有幫助;但為了完整起見,我就是這樣做的。
export LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so
我在腳本中添加了該行/etc/init.d/motion
,並確保我保存圖片的資料夾具有權限,以便用戶動作可以寫入它 -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 <[email protected]>
# Modified by : Juan Angulo Moreno <[email protected]>
# eddy Petrisor <[email protected]>
# ArAge <[email protected]>
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