pg.ddx.io  pgsql-pkg-debian@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Nehren <cnehren+pgsql-pkg-debian@pobox.com>
To: pgsql-pkg-debian@postgresql.org
Subject: Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql
Date: Fri, 30 May 2014 13:05:58 -0400
Message-ID: <20140530170558.GA5510@behemoth> (raw)
In-Reply-To: <20140530170316.GC13595@behemoth>
References: <20130530025835.GB974@msgid.df7cb.de>
	<20140530170316.GC13595@behemoth>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-pkg-debian>

It would help if I actually attached the patch.  My apologies.

On Fri, May 30, 2014 at 13:03:16 -0400, Chris Nehren wrote:
> > On Mon, 2013-05-27 at 09:27 +0000, stronny@celestia.ru wrote:
> > > The following bug has been logged on the website:
> > > 
> > > Bug reference:      8177
> > > Logged by:          stronny
> > > Email address:      stronny@celestia.ru
> > > PostgreSQL version: 9.2.4
> > > Operating system:   wheezy
> > > Description:        
> > > 
> > > When installed from apt.postgresql.org Postgres fails to start on system
> > > boot.
> > > 
> > > Wheezy changed /var/run to become memory-based so initscript should create
> > > /var/run/postgresql if necessary.
> > 
> > start() {
> >     # create socket directory
> >     if [ -d /var/run/postgresql ]; then
> >         chmod 2775 /var/run/postgresql
> >     else
> >         install -d -m 2775 -o postgres -g postgres /var/run/postgresql
> >     fi
> > 
> >     do_ctl_all start "$1" "Starting PostgreSQL $1 database server"
> > }
> > 
> > We create the directory, what specifically doesn't work for you?
> 
> I've been able to reproduce this as well, and have found the root
> cause.  Presently, the init script itself
> (/etc/init.d/postgresql) does this:
> 
>     start|stop|restart|reload)
>         if [ -z "`pg_lsclusters -h`" ]; then
>             log_warning_msg 'No PostgreSQL clusters exist; see "man pg_createcluster"'
>             exit 0
>         fi
> 
> pg_lsclusters is a Perl application that gets most of its logic
> from PgCommon.pm.  Its entry point into PgCommon.pm (the one we
> care about, anyway) is the subroutine &cluster_info.
> &cluster_info, at line 575, calls &get_cluster_socketdir.  This
> subroutine, at line 360, gets the 'unix_socket_directories' value
> from the configuration file. If the value is defined in the
> configuration file (the default), it immediately returns that
> value to &cluster_info.  This is important.  If the value is
> *not* defined, then &get_cluster_socketdir defaults it to
> '/var/run/postgresql' and attempts to stat() this directory.  As
> '/var/run' is now a tmpfs in Debian, this fails, because no
> attempt has been made to create that directory before the stat()
> runs.
> 
> There are actually two bugs here.  The first is attempting to
> stat() a directory that the code has not ensured exists, which is
> what this bug is about.  The second, more general, is that the
> code makes no attempts at creating or even verifying the
> existence of any unix_socket_{directory,directories} before
> returning.  I've attached a patch to the init script that ensures
> /var/run/postgresql actually exists before the code tries to
> stat() it.
> 
> The reproduction steps for this bug are as follows:
> 
> 1. install fresh Debian wheezy machine
> 2. Add official Postgres mirror to apt, installing the keyring
> for same
> 3. Install the Postgres server
> 4. Remove any unix_socket_{directory,directories} directive from
> /etc/postgresql/9.?/main/postgresql.conf
> 5. Reboot, observe Postgres startup failure
> 
> I've been able to reproduce this 100% of the time with the above
> steps.
> 
> -- 
> Chris Nehren



-- 
Chris Nehren

Attachments:

postgresql.mkdir.patch (text/x-diff, 872B) download --- /etc/init.d/postgresql 2013-08-02 04:50:43.000000000 -0400 +++ postgresql 2014-05-29 17:33:51.598667808 -0400 @@ -28,6 +28,16 @@ case "$1" in start|stop|restart|reload) + # we need to create the /var/run/postgresql directory as root before + # dropping privileges so that the postgres user can start the database + # later, even in the event of internal server crash at boot. this + # directory needs to exist for postgres to run, and things will fail to + # start if it doesn't exist (see BUG #8177). + if [ -d /var/run/postgresql ]; then + chmod 2775 /var/run/postgresql + else + install -d -m 2775 -o postgres -g postgres /var/run/postgresql + fi if [ -z "`pg_lsclusters -h`" ]; then log_warning_msg 'No PostgreSQL clusters exist; see "man pg_createcluster"' exit 0

view thread (7+ messages)

Message-ID: <20140530170558.GA5510@behemoth>
Permalink:  ../20140530170558.GA5510@behemoth/
Also on:    postgresql.org/message-id/20140530170558.GA5510@behemoth

 ·  · 

reply

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-pkg-debian@postgresql.org
  Cc: cnehren+pgsql-pkg-debian@pobox.com
  Subject: Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql
  In-Reply-To: <20140530170558.GA5510@behemoth>
  References: <20130530025835.GB974@msgid.df7cb.de> <20140530170316.GC13595@behemoth> <20140530170558.GA5510@behemoth>

* 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