[systemd-devel] Can service of timers.target having After=multi-user.target create a loop?

Andrei Borzenkov arvidjaar at gmail.com
Sun Jul 12 14:13:59 UTC 2020


12.07.2020 16:21, Amish пишет:
> Hello,
> 
> This is a question out of curiosity and not currently any problem.
> 
> I have a timer file like this:
> 
> [Unit]
> Description=Foo
> After=multi-user.target
> 
> [Timer]
> OnCalendar=*:0/5
> Persistent=false
> 
> [Install]
> WantedBy=timers.target
> 
> And corresponding service file like this:
> 
> [Unit]
> Description=Foo
> 
> [Service]
> Type=oneshot
> ExecStart=-/usr/bin/checkservices
> 
> /usr/bin/checkservices checks if some important services are running and
> sends alert if not.
> 
> Above timer is supposed to run every five minutes. But not while system
> is still booting.
> 
> If I do not put After=multi-user.target then timer gets triggered even
> before those services have begun (while booting) and sends false alarm.
> 
> With above settings, I do not face that issue.
> 
> But just out of curiosity I am eager to know if this or something
> similar can cause loop and hang system forever from booting?
> 
> Because AFAIK timers.target runs before multi-user.target. But here
> something inside timers.target waits for multi-user.target.
> 
> So how does systemd resolve this loop?
> 

There is no loop. There is no transitive dependency between timer unit
and service unit. Timer unit gets started early and enqueues start job
for service unit; this start job waits for multi-user.target according
to After dependency. Mulitple invocation of timer will try enqueue start
job again which will simply be merged with existing pending request.


More information about the systemd-devel mailing list