Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

systemd wakeup.target

Go to solution Solved by Nayr438,
12 hours ago, heimdali said:

apparently systemd has (not yet?) a wakeup.target which would allow to have stuff done when the computer is woken up from hibernation (or from suspend to RAM or both).

suspend.target
hibernate.target
hybrid-sleep.target

 

Try

[Unit]
Description=set /sys/power/image_size to zero
After=hibernate.target

[Service]
ExecStart=/bin/bash -c "echo 0 > /sys/power/image_size"

[Install]
WantedBy=hibernate.target

 

Hi,

 

apparently systemd has (not yet?) a wakeup.target which would allow to have stuff done when the computer is woken up from hibernation (or from suspend to RAM or both).

 

So how can I make systemd do automatically do stuff when the computer is woken up?

 

If I were to re-phrase the question in an obscure manner, I would ask if /sys/power/image_size will retain the value I may have set --- via a unit file which is wanted by multi-user.target or set otherwise --- because if it did that, then I wouldn't need to make the unit file wanted by whatever the equivalent of wakeup.target might be.

 

Link to post
Share on other sites
25 minutes ago, heimdali said:

Hi,

 

apparently systemd has (not yet?) a wakeup.target which would allow to have stuff done when the computer is woken up from hibernation (or from suspend to RAM or both).

 

So how can I make systemd do automatically do stuff when the computer is woken up?

 

If I were to re-phrase the question in an obscure manner, I would ask if /sys/power/image_size will retain the value I may have set --- via a unit file which is wanted by multi-user.target or set otherwise --- because if it did that, then I wouldn't need to make the unit file wanted by whatever the equivalent of wakeup.target might be.

 

I found an example unit file that seems to do what you need...

Quote

[Unit]
Description=Set the Advanced Power Management level of a chosen Hard Disk
After=basic.target
After=suspend.target
After=hibernate.target

[Service]
Type=oneshot
ExecStart=your program or script goes here

[Install]
WantedBy=basic.target
WantedBy=suspend.target
WantedBy=hibernate.target

https://bbs.archlinux.org/viewtopic.php?id=169791

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to post
Share on other sites

Thanks!  I've tried this file and started the service manually:

[Unit]
Description=set /sys/power/image_size to zero

[Service]
User=root
Type=oneshot
RemainAfterExit=no
ExecStart=echo 0 > /sys/power/image_size

[Install]
WantedBy=multi-user.target

Unfortunately, it does not change /sys/power/image_size to 0.  Mabye systemd isn't allowed to do such things?

 

It doesn't make any sense to me that something should be done after the computer has gone to sleep or switched off, as 'After hibernate.target' would indicate.  It's not gona do anyting when turned off.

 

Apparently there is a sleep.target which should be used for this, but I couldn't find any documentation about it.  See here: https://github.com/systemd/systemd/issues/6364

 

 

Link to post
Share on other sites
10 minutes ago, heimdali said:

It doesn't make any sense to me that something should be done after the computer has gone to sleep or switched off, as 'After hibernate.target' would indicate.  It's not gona do anyting when turned off.

I took it that to mean when the computer is next booted up after hibernate.target has been run. When hibernating it saves the contents of RAM to the HDD so on next boot it will know the last thing it did was run hibernation.

 

That said I'm really not sure that is the case.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to post
Share on other sites

Hm, well, it depends.  I'm trying to fix hibernating today because it quit working quite a while ago when I removed a disk that had been used to write RAM contents to.  It's finally working again and now I can save power.

 

In the process of trying to fix it, I found out that hibernated RAM isn't just loaded like magically.  It also requires, besides other configuration, to tell dracut to load the resume module.  Without it, the hibernated RAM won't be loaded.

 

Since it seems a good idea to set the image_size to 0 --- which is supposed to make the RAM image that gets written to disk as small as possible --- not only because it would making waking up faster but more importantly, because the swap partition I'm using is smaller than the RAM, I'm trying to get that automated.

 

And I don't know what these targets actually do.  A wakeup.target might make a lot more sense ...  In any case, as long my unit file can't set the image_size, it's not going to help anyway.

 

Oh, I think I found it: https://bbs.archlinux.org/viewtopic.php?id=195364

 

I'll see if that works on the next reboot.

 

Link to post
Share on other sites
12 hours ago, heimdali said:

apparently systemd has (not yet?) a wakeup.target which would allow to have stuff done when the computer is woken up from hibernation (or from suspend to RAM or both).

suspend.target
hibernate.target
hybrid-sleep.target

 

Try

[Unit]
Description=set /sys/power/image_size to zero
After=hibernate.target

[Service]
ExecStart=/bin/bash -c "echo 0 > /sys/power/image_size"

[Install]
WantedBy=hibernate.target

 

Link to post
Share on other sites

Thanks, I've marked that as solution because the unit file works when started manually, so it would do what it is intended:

 

[Unit]
Description=set /sys/power/image_size to zero

[Service]
ExecStart=/usr/bin/sh -c '/usr/bin/echo 0 > /sys/power/image_size'

[Install]
WantedBy=multi-user.target

 

I don't know about the target, though, I'm leaving it with the tmpfile entry for now and check if it works after the next reboot.  After resuming from hibernation, the image_size was zero.

 

Why is it necessary to use sh (or bash) to run echo?  That shouldn't be needed.

 

I'll put my note about fixing hibernation into another post here:

 

Link to post
Share on other sites
10 hours ago, heimdali said:

I don't know about the target, though, I'm leaving it with the tmpfile entry for now and check if it works after the next reboot.  After resuming from hibernation, the image_size was zero.

 

They Keyword is "After="

 

[Install]
WantedBy=hibernate.target

This Service File should be started when hibernate.target is run

 

[Unit]
Description=set /sys/power/image_size to zero
After=hibernate.target

But we shouldn't run it until hibernate.target has finished, which would be on resume aka your "wakeup.target". Without specifying "After=" it will just be run when "hibernate.target" is run.

 

[Install]
WantedBy=multi-user.target

This just says it should be run when we reach run level 2 (shell). It will only be executed on Startup.

 

10 hours ago, heimdali said:

Why is it necessary to use sh (or bash) to run echo?  That shouldn't be needed.

Because your running a shell command. The system has no idea what ">" means, but a shell does.

Link to post
Share on other sites

Nah I would want it to run before hibernating to keep the size of the image that gets written to disk as small as possible --- and afterwards to keep it that way (though it won't be necessary if it runs every time before hibernating anyway).

 

Good point with having to use a shell!  I didn't think of that at all.  If I need to run this, I think I'll just write a program in C to do the writing.  That'll be fun and probably have less overhead.

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×