/usr/lib/systemd/system-shutdown/
Run Code Online (Sandbox Code Playgroud)
或在 Debian 中
/lib/systemd/system-shutdown/
Run Code Online (Sandbox Code Playgroud)
让它在重启或关机时执行。从
https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html:
在执行实际系统halt/poweroff/reboot/kexec systemd-shutdown 之前,将运行/usr/lib/systemd/system-shutdown/ 中的所有可执行文件,并向它们传递一个参数:“halt”、“poweroff”、“reboot” " 或 "kexec",取决于选择的操作。此目录中的所有可执行文件都是并行执行的,并且在所有可执行文件完成之前不会继续执行操作。
我的脚本在How to run a script at shutdown on Debian 9 or Raspbian 8 (Jessie) 中描述为:
#!/bin/sh
touch /test
Run Code Online (Sandbox Code Playgroud)
但是,它似乎无法在我的 Debian 系统上运行,我什至将其报告为bug。
我想在重启和关闭时执行这个 shell 脚本:
#!/bin/sh
touch /test
Run Code Online (Sandbox Code Playgroud)
它的权限是
-rwxr-xr-x 1 root root 22 Feb 24 09:34 /etc/init.d/te1
Run Code Online (Sandbox Code Playgroud)
它有这个链接
/etc/rc0.d/K01te1 -> ../init.d/te1
/etc/rc6.d/K01te1 -> ../init.d/te1
Run Code Online (Sandbox Code Playgroud)
如果我有这个链接,它在启动时工作
/etc/rc5.d/S01te1 -> ../init.d/te1
Run Code Online (Sandbox Code Playgroud)
但我需要它在关机时运行。
我如何在 Debian 8 和 9 测试中做到这一点?
该建议 touch /var/lock/subsys/te1
没有奏效。