I have a web application that is started by systemd
. It uses Postgresql as database, so it rely on it. Here is the unit file of my web application (I have remove the un-relevant/sensitive parts):
[Unit]
Description=xxxx
Requires=postgresql.service
After=network.target postgresql.service
[Service]
Type=simple
PermissionsStartOnly=true
SyslogIdentifier=xx-service
User=yyy
Group=zzz
ExecStart=/opt/.../xx
WorkingDirectory=/opt/xx
StandardOutput=journal+console
[Install]
WantedBy=multi-user.target
Host os is Ubuntu server 16.04.
I recently had an event where the web application was not running in the morning when I returned to work. After checking the logs, I discovered the service was stopped by systemd
because postgresql
had an update. Apparently aptitude
stopped postgresql
before the upgrade and restarted it rigth after the update. When I logged into the machine it was running.
But systemd
decided to stop my web application before stopping postgresql
, which is nice, but didn't restart the web app it after it restarted postgresql
.
How to instruct systemd
to restart the appliation after postgresql
service is restarted ?
Best Answer
I think you're looking for
PartOf
:Add
PartOf=postgresql.service
to the unit file of your web application, reloadsystemctl-daemon
and test.And to address the situation where your web application will have to start automatically after
postgresql.service
gets started, you could combinePartOf
withWants
, but inpostgresql
's unit file: