Skip to main content
Clarification
Source Link
ReedGhost
  • 543
  • 3
  • 7

A bit difficult to answer given that the actual unit files in question are omitted, but you seem to misunderstand what Before=/After= are meant to do;

The implication when using Before/After in unit files is that given a prioritization decision between two or more units, the Before/After conditions will determine the order in which actions are taken on the units.

In your case you have two services in which one service A.service is dependent on a second service B.service, however you have not specified that these two services have a dependency relationship, only the order in which they would execute if they had one.

With this being the case, it sounds like you want to also set Requisite=, Requires= or Wants= on A.service in reference to B.service such that A.Service looks as follows:

[Unit]
Requires=B.service
After=B.service

With this configuration, activation of the service A.service will necessitate activation of B.service and the After= directive will ensure that A.service will not begin execution of its ExecStart= directive(s) until after B.service has completed execution of its own ExecStart= directive(s)

Requires= and Wants= will not only check if listed units are already active, but will also activate them if they were not already

Requisite= will only check if a unit is running, if it is not, the unit it is defined in will immediately fail

Before= and After= only specify the order of activation for units when called simultaneously. Which is why you can have A.service activate before B.service in your current configuration, since they aren't currently being simultaneously activated, the ordering dependency is not applied.

It would be good coverage to also set Before=A.service on B.service

TLDR: You need to define both After= as well as Requires=. You "need" Requires= to ensure that if B.service is not already running, it will be activated at the same time as when A.service is ran. You need After= to specify that when A.service and B.service have a simultaneous activation, that A.service will delay its execution until after B.service has executed.

A bit difficult to answer given that the actual unit files in question are omitted, but you seem to misunderstand what Before=/After= are meant to do;

The implication when using Before/After in unit files is that given a prioritization decision between two or more units, the Before/After conditions will determine the order in which actions are taken on the units.

In your case you have two services in which one service A.service is dependent on a second service B.service, however you have not specified that these two services have a dependency relationship, only the order in which they would execute if they had one.

With this being the case, it sounds like you want to also set Requisite=, Requires= or Wants= on A.service in reference to B.service such that A.Service looks as follows:

[Unit]
Requires=B.service
After=B.service

With this configuration, activation of the service A.service will necessitate activation of B.service and the After= directive will ensure that A.service will not begin execution of its ExecStart= directive(s) until after B.service has completed execution of its own ExecStart= directive(s)

Requires= and Wants= will not only check if listed units are already active, but will also activate them if they were not already

Requisite= will only check if a unit is running, if it is not, the unit it is defined in will immediately fail

Before= and After= only specify the order of activation for units when called simultaneously. Which is why you can have A.service activate before B.service in your current configuration, since they aren't currently being simultaneously activated, the ordering dependency is not applied.

It would be good coverage to also set Before=A.service on B.service

A bit difficult to answer given that the actual unit files in question are omitted, but you seem to misunderstand what Before=/After= are meant to do;

The implication when using Before/After in unit files is that given a prioritization decision between two or more units, the Before/After conditions will determine the order in which actions are taken on the units.

In your case you have two services in which one service A.service is dependent on a second service B.service, however you have not specified that these two services have a dependency relationship, only the order in which they would execute if they had one.

With this being the case, it sounds like you want to also set Requisite=, Requires= or Wants= on A.service in reference to B.service such that A.Service looks as follows:

[Unit]
Requires=B.service
After=B.service

With this configuration, activation of the service A.service will necessitate activation of B.service and the After= directive will ensure that A.service will not begin execution of its ExecStart= directive(s) until after B.service has completed execution of its own ExecStart= directive(s)

Requires= and Wants= will not only check if listed units are already active, but will also activate them if they were not already

Requisite= will only check if a unit is running, if it is not, the unit it is defined in will immediately fail

Before= and After= only specify the order of activation for units when called simultaneously. Which is why you can have A.service activate before B.service in your current configuration, since they aren't currently being simultaneously activated, the ordering dependency is not applied.

It would be good coverage to also set Before=A.service on B.service

TLDR: You need to define both After= as well as Requires=. You "need" Requires= to ensure that if B.service is not already running, it will be activated at the same time as when A.service is ran. You need After= to specify that when A.service and B.service have a simultaneous activation, that A.service will delay its execution until after B.service has executed.

Source Link
ReedGhost
  • 543
  • 3
  • 7

A bit difficult to answer given that the actual unit files in question are omitted, but you seem to misunderstand what Before=/After= are meant to do;

The implication when using Before/After in unit files is that given a prioritization decision between two or more units, the Before/After conditions will determine the order in which actions are taken on the units.

In your case you have two services in which one service A.service is dependent on a second service B.service, however you have not specified that these two services have a dependency relationship, only the order in which they would execute if they had one.

With this being the case, it sounds like you want to also set Requisite=, Requires= or Wants= on A.service in reference to B.service such that A.Service looks as follows:

[Unit]
Requires=B.service
After=B.service

With this configuration, activation of the service A.service will necessitate activation of B.service and the After= directive will ensure that A.service will not begin execution of its ExecStart= directive(s) until after B.service has completed execution of its own ExecStart= directive(s)

Requires= and Wants= will not only check if listed units are already active, but will also activate them if they were not already

Requisite= will only check if a unit is running, if it is not, the unit it is defined in will immediately fail

Before= and After= only specify the order of activation for units when called simultaneously. Which is why you can have A.service activate before B.service in your current configuration, since they aren't currently being simultaneously activated, the ordering dependency is not applied.

It would be good coverage to also set Before=A.service on B.service