DEV Community

Ayman Bagabas
Ayman Bagabas

Posted on • Originally published at aymanbagabas.com on

Suspend then hibernate in systemd 239

In systemd 239, they have added a new service that handles suspending then hibernating after a given amount of time. This is easier than using external scripts since it comes built-in with this version of systemd. You can check systemd version with systemctl --version.

First, you have to define the delay time before the system wakes up and go into hibernation and that should be defined in /etc/systemd/sleep.conf

[Sleep]
HibernateDelaySec=15min

Enter fullscreen mode Exit fullscreen mode

Here, what we care about is the last line HibernateDelaySec where you can define delayed time. As you see, I have it set to 15 minutes after suspending.

Lastly, we need to override the default suspend to execute suspend-then-hibernate instead of regular suspend:

ln -s /usr/lib/systemd/system/systemd-suspend-then-hibernate.service /etc/systemd/system/systemd-suspend.service

Enter fullscreen mode Exit fullscreen mode

This will make systemd executes suspend-then-hibernate instead of suspend every time suspend is invoked.

Reference

systemd-sleep.conf

systemd-suspend-then-hibernate.service

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay