1

I am creating a service file for myprog.service, and I want to ensure it starts only after PostgreSQL has started.

However, if the user does not have PostgreSQL installed, then I want it to ignore that requirement and let myprog.service start anyways.

Can SystemD service files have dependencies on an optional (potentially non-existent) service?

1

Yes. As described in the systemd.unit(5) man page, use a Wants= and After= directive, as such:

example.service:

[Unit]
Description=Example service
Wants=postgresql.service
After=postgresql.service

Wants= indicates that the dependency is optional (as opposed to Requires or Requisite), and After= places it before this unit.

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.