systemd / systemd

The systemd System and Service Manager
https://systemd.io
GNU General Public License v2.0
12.9k stars 3.7k forks source link

`systemctl daemon-reload` fire timers containing both `OnActiveSec=0` and `OnUnitActiveSec=…` #16186

Open tchernomax opened 4 years ago

tchernomax commented 4 years ago

systemd version the issue has been seen with

systemd 245 (245.6-6-arch)
+PAM +AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid

Used distribution

archlinux

Expected behaviour you didn't see

root@mde-oxalide # tail -n+1 test.*
==> test.service <==
[Service]
Type=oneshot
ExecStart=echo "supertest"

==> test.timer <==
[Timer]
OnActiveSec=0
OnUnitActiveSec=10h

root@mde-oxalide # systemctl list-timers test.timer
NEXT                         LEFT    LAST                         PASSED  UNIT       ACTIVATES
…                               …         …                              15s ago    test.timer test.service

root@mde-oxalide # systemctl daemon-reload
root@mde-oxalide # systemctl list-timers test.timer
NEXT                         LEFT    LAST                         PASSED UNIT       ACTIVATES
…                               …         …                              20s ago    test.timer test.service

daemon-reload do not fire the timer.

Unexpected behaviour you saw

root@mde-oxalide # systemctl list-timers test.timer
NEXT                         LEFT    LAST                         PASSED  UNIT       ACTIVATES
…                               …         …                              15s ago    test.timer test.service

root@mde-oxalide # systemctl daemon-reload
root@mde-oxalide # systemctl list-timers test.timer
NEXT                         LEFT    LAST                         PASSED UNIT       ACTIVATES
…                               …         …                              4s ago    test.timer test.service

root@mde-oxalide # journalctl -u test.service -e
juin 15 23:05:24 systemd[1]: Starting test.service...
juin 15 23:05:24 echo[114321]: supertest
juin 15 23:05:24 systemd[1]: test.service: Succeeded.
juin 15 23:05:24 systemd[1]: Finished test.service.
juin 15 23:05:54 systemd[1]: Starting test.service...
juin 15 23:05:54 echo[114400]: supertest
juin 15 23:05:54 systemd[1]: test.service: Succeeded.
juin 15 23:05:54 systemd[1]: Finished test.service.

daemon-reload did fire the test.timer.

Steps to reproduce the problem

max@mde-oxalide % cd ~/.config/systemd/user
max@mde-oxalide % cat > test.service <<END
[Service]
Type=oneshot
ExecStart=echo "supertest"
END
max@mde-oxalide % cat > test.timer <<END
[Timer]
OnActiveSec=0
OnUnitActiveSec=10h
END
max@mde-oxalide % systemctl --user daemon-reload
max@mde-oxalide % systemctl --user start test.timer
max@mde-oxalide % systemctl --user list-timer test.timer
max@mde-oxalide % systemctl --user daemon-reload
max@mde-oxalide % systemctl --user list-timer test.timer

You will see the test.timer has been fired by the second daemon-reload.

poettering commented 4 years ago

which systemd version is this?

tchernomax commented 4 years ago

@poettering sorry, I misformatted the description. It's edited now.

systemd 245 (245.6-6-arch)
+PAM +AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid
tchernomax commented 3 years ago

For information, this is still happening on version 247:

% systemctl --version
systemd 247 (247.2-1-arch)
+PAM +AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +ZSTD +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid
poettering commented 3 years ago

OnUnitActiveSec= is not supported really for Type=oneshot services, since these services never are active, they go from activating directly to inactive. There's an issue about that somewhere.