I've written a program that uses a Postgres database, and I wrote a systemd service file for it. Currently my service gets started on boot just fine, and it gets stopped when Postgres is stopped for upgrading (by
apt upgrade). However, when the upgrade is complete and Postgres is started again, my service is not automatically started.
Can I define some dependency to get my service started again automatically?
This is the status of my service after it was automatically stopped during the Postgres upgrade:
● tabill.service - My service Loaded: loaded (/srv/tabill/tabill.service; enabled; vendor preset: enabled) Active: inactive (dead) since Tue 2017-07-04 00:29:24 EEST; 44min ago Main PID: 1048 (code=killed, signal=TERM)
Note that I can manually start the service again just fine.
Here's my service file:
[Unit] Description=My service Wants=nginx.service Requires=postgresql.service After=postgresql.service [Service] Type=simple ExecStart=/srv/tabill/app/serve Restart=always TimeoutSec=60 [Install] WantedBy=multi-user.target
I've tried adding
BindsTo=postgresql.service, and then manually stopping and starting Postgres, but neither helped.
Of course I could remove the
Requires, but stopping both services together is preferable, if only they would both start back up.
PartOf=sounds like the right solution. Did you try it with
Requires=removed, that didn't help. I think the problem is that
PartOf=links "stopping and restarting of units", but Postgres isn't restarted during an upgrade. It's stopped, upgraded, and started.
systemctl restart postgresql, systemd remembers to restart its dependent services again. It seems like apt, for some reason, does combination of