0

In my system I have b.service activated by b.timer. I want another service (a.service) that start before b.service. I cant change b.service or b.timer because are not mine. I've putte Before=b.service in a.service but the timer start b.service without starting a.service.

2 Answers 2

0

You can mark a.service as RequiredBy b.service.

Make a.service look like:

[Unit]
Before=b.service

[Service]
Type=exec
ExecStart=...

[Install]
RequiredBy=b.service

And then:

systemctl enable a.service

Now whenever b.service starts -- either via a timer or via systemctl start -- your new a.service will start first.

1
  • Thanks, that worked for me, i've tryed this solution before but it didn't work because i run the command systemctl daemon-reload instead of systemctl enable b.service after modified of the service file Commented Jul 27, 2023 at 8:19
0

The Before directive is only used during startup. It's only used for to determine the orders of the services.

In order to achieve what you need, add the following section to to your a.service:

[Install]
WantedBy=b.service

Then run:

systemctl enable a.service

This will ensure that when b.service is supposed to get started, a.service will be started before.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .