Comment 17 for bug 2015126

Revision history for this message
Nick Rosbrook (enr0n) wrote :

Thanks, that is very helpful. I tested this for service units too, and got the same result:

$ systemd-run -u test-1.service -p RuntimeMaxSec=1m /usr/bin/bash -c 'while true; do sleep 1; done'
$ systemctl suspend # Waited a bit...

After resume:

$ systemctl status test-1.service
● test-1.service - /usr/bin/bash -c while true; do sleep 1; done
     Loaded: loaded (/run/systemd/transient/test-1.service; transient)
  Transient: yes
     Active: active (running) since Fri 2023-04-21 15:35:17 EDT; 2min 15s ago
      Until: Fri 2023-04-21 15:36:17 EDT; 1min 15s ago
   Main PID: 61473 (bash)
      Tasks: 2 (limit: 18896)
     Memory: 572.0K
        CPU: 138ms
     CGroup: /system.slice/test-1.service
             ├─61473 /usr/bin/bash -c "while true; do sleep 1; done"
             └─62087 sleep 1

Apr 21 15:35:17 six systemd[1]: Started test-1.service - /usr/bin/bash -c while true; do sleep 1; done.
$ systemctl status test-1.service
× test-1.service - /usr/bin/bash -c while true; do sleep 1; done
     Loaded: loaded (/run/systemd/transient/test-1.service; transient)
  Transient: yes
     Active: failed (Result: timeout) since Fri 2023-04-21 15:37:35 EDT; 1s ago
   Duration: 2min 18.274s
    Process: 61473 ExecStart=/usr/bin/bash -c while true; do sleep 1; done (code=killed, signal=TERM)
   Main PID: 61473 (code=killed, signal=TERM)
        CPU: 145ms

Apr 21 15:35:17 six systemd[1]: Started test-1.service - /usr/bin/bash -c while true; do sleep 1; done.
Apr 21 15:37:35 six systemd[1]: test-1.service: Service reached runtime time limit. Stopping.
Apr 21 15:37:35 six systemd[1]: test-1.service: Failed with result 'timeout'.

I am not sure if this is the intended behavior, so I will look into it further. The fact that the "Until: " line shows a time in the past makes me think this is not the intended behavior, and that timers should be restarted on suspend (which will immediately timeout if the time is in the past).