Custom service for PostgreSQL can't be stopped

Hi everybody,

I’m using PostgreSQL for a custom app I’m working on and to solve some configuration issues I wrote a bash script that is executed as serviceConfig.ExecStart = ... and the last line of the bash script is postgres ....

I know this is not the best practice and I should rather execute the script in<name>.preStart but I’d prefer to keep it during the development like this.

It works well except for stopping - when I try to stop the systemd service, it takes 2 min (default timeout time) and then logs show Killing process 7538 (postgres) with signal SIGKILL..

It’s pretty clear to me that stopping the systemd service means sending a stop SIGTERM to the bash script but then the bash script doesn’t propagate it to postgres. Is there a way how to fix that / improve the bash script?

Thank you.

Hmm, can you try ending the script in exec postgres ... instead? I’m not actually sure exactly what systemd is doing here (it depends on the specific unit configuration you have) but either way, it is cleaner if you exec at the end because then the process that systemd will be dealing with will be postgres itself instead of bash.

Thank you! Solved! I’ve never used exec in a shell script and now looking at man page - I’m not the only one with this need since this is exactly the purpose of the exec command.

1 Like