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

Andrei Borzenkov arvidjaar at gmail.com
Wed Apr 10 19:21:32 UTC 2024


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".

> I tried, variously, to no apparent effect:
> 
>    systemctl restart logrotate.timer
> 
>    systemctl start logrotate.service
> 
> How should I be testing this?
> 



More information about the systemd-devel mailing list