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
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.
-
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 ofsystemctl enable b.service
after modified of the service file Commented Jul 27, 2023 at 8:19
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.