在系统关闭/重新启动/关闭电源之前,我已经尝试尝试启动脚本的时间早于其他任何脚本。不幸的是systemd被用作我正在使用的系统上的初始化子系统。
我做了什么 1.创建了一个依赖于multi-user.target的附加目标:
~$ cat /lib/systemd/system/last-service.target
[Unit]
Description=Last service(s) to start
Requires=multi-user.target
After=multi-user.target
AllowIsolate=yes
2。创建了last-service.target所需的服务:
~$ cat /lib/systemd/system/shutdown-system.service
[Unit]
Description=Before power off
Requires=multi-user.targer
After=multi-user.targer
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/logger "XXXy will start now"
ExecStop=/usr/bin/logger "XXXz will poweroff now"
[Install]
WantedBy=last-service.target
现在,如果我检查服务/目标状态,我会看到:
~$ sudo systemctl -l status last-service.target
● last-service.target - Last service(s) to start
Loaded: loaded (/lib/systemd/system/last-service.target; enabled)
Active: active since Tue 2018-07-03 11:22:14 UTC; 36min ago
~$ sudo systemctl -l status shutdown-system.service
● shutdown-system.service - Before power off
Loaded: loaded (/lib/systemd/system/shutdown-system.service; enabled)
Active: active (exited) since Tue 2018-07-03 11:22:13 UTC; 36min ago
Process: 467 ExecStart=/usr/bin/logger XXXy will start now (code=exited, status=0/SUCCESS)
Main PID: 467 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/shutdown-system.service
因此,从理论上讲,我的脚本应该在关闭电源/重新启动时首先执行,因为它是最后启动的。对我来说,看起来不错,但systemd认为不是,并且在系统日志中我从未看到“ XXXz现在将关闭电源”。有人可以告诉我我在做错什么,还是可以解决这个问题?
谢谢
啊,如果这很重要:
~$ systemd --version
systemd 215
+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR
ps我要放弃,并用我自己的脚本替换到systemctl的重新启动/关闭/停止符号链接。