1

I'm trying to implement the delayed hibernation unit. I'm on arch/antergos.

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

systemd-analyze verify ...hibernate.service responds with an empty output.

I copied the unit file straight from the arch wiki and changed SLEEPLENGTH to 1 hour. How can I debug the issue? How can I make systemd issue more descriptive error messages?

suspend-to-hibernate.service

[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
  • Where is suspend-to-hibernate.service, and have you run systemctl daemon-reload after creating/modifying that file? – muru Apr 2 '18 at 4:03
  • suspend-to-hibernate.service sits in a sub-folder of my home folder, from where I also run the commands. I was never able to enable it, so I haven't run systemctl daemon-reload – pandita Apr 2 '18 at 5:35
  • 1
    As given in the Arch wiki page, the file should be in /etc/systemd/system/, and you have to daemon-reload before enabling it (daemon-reload gets systemd to recheck its directories for new or modified units, and only after than can you enable a new a service). – muru Apr 2 '18 at 5:38
  • Thanks heaps, this worked. If you sum this up in an answer I'll accept it. I got to say that I find the error message super confusing.... it made me think that there is a syntax error in the file or something like this... – pandita Apr 2 '18 at 8:41
2

As given in the Arch wiki page, the file should be in /etc/systemd/system/. There are several directories where systemd looks for unit files, and /etc/systemd/system/ is where a system administrator should place their service files. See man systemd.unit.

After creating or a modifying a file in these directories, you have to run systemctl daemon-reload, which gets systemd to recheck its directories for new or modified units. Only then can you enable or start a new service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.