1

I have a series of mutually exclusive systemd services that are started and stopped by users as needed. Each of the services requires exclusive use of some hardware, so many of the services conflict with each other. (But not all services conflict with all other services)

To manage this I've used Conflicts=, which almost works perfectly, however the ExecStart of the starting service seems to run while the ExecStop script of the conflicting service is still running running, which causes the starting service to fail as the hardware resources are not yet available.

If I have the start scripts sleep for some safe amount of time, like 30 seconds, they function perfectly, but I'd much rather them start as soon as the conflicting service stops.

After= doesn't seem to work as the services can be stopped and started repeatedly, in arbitrary order, and After= causes a cyclical dependency.

Is there a way to do this in systemd without resorting to checking if a conflict is running inside the ExecStart scripts?

0

My guess is that your ExecStop= command is issuing an async operation, like sending a termination signal to a process, and then exiting immediately before the process has finished shutting down.

Make sure your ExecStop= command is a synchronous operation that does not exit until the service is completely shutdown.

  • That was how I expected it to work, so the ExecStop command uses a do while to wait until the service is stopped before it returns, and I have confirmed that the the units don't get marked as stopped until after the ExecStop script finishes freeing up the resources. The ExecStart is definitely running while the ExecStops are still waiting, and the service failed to start messages appear in the journal before the service stopped messages. – millow Aug 30 '18 at 16:31
  • I would search the systemd issue tracker for bug reports about this and if there is not already one, file a new one. (Assuming you are using the latest version of systemd or nearly-so). Your experience seems to be in conflict with documentation for ExecStop=, which I based my answer on. – Mark Stosberg Sep 4 '18 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.