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?

TSG
  • 1,580
  • 6
  • 26
  • 42

1 Answers1

2

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.

ErikF
  • 3,942
  • 1
  • 10
  • 15