systemd自定义unit无法被sleep.target触发

启动讨论 grub/grub2/syslinux/grub4dos/Lilo
回复
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

systemd自定义unit无法被sleep.target触发

#1

帖子 vickycq » 2015-07-08 12:49

自定义一个custom.service,用于待机唤醒时执行一段脚本,结果无法触发。

采用的步骤:
/home/user/bin/test.sh

代码: 全选

#!/bin/bash
date >> /home/user/test.log
然后chmod +x /home/user/test.log

/etc/systemd/system/custom.service:

代码: 全选

[Unit]
Description=Local system resume actions
After=sleep.target

[Service]
Type=simple
ExecStart=/home/user/bin/test.sh

[Install]
WantedBy=sleep.target
之后systemctl enable custom.service,返回成功创建链接。

systemctl start custom.service,尝试启动,运行一次,成功。家目录下出现test.log,说明custom.service和test.sh没问题,能正确执行,journalctl -u custom.service中出现新的运行记录。

此时执行systemctl status custom.service 检查状态:

代码: 全选

● custom.service - Local system resume actions
   Loaded: loaded (/etc/systemd/system/custom.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
貌似一切正常。

但是,待机再恢复时,此服务没有运行。/home/user/下没出现test.log,journalctl -u custom.service中没出现新的运行记录。
尝试用不同的方法待机 (pm-suspend, xfce4-session-logout, systemctl start suspend.target)均无效。

:em20 :em20 :em20

请问哪里做错了?
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: systemd自定义unit无法被sleep.target触发

#2

帖子 vickycq » 2015-07-08 18:26

发现只有 systemctl suspend 才能触发 After=sleep.target 的服务,pm-utils不行。

但是问题又来了,上真货:

代码: 全选

ExecStart=/home/user/bin/test.sh
改为

代码: 全选

ExecStart=/sbin/hdparm -B 254 -S 0 /dev/sda 
就不能触发了,但可以手动运行。 :em20
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: systemd自定义unit无法被sleep.target触发

#3

帖子 poloshiao » 2015-07-08 18:54

如果你是使用 Grub 2 參閱
http://ubuntuforums.org/showthread.php? ... st13092756
/etc/grub.d/06_custom

補充
上面這一篇主題 Systemd experience
有許多 systemd 使用者經驗 分享
有興趣 可以參考看看
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: systemd自定义unit无法被sleep.target触发

#4

帖子 vickycq » 2015-07-08 19:45

好,谢谢。发现archwiki上有一篇专讲systemd suspend/resume hook,看看。

https://wiki.archlinux.org/index.php/Po ... vice_files
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
回复