I am having a postgresql database on SLES 12 SP3 system whose service is managed by systemd through the standard unit file. I wanted to automatically restart the service on failure, so create the directory /etc/systemd/system/postgresql.service.d/psql.conf with the following content.
This works well and I was happy. Now there is a requirement to setup High Availability system with a slave on standby in case the master fails. The team working on HA has requested to disable the Restart service flag when cluster is setup as they will monitor the service and fail over to the slave when postgresql stops. So I created a file /etc/systemd/system/potgresqlHA.service which is the copy of the existing unit file and HA team started using this file.
systemctl start/stop/restart/status postgresqlHA
Now there is a script which takes a backup of the database when requested. This script checks the status of postgresql before backup to make sure the service is running.
systemctl status postgresql
This works well when cluster is not setup. But when the cluster is setup the status of the service is stopped because postgresqlHA is the service which is started.
How to make the backup script work irrespective of the database service which is running? Is there something I can configure in one of the unit files to make this easier to manage?
I have same problem checking the status for some other services (apache2, tomcat etc) in other scripts.