这与其他主题的问题不同。我试图在我的 ubuntu 上创建一个服务,但它一直说这个服务不活动(死)。
我的操作系统:
我的服务(在 /etc/systemd/system/resume.service ):
[Unit]
Description=Run commands after resume from suspend
After=suspend.target
[Service]
ExecStart=/bin/sh /usr/local/bin/resume.sh
[Install]
WantedBy=suspend.target
我的 shell 脚本(在 /usr/local/bin/resume.sh ):
#!/bin/sh
# Workaround for XFCE bug re black screen on resume from suspend:
# if a user is logged into an X session via xfce, run 'xrandr --auto' to restore default display.
for id in $(loginctl list-sessions --no-legend | awk '{ print $1 }')
do
s="$(loginctl show-session "$id")"
if printf "$s" | grep -q 'Display=:0'
then
if printf "$s" | grep -q 'Desktop=xfce'
then
u="$(printf "$s" | grep 'Name=' | cut -d'=' -f2)"
DISPLAY=:0 su "$u" -c 'xrandr --auto'
exit
fi
fi
done
我试过这些命令但我无法激活该服务:
sudo systemctl enable resume.service
sudo systemctl start resume.service
在我运行 $sudo systemctl statusresume.service 之后:
○ resume.service - Run commands after resume from suspend
Loaded: loaded (/etc/systemd/system/resume.service; enabled; vendor pres>
Active: inactive (dead)
سپتامبر 15 22:59:00 linux systemd[1]: resume.service: Deactivated successfull>
سپتامبر 15 22:59:30 linux systemd[1]: Started Run commands after resume from >
سپتامبر 15 22:59:30 linux systemd[1]: resume.service: Deactivated successfull>
سپتامبر 15 23:00:57 linux systemd[1]: Started Run commands after resume from >
سپتامبر 15 23:00:57 linux systemd[1]: resume.service: Deactivated successfull>
سپتامبر 15 23:04:02 linux systemd[1]: Started Run commands after resume from >
سپتامبر 15 23:04:02 linux systemd[1]: resume.service: Deactivated successfull>
سپتامبر 15 23:10:36 linux systemd[1]: Starting Run commands after resume from>
سپتامبر 15 23:10:36 linux systemd[1]: resume.service: Deactivated successfull>
سپتامبر 15 23:10:36 linux systemd[1]: Started Run commands after resume from