My desktop computer, which runs GNOME, is configured to suspend on 20 minutes of inactivity (desired behavior). However, at various time I tend to remote to it from my laptop for development.
What’s the best approach to disable suspend of computer while SSH sessions are active (i.e., not idle)?
Seeing as nobody knows, then i will theory-ize , then you going to have ‘tickle’ gnome in some, more than likekly with a dbus message, to tell the gnome suspend function that ‘something is happening’’.
Disable suspend and hibernation
For systems which should never attempt any type of suspension, these targets can be disabled at the systemd level with the following:
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
To re-enable hibernate and suspend use the following command:
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
so , maybe something on a cronjob, which checks if users are still logged in, you may need ignore users logged into actually local tty’s and local xsessons.
in the system profile, that runs when all users logging in do.
last | grep "still logged in"
if [[ $? -eq 1 ]]
then
#To re-enable hibernate and suspend use the following command:
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
fi
which renables suspend service , when all users are logged out , again don’t forget to exclude local users on tty’s :-).
have fun.
This post was brought you by the ACME instant shell scripting service. Thank you for using ACME.
[b0ef@nixos:~]$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
[sudo] password for b0ef:
Failed to mask unit: File /etc/systemd/system/sleep.target already exists and is a symlink to /nix/store/9gzw98jc64qkwd17a6qqm63w25zysi57-systemd-253.6/example/systemd/system/sleep.target.