系统相关
首页 > 系统相关> > linux – 为什么/etc/rc6.d中的脚本不能在重启时运行?

linux – 为什么/etc/rc6.d中的脚本不能在重启时运行?

作者:互联网

我试图在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会写入该文件.我究竟做错了什么?

解决方法:

所以.我似乎找到了一个解决方案,但我不知道为什么需要它,因为它不在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系统日志关闭正在运行,因此在shutdown / reboot上运行stop脚本时很烦人.我认为.

标签:init-d,linux,shutdown
来源: https://codeday.me/bug/20190815/1660506.html