我需要在系统(Fedora 33)进入睡眠模式之前和之后运行一些脚本。到目前为止,我尝试了两种不同的方法,但都失败了。
首先是将命令和脚本文件放置在这里:/lib/systemd/system-sleep/pre-suspend.sh
#!/bin/bash/
if [ "${1}" == "pre" ]; then
#
elif [ "${1}" == "post" ]; then
/path/to//scripts/script1
fi
systemd
第二种方法是使用所需的说明创建以下 2 个服务文件:
/etc/systemd/system/pre-sleep.service
/etc/systemd/system/post-sleep.service
样本:
/etc/systemd/system/pre-sleep.service
[Unit]
Description=Run before sleep
DefaultDependencies=no
Before=sleep.target
[Service]
Type=oneshot
ExecStart=/bin/bash /path/to//scripts/script1
TimeoutStartSec=0
[Install]
RequiredBy=sleep.target
然后,我重新加载了 systemd 管理器配置:
systemctl daemon-reload
如果我检查状态,它会返回已加载但不活动的状态:
systemctl status pre-sleep.service
● pre-sleep.service - Run before sleep
Loaded: loaded (/etc/systemd/system/pre-sleep.service; disabled; vendor preset: disabled)
Active: inactive (dead)
我缺少什么?