mat*_*igo 11
您可以通过创建服务文件,然后重新加载systemd
. 就是这样:
打开终端(如果尚未打开)
确保要在关机时运行的脚本可执行:
chmod +x ~/scripts/pre-shutdown.sh
Run Code Online (Sandbox Code Playgroud)
/etc/systemd/system
为关闭服务创建一个文件。为了这个例子,我将我的文件称为nighty-night.service
.
将以下行添加到.service
文件中,并根据需要进行修改:
[Unit]
Description=Pre-Shutdown Processes
DefaultDependencies=no
Before=shutdown.target
# This works because it is installed in the target and will be
# executed before the target state is entered
# Also consider kexec.target
[Service]
Type=oneshot
ExecStart=/home/smeterlink/scripts/pre-shutdown.sh # your path and filename
[Install]
WantedBy=halt.target reboot.target shutdown.target
Run Code Online (Sandbox Code Playgroud)
重新加载 systemd,启用该服务,使其在引导时启动,然后启动它:
sudo systemctl daemon-reload
sudo systemctl enable nighty-night.service
sudo systemctl start nighty-night.service
Run Code Online (Sandbox Code Playgroud)
您可以查看它是否运行正常systemctl status nighty-night
这里的所有都是它的。
归档时间: |
|
查看次数: |
11591 次 |
最近记录: |