0

I want to make nginx service dependent on a service I wrote, say abc.service. By dependent, I mean:

  • nginx service should stop when I stop abc
  • nginx service should start when I start abc

A typical way would be to modify /lib/systemd/system/nginx.service and add Wants abc directive. However, I don't want to modify nginx.service file - as this is shipped with nginx package.

Any other way to do this?

Jenny D
  • 27,358
  • 21
  • 74
  • 110
constantine1
  • 103
  • 3
  • Create a [drop-in file](https://serverfault.com/questions/824389/varnish-daemon-not-listening-on-configured-port/824399?r=SearchResults#824399). – Gerald Schneider Dec 11 '18 at 07:40

1 Answers1

5

Never modify a unit delivered in /lib/systemd/system, those units are shipped by packages owners, and could be overridden at package upgrade.

option 1 : create a copy of the unit in /etc/systemd/system and modify it. then systemctl daemon-reload and you are done. /etc/systemd/system is the place for your local units => https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Unit%20File%20Load%20Path

option 2 : create a drop-in file as suggested by Gerald Schneider.

root@host# mkdir /etc/systemd/system/nginx.service.d root@host# cat /etc/systemd/system/nginx.service.d/mydeps.conf [Unit] Wants=abc.service

you may also need a directive in abc.service to make nginx stop when abc stops.

Chaoxiang N
  • 1,218
  • 4
  • 10