Prevent stand-by temporarily?

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
stefan_o
Level 2
Level 2
Posts: 55
Joined: Wed Jan 11, 2017 4:40 pm

Prevent stand-by temporarily?

Post by stefan_o »

Hello,

my PC is going into stand-by after 10 minutes, like it's supposed to do. Unfortunately it does so no matter what, even when downloading a large file or doing some computation. The simple trick is to just start a video/audio, that will prevent stand-by, but is quite inconvenient (you have to turn volume down etc.). When I remotely accessing my PC to start a computation this even more annoying.
Isn't there a simple tool called that prevents stand-by, that could be used like this:

nosleep
some-long-computation
killall nosleep

or maybe

nosleep command

That will run the the command and prevent sleep until exit. Does anything like this exist? All I could fine is "you change the setting and change it back". This is not what I want. A media player without root privileges can prevent stand-by, isn't there a tool that can do the same without the need of playing a video?

Best regards
Stefan
Last edited by LockBot on Tue Aug 08, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Prevent stand-by temporarily?

Post by rene »

On Xfce's "Power Manager Plugin" as present by default in the tray you can click and set 'Presentation Mode'. If you don't use the Xfce edition: relatively sure that Cinnamon/MATE will have something similar?

Also possible: systemd-inhibit <command>
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Prevent stand-by temporarily?

Post by vimes666 »

In Mate there is a panel applet called Inhibit Applet. Right-click an empty spot on your panel and click Add to panel
Image
edit: why is that image so big?!
If you think the issue is solved, edit your original post and add the word solved to the title.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Prevent stand-by temporarily?

Post by rene »

vimes666 wrote: Wed Feb 08, 2023 2:39 pm edit: why is that image so big?!
Are you on a 4K display? ;-)
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Prevent stand-by temporarily?

Post by vimes666 »

Are you on a 4K display?
No far from that.. the image is enlarged beyond its pixel size in the forum.. probably a pphbb thing.
If you think the issue is solved, edit your original post and add the word solved to the title.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Prevent stand-by temporarily?

Post by rene »

Let us not furthermore muddy the thread, but just in case you with that "enlarged beyond its pixel-size in the forum" in fact mean that: for me the (588x538) picture when saved is exactly as large when viewed on the forum as when viewed through an external viewer, and both exactly right in relation to the 1920x1080 of my desktop. If not for you I'd say you have some weird browser-sides scale factor configured somewhere...
stefan_o
Level 2
Level 2
Posts: 55
Joined: Wed Jan 11, 2017 4:40 pm

Re: Prevent stand-by temporarily?

Post by stefan_o »

I'm on Cinnamon and found a similar applet, but it's not exactly what I want:
  • I want to prevent stand-by not screensaver (screen should turn off)
  • I also want something that works from the console
Any ideas?
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Prevent stand-by temporarily?

Post by rene »

As mentioned, systemd-inhibit <command> (although I don't know if on your setup this keeps "the screensaver" active). man systemd-inhibit for more info.
stefan_o
Level 2
Level 2
Posts: 55
Joined: Wed Jan 11, 2017 4:40 pm

Re: Prevent stand-by temporarily?

Post by stefan_o »

rene wrote: Thu Feb 09, 2023 12:12 am As mentioned, systemd-inhibit <command> (although I don't know if on your setup this keeps "the screensaver" active). man systemd-inhibit for more info.
Two problems:
  • Doesn't work from SSH: Failed to inhibit: Access denied. Same user on desktop terminal no access problem
  • Doesn't work at all. If I start a process with systemd-inhibit system goes standby just like normal (and that process is listed as block by systemd-inhibit --list).
What am I doing wrong?
Last edited by stefan_o on Thu Feb 09, 2023 7:50 am, edited 1 time in total.
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Prevent stand-by temporarily?

Post by vimes666 »

There is another way to disable all sorts of sleep modes but it needs sudo.
To turn all forms of sleep off:

Code: Select all

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
and to turn them back on again:

Code: Select all

sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
Got it from here: https://blog.wijman.net/disable-suspend ... -in-linux/
If you think the issue is solved, edit your original post and add the word solved to the title.
stefan_o
Level 2
Level 2
Posts: 55
Joined: Wed Jan 11, 2017 4:40 pm

Re: Prevent stand-by temporarily?

Post by stefan_o »

I don't want enabling/disabling something, just blocking. Otherwise in case of a crash etc. it won't get enabled again
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Prevent stand-by temporarily?

Post by vimes666 »

Well, it is basically what you asked for:
nosleep
some-long-computation
killall nosleep
When you have a computer crash in the middle of the long-computation I think having the sleep modes turned off is the least of your worries anyway.
If you think the issue is solved, edit your original post and add the word solved to the title.
stefan_o
Level 2
Level 2
Posts: 55
Joined: Wed Jan 11, 2017 4:40 pm

Re: Prevent stand-by temporarily?

Post by stefan_o »

There is a subtle difference: With killall nosleep I terminate the process, which means at least after a reboot it will go back to sleep like normal if that's not done (nothing changed permanently). Also this should be possible without root access.
I also don't necessary mean a computer crash, but maybe a script issue that causes the second command not to be executed.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Prevent stand-by temporarily?

Post by rene »

The "from SSH" thing is a mere polkit issue which you could if you so wanted configure out -- but I confirm that it doesn't work at all on at least Mint 21.1 Xfce. The xfce4-power-manager still puts the system to sleep after whichever time is configured in the /xfce4-power-manager/inactivity-on-ac or -on-battery xfconf key also with a sleep inhibitor lock taken.

Pardon, dunno. Undoubtedly an issue again of battling freedesktop.org specifications and/or reality -- but a Google search finds only converse desires and I don't have the time to try and dig deeper.
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Prevent stand-by temporarily?

Post by vimes666 »

There is a subtle difference
Yes I agree. I have to think this over while having a good lunch because the only solution I can think of now is buying a cheap Chinese mouse that always keeps your system awake unless you switch it off..
If you think the issue is solved, edit your original post and add the word solved to the title.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Prevent stand-by temporarily?

Post by rene »

Or a regular mouse and an electric toothbrush...
stefan_o
Level 2
Level 2
Posts: 55
Joined: Wed Jan 11, 2017 4:40 pm

Re: Prevent stand-by temporarily?

Post by stefan_o »

rene wrote: Thu Feb 09, 2023 9:02 am Or a regular mouse and an electric toothbrush...
A bluetooth-controlled toothbrush...

Sometimes I access my PC via SSH (after using Wake-on-LAN), but it will go back sleep after 10 minutes. Sometimes this is what should happen (I just copy some small file), sometimes not, I start a computation, copy a large file over a slow network etc.

There should be a simple way to temporarily disable sleep. How do video players manage that? Or is there some detection in Cinnamon that there is audio or video playing and therefore stand-by is disabled?
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Prevent stand-by temporarily?

Post by vimes666 »

I am afraid there is no simple way, here is one using systemd.

Make a new systemd service by creating this file /etc/systemd/system/dontsleep.service as superuser/admin containing:

Code: Select all

[Unit]
Description=Inhibit suspend in case of [some] activity
Before=sleep.target

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c 'if ps -ae | grep "nosleep" > /dev/null; then exit 1; else exit 0; fi'

[Install]
RequiredBy=sleep.target
Enable it with:

Code: Select all

systemctl enable dontsleep.service
Create a script called /home/username/bin/nosleep and paste this in it:

Code: Select all

#!/usr/bin/bash
sleep infinity
Don't forget to make it executable

Code: Select all

chmod +x 
The systemd change may need a reboot, I am not sure.
Now, when you need sleep to be suspended just type

Code: Select all

nosleep &
in the terminal (& sends it to the background). Start your lengthy computing and afterwards type:

Code: Select all

killall nosleep
I you don't kill it, it won't survive a reboot, so things will return to normal.

Explanation: The systemd service you created will be run at the moment the system tries to go to sleep. If the Execstart command ends with return code other than 0, the system wil not go to sleep.
The command ps -ae | grep "nosleep" looks for a process named nosleep and if it finds it creates return code 1.

Warning: I didnt test this myself.

Found it here: https://unix.stackexchange.com/question ... -connected and that was copied from here: https://bbs.archlinux.org/viewtopic.php ... 0#p1380080

Edit: added else and redirection to /dev/null to suppress the output
If you think the issue is solved, edit your original post and add the word solved to the title.
billyswong
Level 8
Level 8
Posts: 2223
Joined: Wed Aug 14, 2019 1:02 am

Re: Prevent stand-by temporarily?

Post by billyswong »

Hi, my idea may not be what you want, but my first reaction is: why not create a silent audio or video file just for this purpose, then at least you don't have to turn down the volume for it.
Locked

Return to “Other topics”