Suspend on idle not working again after wake-up for sheduled task

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read how to get help
Post Reply
Zener131
Level 1
Level 1
Posts: 5
Joined: Wed Dec 20, 2017 11:39 am

Suspend on idle not working again after wake-up for sheduled task

Post by Zener131 » Wed Dec 20, 2017 12:26 pm

Hello.

Here is the problem I'm searching a solution or workaround for.

Context:
1) The PC is a recent workstation running Mint v.18.1. I configured the power management to activate a screensaver then suspend after 1h more idle. In addition I changed the suspend type to hibernate. This works very fine: after such delay idle, the PC does hibernate then simply moving the mouse triggers a wake-up: Grub menu then back to login screen...
=> So there is no issue with power management in such a normal use case.
2) I used Cron and Rtcwake to schedule a (nightly backup) job and it works fine too: at wanted time the PC wakes then the scheduled task is executed. After it should sleep again...

Problem:
After the scheduled task (several hours later) I can find the PC with the screensaver still active instead of hibernating.
If in that state I simply move the mouse and do nothing else, the login screen appears then after the expected delay, the PC hibernates again.

So actually the suspend on idle appears not to be rearmed after a cycle, unless some real user activity occurs. What means that it works when the PC is awaken manually, not when the RTC alarm does it.

Ideas:
There is no big job remaining after the scheduled task that could keep the PC active. The proof is that just moving the mouse makes it sleep again after the idle delay.

I tried to fake some user activity using xdotool to move the mouse from the scheduled task, with no success. Since this is a cron job (root account), it has no GUI environment, then I'm not sure xdotool actually does anything when run this way. And if it does, I'm not sure it has an effect on idle detection...

A solution in the form of explicitly requiring a suspend at the end of the scheduled task (or something Cron-based), regardless of other potential tasks, is not acceptable: functionally the PC must go to sleep just when it is idle, not on some kind of arbitrary order,
So a correct workaround would be to reset the idle counter to rearm the standard power management system. How to do that from a Cron-based task ?

Then of course, the best solution would be that the cycle is automatically restarted whenever the PC wakes-up, even with no user present, no ? Any idea about the reason why it is not ?

Thanks for ideas.
Best regards.

Zener131
Level 1
Level 1
Posts: 5
Joined: Wed Dec 20, 2017 11:39 am

Re: Suspend on idle not working again after wake-up for sheduled task

Post by Zener131 » Wed Jan 03, 2018 6:32 am

I could not find any way to make the screensaver redo its cycle after an automated wake-up, nor any acceptable workaround, then I opened this ticket:
https://github.com/linuxmint/cinnamon-s ... issues/260

Zener131
Level 1
Level 1
Posts: 5
Joined: Wed Dec 20, 2017 11:39 am

Re: Suspend on idle not working again after wake-up for sheduled task

Post by Zener131 » Sun Feb 04, 2018 5:10 am

Hello.
Some news...

Finally I could get a result this way: using xdotool to move the mouse in the hook for post-hibernate (so at wake-up).

It is necessary to add some context this way:

# On wake-up, fake some neutral User activity so that the idle counter is reset and after,
# hibernation can be triggered again. This requires access to a regular User's session:
export DISPLAY=:0 ;
export XAUTHORITY=~/.Xauthority ;
cp /home/<some real user>/.Xauthority $XAUTHORITY ;
xdotool mousemove_relative -- 131 131 ;

This appears to mean that it will not work if there is no real user currently having a X session open.
=> Does somebody know which "pseudo-user" owns the session when nobody is loged in ? the equivalent of "DEFAULT USER" under Windows...

Then doing that with xdotool appears to work... sometimes: the station goes back to hibernation after the nightly job.
But not always !

The alternative, most of times, is to find the station still active with the screensaver but also in a strange state where you get asked a password for anything: mounting a USB stick, unmounting it, trying to reboot or...
...to sleep or hibernate, of course !
It looks like the session was somewhat corrupted when used by root (probably a file set with root-only permissions, but which one ?). At this time the only thing to do is to logoff/login again.

Curiously this is only for the station using Cinnamon. The one using XFCE sleeps again properly (but for this one I don't use hibernation).

Other experiment:

To fix that potential permission affair I also tried to make the wake-up hook do the xdotool thing and do it on the account of the regular User:

export DISPLAY=:0 ;
export XAUTHORITY=/home/<real user>/.Xauthority ;
su <real user> -c "xdotool mousemove_relative -- 131 131" >> /tmp/test-su-xdotool.log 2>&1 ;

With the same desperating result.

Conclusion:

I don't think that anything clean and reliable can be done this way to workaround the bug, X does not like root...

The next try will be to attempt to inject some fake User activity at lower level (than X) using the pseudo-device /dev/uinput...
But I'm getting a bit disgusted :-/

Actually the problem is not related to the screensaver (that only masks the screen) but rather to the part of the Gnome Session Manager that handles the idle state and should simply restart counting at wake-up.
=> Does somebody know which code is involved ?

Thanks for any help.
Best regards.

Zener131
Level 1
Level 1
Posts: 5
Joined: Wed Dec 20, 2017 11:39 am

Re: Suspend on idle not working again after wake-up for sheduled task

Post by Zener131 » Fri Feb 23, 2018 2:20 pm

Hello.

I feel a little alone guys, nobody has both nightly backups and a power saving policy ? :P

But I think I found a credible root cause, then a fix may be available soon:
https://bugzilla.gnome.org/show_bug.cgi?id=793766

Best regards.

Post Reply

Return to “Other topics”