I’d like to automate logging out and suspending the PC on Ubuntu 24 with lightdm.
I tried this:
SESSION_ID=$(loginctl | grep $(whoami) | awk '{print $1}')
loginctl terminate-session "$SESSION_ID"
systemctl suspend
This logs me out (fairly brutally, TBH, running apps complain they quit unexpectedly so maybe not the cleanest) but does not suspend the PC.
If I change the order (suspend first, then logout) then obviously the machine gets suspended and… that’s it. Once I resume, I’m still logged in.
What’a a proper way of doing this? Ideally I’d like a proper logout, too, not “kill everything and run”.