Start stopped service because of dependency update
I have two systemd services: postgresql.service
and app.service
. postgresql.service
is distribution provided (ubuntu 15.10) and app.service
is written by myself.
Since app
needs postgresql
, the service looks like:
[Unit]
Description=Start App
Requires=postgresql.service
After=postgresql.service
[Install]
WantedBy=multi-user.target
[Service]
Restart=always
ExecStart=/path/to/app
Now today postgresql got updated. Of course it restarted the postgresql.service
after update automatically. But this killed my app.service
, because it requires postgresql
:
# systemctl status app
[...]
Apr 08 12:04:42 host systemd[1]: Stopping Start App...
Apr 08 12:04:42 host systemd[1]: Stopped Start App.
Apr 08 12:04:42
is the time where the update of postgresql
happened.
How can I change the app.service
so that it does not simply get killed when postgresql
restarts but (re)starts automatically then, too (only when it is enabled, of course)?
Or to ask it another way around: How can I configure app.service
that it always automatically starts after postgresql.service
when app.service
is enabled? So basically a systemctl start postgresql
first starts postgresql
and then automatically app
.
Solution 1:
I think systemd wants me to use Wants
instead of Requires
. From the manual:
Requires=
Configures requirement dependencies on other units. If this unit gets activated, the units listed here will be activated as well. If one of the other units gets deactivated or its activation fails, this unit will be deactivated. [...] Often, it is a better choice to use Wants= instead of Requires= in order to achieve a system that is more robust when dealing with failing services.
Now using Wants
and this seems to be like what I really want a robust system dealing with failing services. So I do.