[systemd-devel] How to chain services driven by a timer?

Dan Nicholson dbn at endlessos.org
Wed Apr 10 19:29:10 UTC 2024


On Wed, Apr 10, 2024 at 1:21 PM Andrei Borzenkov <arvidjaar at gmail.com> wrote:
>
> On 10.04.2024 22:04, Brian Reichert wrote:
> > On Wed, Apr 10, 2024 at 09:06:09AM -0600, Dan Nicholson wrote:
> >> On Wed, Apr 10, 2024 at 8:50???AM Brian Reichert <reichert at numachi.com> wrote:
> >>>
> >>> My current service file:
> >>>
> >>>    [Unit]
> >>>    Description=Activities after logrotation
> >>>
> >>>    Requires=logrotate.service
> >>>    Wants=logrotate.service
> >>>    After=logrotate.service
> >>>
> >>>    [Service]
> >>>    #Type=oneshot
> >>>    Type=simple
> >>>
> >>>    ExecStart=/usr/bin/logger 'XXX post log rotation'
> >>>
> >>>    [Install]
> >>>    WantedBy=timers.target
> >>
> >> The critical part is WantedBy=logrotate.service. In other words, when
> >> logrotate.service is activated, you want it to also activate your
> >> service. Then After=logrotate.service above will ensure your service
> >> starts after it completes. The Requires and Wants above are
> >> conflicting. You only want one or the other, but I'd probably put it
> >> as Requires=logrotate.service. That way your unit won't start if
> >> logrotate.service fails.
> >
> > Thanks to you and <grawity at gmail.com> for your advice. I think I've
> > correctly incorporated your suggestions, but I still can't seem to get
> > things to work.
> >
> > Perhaps my method of testing is flawed.
> >
> > My current service:
> >
> >    [Unit]
> >    Description=Activities after logrotation
> >
> >    Requires=logrotate.service
> >
> >    [Service]
> >    Type=simple
> >
> >    ExecStart=/usr/bin/logger 'XXX post log rotation'
> >
> >    [Install]
> >    WantedBy=logrotate.service
> >
>
> Links in [Install] section are created by "systemctl enable".

Just to be complete, your unit won't be triggered until you see it in
"systemctl show -p Wants logrotate.service". With
WantedBy=logrotate.service, you'll also find a symlink to your service
in /etc/systemd/system/logrotate.service.wants/ once it's enabled.


More information about the systemd-devel mailing list