systemd 无效参数 - 调试延迟休眠服务文件

systemd 无效参数 - 调试延迟休眠服务文件

我正在尝试实施延迟冬眠单位。我在 arch/antergos。

>>> systemctl enable suspend-to-hibernate.service
Failed to enable unit ...to-hibernate.service: Invalid argument

systemd-analyze verify ...hibernate.service以空输出响应。

我直接从 arch wiki 复制了单元文件,并将 SLEEPLENGTH 更改为 1 小时。我该如何调试该问题?如何让 systemd 发出更具描述性的错误消息?

挂起至休眠服务

[Unit]
Description=Delayed hibernation trigger
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279
Documentation=https://wiki.archlinux.org/index.php/Power_management
Conflicts=hibernate.target hybrid-sleep.target
Before=sleep.target
StopWhenUnneeded=true

[Service]
Type=oneshot
RemainAfterExit=yes
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"
Environment="SLEEPLENGTH=+1hour"
ExecStart=-/usr/bin/sh -c 'echo -n "alarm set for "; date +%%s -d$SLEEPLENGTH | tee $WAKEALARM'
ExecStop=-/usr/bin/sh -c '\
  alarm=$(cat $WAKEALARM); \
  now=$(date +%%s); \
  if [ -z "$alarm" ] || [ "$now" -ge "$alarm" ]; then \
     echo "hibernate triggered"; \
     systemctl hibernate; \
  else \
     echo "normal wakeup"; \
  fi; \
  echo 0 > $WAKEALARM; \
'

[Install]
WantedBy=sleep.target

答案1

正如 Arch wiki 页面中给出的,该文件应该是/etc/systemd/system/. systemd 有几个目录可以查找单元文件,/etc/systemd/system/系统管理员也应该在其中放置其服务文件。看man systemd.unit

在这些目录中创建或修改文件后,您必须运行systemctl daemon-reload,这会让 systemd 重新检查其目录中是否有新的或修改的单元。只有这样您才能启用或启动新服务。

相关内容