Re: BUG #12072: init script creates pid file with wrong owner

From: Henrik Størner <henrik(at)hswn(dot)dk>
To: Sandeep Thakkar <sandeep(dot)thakkar(at)enterprisedb(dot)com>, henrik-postgres(at)hswn(dot)dk
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #12072: init script creates pid file with wrong owner
Date: 2014-12-01 07:10:31
Message-ID: 547C1467.2020307@hswn.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-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(at)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(at)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(at)postgres ~]# service postgresql-9.3 initdb
Initialising database: [ O.k. ]
[root(at)postgres ~]# service postgresql-9.3 start
Starting postgresql-9.3-service: [ O.k. ]
[root(at)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(at)hswn(dot)dk
> <mailto:henrik-postgres(at)hswn(dot)dk>> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 12072
> Logged by: Henrik Storner
> Email address: henrik-postgres(at)hswn(dot)dk
> <mailto:henrik-postgres(at)hswn(dot)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(at)postgresql(dot)org
> <mailto:pgsql-bugs(at)postgresql(dot)org>)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>
>
>
>
> --
> Sandeep Thakkar
>

Attachment Content-Type Size
pginit.patch text/x-diff 285 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2014-12-01 15:41:15 Re: BUG #12072: init script creates pid file with wrong owner
Previous Message John R Pierce 2014-12-01 06:09:16 Re: BUG #12072: init script creates pid file with wrong owner