我正在尝试在 Raspberry Pi 上记录关闭/重新启动。我正在运行最新的 Raspbian。这是我的设置:
cat /etc/init.d/log-shutdown.sh
:
#!/bin/sh
### BEGIN INIT INFO
# Provides: log-shutdown
# Required-Start:
# Required-Stop: umountroot
# Should-Stop:
# Default-Start:
# Default-Stop: 0 6
# Short-Description: Log shutdown date.
### END INIT INFO
echo "I ran">/log-shutdown
ls -Al /etc/init.d/log-shutdown.sh
:
-rwxr-xr-x 1 root root 258 Apr 15 20:10 /etc/init.d/log-shutdown.sh
ls -Al /etc/rc0.d/*log-shutdown*
lrwxrwxrwx 1 root root 25 Apr 15 19:41 /etc/rc0.d/K01log-shutdown.sh -> ../init.d/log-shutdown.sh
ls -Al /etc/rc6.d/*log-shutdown*
:
lrwxrwxrwx 1 root root 25 Apr 15 19:41 /etc/rc6.d/K01log-shutdown.sh -> ../init.d/log-shutdown.sh
运行sudo shutdown -r now
并等待 Pi 重新启动后,/log-shutdown
未写入。手动运行sudo /etc/init.d/log-shutdown.sh
确实会写入文件。我究竟做错了什么?
答案1
所以。我似乎找到了一个解决方案,但我不知道为什么需要它,因为它不在 Ubuntu 上。/etc/init.d/log-shutdown
(我删除了.sh
)现在看起来像这样:
#!/bin/sh
### BEGIN INIT INFO
# Provides: log-shutdown
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Log shutdown date
### END INIT INFO
case "$1" in
start)
touch /var/lock/subsys/log-shutdown
;;
stop)
date +%s > /data/log/log-shutdown
;;
*)
echo "Usage: /etc/init.d/log-shutdown stop"
exit 1
;;
esac
重要的一点是touch /var/lock/subsys/log-shutdown
,它告诉 init 系统正在log-shutdown
运行,因此它会在关机/重新启动时运行停止脚本。我认为。