systemd unit file was created to control the start and stop of Postgres. It works just fine as expected if systemctl start or start command is used. But, if the machine is rebooted (systemctl reboot), then during its shutdown, the postgres process ALWAYS gets killed before ExecStop script is executed. By the time ExecStop script is executed, the process has been already killed and the script fails.
Here is the unit file:
[Unit] Description=PostgresStartStop service Requires=network.target After=network.target Before=shutdown.target reboot.target halt.target kexec.target DefaultDependencies=no [Service] Type=forking RemainAfterExit=yes ExecStart=/etc/rc.d/init.d/postgresStartStop start ExecStop=/etc/rc.d/init.d/postgresStartStop stop TimeoutSec=900 StandardOutput=inherit PIDFile=/var/lib/pgsql/data/postmaster.pid [Install] WantedBy=multi-user.target
I tried many different directives, but no avail.