Closed madbrain76 closed 1 year ago
Additional info :+1: Repeatedly typing "systemctl status autosuspend" shows the following . Note how the "since idle" time does not change .
root@server10g:/etc# systemctl status autosuspend
● autosuspend.service - A daemon to suspend your server in case of inactivity
Loaded: loaded (/lib/systemd/system/autosuspend.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-12-02 02:08:00 PST; 23h ago
Docs: https://autosuspend.readthedocs.io/en/latest/systemd_integration.html
Main PID: 463831 (autosuspend)
Tasks: 1 (limit: 38368)
Memory: 12.3M
CGroup: /system.slice/autosuspend.service
└─463831 /usr/bin/python3 /usr/bin/autosuspend -l /etc/autosuspend-logging.conf daemon
Dec 03 01:55:55 server10g autosuspend[463831]: 2022-12-03 01:55:55,640 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Dec 03 01:56:25 server10g autosuspend[463831]: 2022-12-03 01:56:25,667 - autosuspend.Processor - INFO - Starting new check iteration
Dec 03 01:56:25 server10g autosuspend[463831]: 2022-12-03 01:56:25,702 - autosuspend.Processor - INFO - System is idle since 2022-12-03 09:43:53.687480+00:00
Dec 03 01:56:25 server10g autosuspend[463831]: 2022-12-03 01:56:25,702 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Dec 03 01:56:55 server10g autosuspend[463831]: 2022-12-03 01:56:55,715 - autosuspend.Processor - INFO - Starting new check iteration
Dec 03 01:56:55 server10g autosuspend[463831]: 2022-12-03 01:56:55,750 - autosuspend.Processor - INFO - System is idle since 2022-12-03 09:43:53.687480+00:00
Dec 03 01:56:55 server10g autosuspend[463831]: 2022-12-03 01:56:55,750 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Dec 03 01:57:25 server10g autosuspend[463831]: 2022-12-03 01:57:25,781 - autosuspend.Processor - INFO - Starting new check iteration
Dec 03 01:57:25 server10g autosuspend[463831]: 2022-12-03 01:57:25,813 - autosuspend.Processor - INFO - System is idle since 2022-12-03 09:43:53.687480+00:00
Dec 03 01:57:25 server10g autosuspend[463831]: 2022-12-03 01:57:25,813 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
root@server10g:/etc# systemctl status autosuspend
● autosuspend.service - A daemon to suspend your server in case of inactivity
Loaded: loaded (/lib/systemd/system/autosuspend.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-12-02 02:08:00 PST; 23h ago
Docs: https://autosuspend.readthedocs.io/en/latest/systemd_integration.html
Main PID: 463831 (autosuspend)
Tasks: 1 (limit: 38368)
Memory: 12.3M
CGroup: /system.slice/autosuspend.service
└─463831 /usr/bin/python3 /usr/bin/autosuspend -l /etc/autosuspend-logging.conf daemon
Dec 03 01:55:55 server10g autosuspend[463831]: 2022-12-03 01:55:55,640 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Dec 03 01:56:25 server10g autosuspend[463831]: 2022-12-03 01:56:25,667 - autosuspend.Processor - INFO - Starting new check iteration
Dec 03 01:56:25 server10g autosuspend[463831]: 2022-12-03 01:56:25,702 - autosuspend.Processor - INFO - System is idle since 2022-12-03 09:43:53.687480+00:00
Dec 03 01:56:25 server10g autosuspend[463831]: 2022-12-03 01:56:25,702 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Dec 03 01:56:55 server10g autosuspend[463831]: 2022-12-03 01:56:55,715 - autosuspend.Processor - INFO - Starting new check iteration
Dec 03 01:56:55 server10g autosuspend[463831]: 2022-12-03 01:56:55,750 - autosuspend.Processor - INFO - System is idle since 2022-12-03 09:43:53.687480+00:00
Dec 03 01:56:55 server10g autosuspend[463831]: 2022-12-03 01:56:55,750 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Dec 03 01:57:25 server10g autosuspend[463831]: 2022-12-03 01:57:25,781 - autosuspend.Processor - INFO - Starting new check iteration
Dec 03 01:57:25 server10g autosuspend[463831]: 2022-12-03 01:57:25,813 - autosuspend.Processor - INFO - System is idle since 2022-12-03 09:43:53.687480+00:00
Dec 03 01:57:25 server10g autosuspend[463831]: 2022-12-03 01:57:25,813 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Right as I was typing this post in Firefox, autosuspend suspended the machine. I had to wake it up with WOL. Most annoying. I suppose I could write a custom checker that calls the "who" command to work around this problem, but it seems like this should is a basic use case that should work.
On a separate note, it's pretty confusing to show the "time since" in UTC format rather than the local time zone. Certainly makes it non-obvious when looking at "systemctl status" output.
Also,the message "Desired idle time of 900.0 s not reached yet" could be more detailed, for instance by displaying the "currently idle for" time, which I would have expected to be zero or close to it when I issued the systemctl status command, and would have made it obvious that it was incrementing without being reset by my user activity.
Can you run the following on a terminal to find out which users are reported on your system in a situation where the system shouldn't suspend:
python3 -c "import psutil; print(psutil.users())"
Here is some more output including what you requested :
root@server10g:/home/madbrain/Desktop# python3 -c "import psutil; print(psutil.users())"
[suser(name='madbrain', terminal=':1', host=':1', started=1670105600.0, pid=5650), suser(name='madbrain', terminal='pts/1', host='', started=1670105728.0, pid=7432)]
root@server10g:/home/madbrain/Desktop# systemctl status autosuspend
● autosuspend.service - A daemon to suspend your server in case of inactivity
Loaded: loaded (/lib/systemd/system/autosuspend.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-12-03 14:13:13 PST; 2min 34s ago
Docs: https://autosuspend.readthedocs.io/en/latest/systemd_integration.html
Main PID: 3784 (autosuspend)
Tasks: 1 (limit: 38368)
Memory: 14.5M
CGroup: /system.slice/autosuspend.service
└─3784 /usr/bin/python3 /usr/bin/autosuspend -l /etc/autosuspend-logging.conf daemon
Dec 03 14:14:13 server10g autosuspend[3784]: 2022-12-03 14:14:13,489 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Dec 03 14:14:43 server10g autosuspend[3784]: 2022-12-03 14:14:43,518 - autosuspend.Processor - INFO - Starting new check iteration
Dec 03 14:14:43 server10g autosuspend[3784]: 2022-12-03 14:14:43,555 - autosuspend.Processor - INFO - System is idle since 2022-12-03 22:13:14.083844+00:00
Dec 03 14:14:43 server10g autosuspend[3784]: 2022-12-03 14:14:43,556 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Dec 03 14:15:13 server10g autosuspend[3784]: 2022-12-03 14:15:13,586 - autosuspend.Processor - INFO - Starting new check iteration
Dec 03 14:15:13 server10g autosuspend[3784]: 2022-12-03 14:15:13,617 - autosuspend.Processor - INFO - System is idle since 2022-12-03 22:13:14.083844+00:00
Dec 03 14:15:13 server10g autosuspend[3784]: 2022-12-03 14:15:13,617 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
Dec 03 14:15:43 server10g autosuspend[3784]: 2022-12-03 14:15:43,646 - autosuspend.Processor - INFO - Starting new check iteration
Dec 03 14:15:43 server10g autosuspend[3784]: 2022-12-03 14:15:43,712 - autosuspend.Processor - INFO - System is idle since 2022-12-03 22:13:14.083844+00:00
Dec 03 14:15:43 server10g autosuspend[3784]: 2022-12-03 14:15:43,712 - autosuspend.Processor - INFO - Desired idle time of 900.0 s not reached yet.
root@server10g:/home/madbrain/Desktop# systemctl status autosuspend^C
root@server10g:/home/madbrain/Desktop# root@server10g:/home/madbrain/Desktop# python3 -c "import psutil; print(psutil.users())"
[suser(name='madbrain', terminal=':1', host=':1', started=1670105600.0, pid=5650), suser(name='madbrain', terminal='pts/1', host='', started=1670105728.0, pid=7432)]
^C
root@server10g:/home/madbrain/Desktop# python3 -c "import psutil; print(psutil.users())"
[suser(name='madbrain', terminal=':1', host=':1', started=1670105600.0, pid=5650), suser(name='madbrain', terminal='pts/1', host='', started=1670105728.0, pid=7432)]
root@server10g:/home/madbrain/Desktop# python3 -c "import psutil; print(psutil.users())"
[suser(name='madbrain', terminal=':1', host=':1', started=1670105600.0, pid=5650), suser(name='madbrain', terminal='pts/1', host='', started=1670105728.0, pid=7432)]
root@server10g:/home/madbrain/Desktop# python3 -c "import psutil; print(psutil.users())"
[suser(name='madbrain', terminal=':1', host=':1', started=1670105600.0, pid=5650), suser(name='madbrain', terminal='pts/1', host='', started=1670105728.0, pid=7432)]
root@server10g:/home/madbrain/Desktop# who
madbrain :1 2022-12-03 14:13 (:1)
madbrain pts/1 2022-12-03 14:14
root@server10g:/home/madbrain/Desktop# uptime
14:16:13 up 3 min, 2 users, load average: 0.33, 0.50, 0.24
Note that I do have 2 X sessions the main Gnome one, and another running specifically for VNC with TigerVNC .
root@server10g:/etc/systemd/system# cat vncserver\@.service
[Unit]
Description=Tiger VNC server
After=syslog.target network.target
[Service]
Type=forking
User=madbrain
PIDFile=/home/madbrain/.vnc/%H:590%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -geometry 3840x2160 -localhost no :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
root@server10g:/etc/systemd/system# ps -ef | grep -i vnc
madbrain 3964 1 0 14:13 ? 00:00:00 /usr/bin/perl /usr/bin/vncserver -geometry 3840x2160 -localhost no :2
madbrain 3965 3964 0 14:13 ? 00:00:00 /usr/bin/Xtigervnc :2 -localhost=0 -desktop server10g:2 (madbrain) -rfbport 5902 -PasswordFile /home/madbrain/.vnc/passwd -SecurityTypes VncAuth,TLSVnc -auth /home/madbrain/.Xauthority -geometry 3840x2160 -depth 24
madbrain 3966 3964 0 14:13 ? 00:00:00 /bin/sh /home/madbrain/.vnc/xstartup
root 7545 7434 0 14:18 pts/1 00:00:00 grep --color=auto -i vnc
root@server10g:/etc/systemd/system#
The logged in users are either on host ::1
or on empty string. Therefore, host = localhost
doesn't match and all users are ignored by the check. You have to updated the host
value to match either ::1
or empty string for the local users. I can add more debug logging later and update the documentation to make configuring this check easier.
I tried host = empty string. Unfortunately, the check this matches when I am logged in from VNC only, and not logged in locally :
root@server10g:/home/madbrain/Desktop# who
madbrain pts/0 2022-12-05 14:24
root@server10g:/home/madbrain/Desktop# python3 -c "import psutil; print(psutil.users())"
[suser(name='madbrain', terminal='pts/0', host='', started=1670279040.0, pid=1247707)]
root@server10g:/home/madbrain/Desktop# systemctl status autosuspend
? autosuspend.service - A daemon to suspend your server in case of inactivity
Loaded: loaded (/lib/systemd/system/autosuspend.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-12-05 14:24:16 PST; 2min 33s ago
Docs: https://autosuspend.readthedocs.io/en/latest/systemd_integration.html
Main PID: 1246773 (autosuspend)
Tasks: 1 (limit: 38368)
Memory: 11.9M
CGroup: /system.slice/autosuspend.service
??1246773 /usr/bin/python3 /usr/bin/autosuspend -l /etc/autosuspend-logging.conf daemon
Dec 05 14:25:16 server10g autosuspend[1246773]: 2022-12-05 14:25:16,311 - autosuspend.Processor - INFO - System is active. Resetting state
Dec 05 14:25:46 server10g autosuspend[1246773]: 2022-12-05 14:25:46,337 - autosuspend.Processor - INFO - Starting new check iteration
Dec 05 14:25:46 server10g autosuspend[1246773]: 2022-12-05 14:25:46,338 - autosuspend.Processor - INFO - Check LocalUsers matched. Reason: User madbrain is logged in on terminal pts/0 from since 167027904>
Dec 05 14:25:46 server10g autosuspend[1246773]: 2022-12-05 14:25:46,338 - autosuspend.Processor - INFO - System is active. Resetting state
Dec 05 14:26:16 server10g autosuspend[1246773]: 2022-12-05 14:26:16,368 - autosuspend.Processor - INFO - Starting new check iteration
Dec 05 14:26:16 server10g autosuspend[1246773]: 2022-12-05 14:26:16,369 - autosuspend.Processor - INFO - Check LocalUsers matched. Reason: User madbrain is logged in on terminal pts/0 from since 167027904>
Dec 05 14:26:16 server10g autosuspend[1246773]: 2022-12-05 14:26:16,369 - autosuspend.Processor - INFO - System is active. Resetting state
Dec 05 14:26:46 server10g autosuspend[1246773]: 2022-12-05 14:26:46,395 - autosuspend.Processor - INFO - Starting new check iteration
Dec 05 14:26:46 server10g autosuspend[1246773]: 2022-12-05 14:26:46,396 - autosuspend.Processor - INFO - Check LocalUsers matched. Reason: User madbrain is logged in on terminal pts/0 from since 167027904>
Dec 05 14:26:46 server10g autosuspend[1246773]: 2022-12-05 14:26:46,396 - autosuspend.Processor - INFO - System is active. Resetting state
root@server10g:/home/madbrain/Desktop#
How can I make the check match only if I'm logged in locally and not remotely through VNC ?
Edit: I made it host = :1
, and it worked. I feel this should not have been required, though.
If you want to match only an empty string with a regular expression, then you can use ^$
. If you just use the empty string itself as the value for the host
config option, any user will match because the empty string is contained in every other string.
I've improved the log message and added more documentation on the configuration of the users check for others trying to achieve the same things. What I am not going to change is using UTC for date-time objects. Local time zones with DST changes and so on are also confusing.
Please reopen if anything else remains.
I have autosuspend installed, including the default check for LocalUsers in /etc/autosuspend.conf, along with some other checks.
Unfortunately, when I'm logged in locally to Gnome, this check does not seem to work. The system goes to sleep while I'm using it, which is very inconvenient.
The other checks I'm using seem to work fine, and prevent autosuspend from suspending as I expected. This check used to work in the past in Ubuntu 20.04 but not anymore, unfortunately.