Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XvSre-00020T-RY for pgsql-bugs@arkaria.postgresql.org; Mon, 01 Dec 2014 15:26:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XvSrd-00038K-Jp for pgsql-bugs@arkaria.postgresql.org; Mon, 01 Dec 2014 15:26:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XvL86-00073t-PU for pgsql-bugs@postgresql.org; Mon, 01 Dec 2014 07:10:42 +0000 Received: from mx.hswn.dk ([2a01:4f8:161:8208:1::6]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XvL7y-0005vk-2K for pgsql-bugs@postgresql.org; Mon, 01 Dec 2014 07:10:41 +0000 X-Virus-Scanned: Debian amavisd-new at mx.hswn.dk Received: from [IPv6:2001:16d8:dda8:0:16da:e9ff:feed:d5a7] (osiris.hswn.dk [IPv6:2001:16d8:dda8:0:16da:e9ff:feed:d5a7]) by vmail.hswn.dk (Postfix) with ESMTPSA id BE43F20148; Mon, 1 Dec 2014 08:10:23 +0100 (CET) Message-ID: <547C1467.2020307@hswn.dk> Date: Mon, 01 Dec 2014 08:10:31 +0100 From: =?UTF-8?B?SGVucmlrIFN0w7hybmVy?= Organization: Xymon User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Sandeep Thakkar , henrik-postgres@hswn.dk CC: "pgsql-bugs@postgresql.org" Subject: Re: BUG #12072: init script creates pid file with wrong owner References: <20141126141924.15506.75024@wrigleys.postgresql.org> In-Reply-To: Content-Type: multipart/mixed; boundary="------------020907000105030405050809" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------020907000105030405050809 Content-Type: multipart/alternative; boundary="------------040507090803060902020207" --------------040507090803060902020207 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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.noar= ch.rpm Installed: pgdg-redhat93.noarch 0:9.3-1 Complete! [root@postgres ~]# yum install postgresql93-server postgresql93-contrib 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=20 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=3D`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null` if [ "x$pid" !=3D x ] then=20=20=20 success "$PSQL_START" touch "$lockfile" * echo $pid > "$pidfile"* echo=20=20=20 else=20=20=20 failure "$PSQL_START" echo=20=20=20 script_result=3D1 fi=20=20=20=20=20 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, > wrote: > > The following bug has been logged on the website: > > Bug reference: 12072 > Logged by: Henrik Storner > Email address: 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 > ) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-bugs > > > > > --=20 > Sandeep Thakkar > --------------040507090803060902020207 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
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> wrote:
The following bug has been logged on the website:

Bug reference:      12072
Logged by:          Henrik Storner
Email address:      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)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



--
Sandeep Thakkar


--------------040507090803060902020207-- --------------020907000105030405050809 Content-Type: text/x-diff; name="pginit.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pginit.patch" --- 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" --------------020907000105030405050809 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------020907000105030405050809--