From: Henrik Størner <henrik@hswn.dk>
To: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
To: henrik-postgres@hswn.dk
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #12072: init script creates pid file with wrong owner
Date: Mon, 01 Dec 2014 08:10:31 +0100
Message-ID: <547C1467.2020307@hswn.dk> (raw)
In-Reply-To: <CANFyU97+vW3x1c0b=cOy5CwcPAKw-oOqJ7p2hfwv2nNrn=3JoA@mail.gmail.com>
References: <20141126141924.15506.75024@wrigleys.postgresql.org>
<CANFyU97+vW3x1c0b=cOy5CwcPAKw-oOqJ7p2hfwv2nNrn=3JoA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Checked. Steps to reproduce:
1) Fresh install of CentOS 6.6 base-server (could be any Redhat like distro)
2) Install Postgres 9.3.5 as per
http://www.postgresql.org/download/linux/redhat/ - i.e. using the
yum.postgresql.org repository
root@postgres ~]# yum install
http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
<cut yum chatter>
Installed:
pgdg-redhat93.noarch 0:9.3-1
Complete!
[root@postgres ~]# yum install postgresql93-server postgresql93-contrib
<cut more yum chatter>
Installing : postgresql93-libs-9.3.5-1PGDG.rhel6.x86_64 1/5
Installing : postgresql93-9.3.5-1PGDG.rhel6.x86_64 2/5
Installing : uuid-1.6.1-10.el6.x86_64 3/5
Installing : postgresql93-contrib-9.3.5-1PGDG.rhel6.x86_64 4/5
Installing : postgresql93-server-9.3.5-1PGDG.rhel6.x86_64 5/5
Verifying : postgresql93-contrib-9.3.5-1PGDG.rhel6.x86_64 1/5
Verifying : postgresql93-9.3.5-1PGDG.rhel6.x86_64 2/5
Verifying : postgresql93-server-9.3.5-1PGDG.rhel6.x86_64 3/5
Verifying : postgresql93-libs-9.3.5-1PGDG.rhel6.x86_64 4/5
Verifying : uuid-1.6.1-10.el6.x86_64 5/5
Installed:
postgresql93-contrib.x86_64 0:9.3.5-1PGDG.rhel6
postgresql93-server.x86_64 0:9.3.5-1PGDG.rhel6
Dependencies installed:
postgresql93.x86_64 0:9.3.5-1PGDG.rhel6 postgresql93-libs.x86_64
0:9.3.5-1PGDG.rhel6 uuid.x86_64 0:1.6.1-10.el6
Complete!
3) Start Postgres using the init script file, and
/var/run/postgresql-9.3.pid is owned by root.
[root@postgres ~]# service postgresql-9.3 initdb
Initialising database: [ O.k. ]
[root@postgres ~]# service postgresql-9.3 start
Starting postgresql-9.3-service: [ O.k. ]
[root@postgres ~]# ls -l /var/run/postgresql-9.3.pid
-rw-r--r--. 1 root root 5 1 dec 07:44 /var/run/postgresql-9.3.pid
The problem is with the init script installed from the rpm package. From
line 161 it performs the server start by doing
echo -n "$PSQL_START"
$SU -l postgres -c "$PGENGINE/postmaster -p '$PGPORT' -D
'$PGDATA' ${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null
sleep 2
pid=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null`
if [ "x$pid" != x ]
then
success "$PSQL_START"
touch "$lockfile"
* echo $pid > "$pidfile"*
echo
else
failure "$PSQL_START"
echo
script_result=1
fi
Note the
echo $pid > "$pidfile"
This creates a pid-file owned by root. The owner:group should be changed
to "postgres:postgres", in the same way that is done with the log file
$PGLOG a bit earlier in the script. A simple one-line patch is attached.
Regards,
Henrik
Den 01-12-2014 kl. 06:07 skrev Sandeep Thakkar:
> The init script will first do "su - postgres" before starting the
> server, so there is no way that the owner of the PID file (default
> location is $DATADIR/postmaster.pid) is not postgres. Please recheck.
>
> On Wed, Nov 26, 2014 at 7:49 PM, <henrik-postgres@hswn.dk
> <mailto:henrik-postgres@hswn.dk>> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 12072
> Logged by: Henrik Storner
> Email address: henrik-postgres@hswn.dk
> <mailto:henrik-postgres@hswn.dk>
> PostgreSQL version: 9.3.5
> Operating system: CentOS 6.6
> Description:
>
> The /etc/init.d/postgresql-9.3 file created a PID file, but fails
> to make it
> owned by user 'postgres'.
>
> This means that using the "pg_ctl" command to restart Postgres fails,
> because user postgres cannot update the pid file (if you set
> external_pid_file in postgresql.conf so it can find the pid file).
>
> The init script should do a "chown postgres:postgres $pidfile" so
> the pid
> file is owned by the postgres user. This allows pg_ctl commands to
> work.
>
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org
> <mailto:pgsql-bugs@postgresql.org>)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>
>
>
>
> --
> Sandeep Thakkar
>
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:pginit.patch (text/x-diff, 284B) download--- postgresql-9.3.orig 2014-12-01 07:58:16.520342256 +0100+++ postgresql-9.3 2014-12-01 08:02:00.998345566 +0100@@ -167,6 +167,7 @@
success "$PSQL_START"
touch "$lockfile"
echo $pid > "$pidfile"
+ chown postgres:postgres "$pidfile"
echo
else
failure "$PSQL_START"
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: henrik@hswn.dk, sandeep.thakkar@enterprisedb.com, henrik-postgres@hswn.dk
Subject: Re: BUG #12072: init script creates pid file with wrong owner
In-Reply-To: <547C1467.2020307@hswn.dk>
References: <20141126141924.15506.75024@wrigleys.postgresql.org> <CANFyU97+vW3x1c0b=cOy5CwcPAKw-oOqJ7p2hfwv2nNrn=3JoA@mail.gmail.com> <547C1467.2020307@hswn.dk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox