我需要在该[install]部分中添加什么,以便 systemd/home/me/so.pl在关机之前和/proc/self/net/dev被销毁之前运行?
[Unit]
Description=Log Traffic
[Service]
ExecStart=/home/me/so.pl
[Install]
?
Run Code Online (Sandbox Code Playgroud) 在文件系统重新挂载为只读后,有没有办法在关机时运行脚本?
我有一个连接到无线套接字的树莓派,我可以通过发送器和脚本来控制它。在文件系统以只读方式安装后,我想在关机时关闭该套接字(关闭树莓派的电源)。
我试过这个:
[Unit]
Description=Test
DefaultDependencies=no
Requires=shutdown.target umount.target final.target
After=shutdown.target umount.target final.target
[Service]
Type=oneshot
ExecStart=/test
KillMode=none
[Install]
WantedBy=halt.target
Run Code Online (Sandbox Code Playgroud)
脚本 /test 确实输出当前的挂载。当它在关机时运行时,它声明根文件系统的读/写,而不是预期的只读。
编辑:
/test 的内容:
#!/bin/bash
echo -n 'Debug-Mount: ' > /dev/tty1
cat /proc/mounts | grep /dev/sda > /dev/tty1
Run Code Online (Sandbox Code Playgroud)
关机时的屏幕输出:
我想在重启和关闭时执行这个 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没有奏效。
shutdown ×3
systemd ×2
init-script ×1
linux ×1
readonly ×1
system-v ×1
sysvinit ×1
unmounting ×1