Thread: Strange pg_ctl behavior: postmaster shuts down on shell interrupt

Strange pg_ctl behavior: postmaster shuts down on shell interrupt

From
"smartdude"
Date:
Hi all

We use postgres 8.0.4 for our application on Linux ES3 kernel 2.4.21-4.
We wrote a small shell script for starting postgres, which does little
more than just calling postmaster. We trap interrupt signal in the
shell script to allow postgres to start even if interrupted by the
user. But the trap does not seem to work with postmaster or pg_ctl -
that is, the process shuts down.

#pg_cant_trap.sh
#!/bin/sh
pg_ctl stop && sleep 10 #to stop any earlier instance
trap 'printf "trapped\n"' 2 3
pg_ctl start
pg_ctl status
sleep 10 #interrupt the script at this point
sleep 10
pg_ctl status

Interrupting the script at the mentioned point stops the postmaster.
This behavior is not seen if I replace postmaster by some of my own
shell script or a program, that is it does not stop.

A small thing, but I am interested in knowing how it is possible for
postmaster to behave in this way.


Re: Strange pg_ctl behavior: postmaster shuts down on shell interrupt

From
Tom Lane
Date:
"smartdude" <in4tunio@gmail.com> writes:
> We use postgres 8.0.4 for our application on Linux ES3 kernel 2.4.21-4.
> We wrote a small shell script for starting postgres, which does little
> more than just calling postmaster. We trap interrupt signal in the
> shell script to allow postgres to start even if interrupted by the
> user.

"trap" only sets the shell's response to signals, not that of programs
started by the shell.  You're going at this entirely the wrong way:
what you need is to make sure the postmaster is dissociated from your
terminal so it doesn't get signals from the keyboard in the first place.
I believe what you need to add is a "-l logfile" option to the pg_ctl
call so that the postmaster's stdout gets disconnected from the
terminal.

            regards, tom lane