Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WqQFx-000196-Tn for pgsql-pkg-debian@arkaria.postgresql.org; Fri, 30 May 2014 17:06:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WqQFx-0006K1-CW for pgsql-pkg-debian@arkaria.postgresql.org; Fri, 30 May 2014 17:06:13 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WqQFw-0006Jv-KS for pgsql-pkg-debian@postgresql.org; Fri, 30 May 2014 17:06:12 +0000 Received: from smtp.pobox.com ([208.72.237.35]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WqQFp-0007MG-1d for pgsql-pkg-debian@postgresql.org; Fri, 30 May 2014 17:06:10 +0000 Received: from smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id A2D701BE4C for ; Fri, 30 May 2014 13:06:02 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :subject:message-id:references:mime-version:content-type :in-reply-to; s=sasl; bh=eBoITYB+3Xk4yJ+wCGyWC8wUhJg=; b=Nu+6Z2d 6zt+VObT/BbnZ11DAk/MFRtLDq9IqB+k4msZyKbZPaR/LCLJm1bZbgptFLv6SECJ hoUCLw18kZOliLhhIOLdBc33SZ/J9G5EsqziBhBJAsiR5CpTdt9HOwknYc/NZrrL RXe8n+s8wppicz9khxpl8feFP8X+/3p3mUMA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=date:from:to :subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=sasl; b=yfiuJQL/17XyFHOsAUrmhOc0dg6ldAoXL +PC1/d+xMGds28rgok1E15fLuX/NIAhPd/v1FbpdPBJeJne962L25M36ZBcG0RiS 1OJQcn7tmMOLQluyaC0u+ObwGQUR90NRexkkjfIMRSqZz/QsMUOsxTVR0A41V5ml pPsAMud+iI= Received: from pb-smtp0. (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id 991B81BE4B for ; Fri, 30 May 2014 13:06:02 -0400 (EDT) Received: from localhost (unknown [75.112.235.167]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-smtp0.pobox.com (Postfix) with ESMTPSA id DE0AA1BE45 for ; Fri, 30 May 2014 13:05:58 -0400 (EDT) Date: Fri, 30 May 2014 13:05:58 -0400 From: Chris Nehren To: pgsql-pkg-debian@postgresql.org Subject: Re: [BUGS] BUG #8177: initscript should create /var/run/postgresql Message-ID: <20140530170558.GA5510@behemoth> Mail-Followup-To: pgsql-pkg-debian@postgresql.org References: <20130530025835.GB974@msgid.df7cb.de> <20140530170316.GC13595@behemoth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="EuxKj2iCbKjpUGkD" Content-Disposition: inline In-Reply-To: <20140530170316.GC13595@behemoth> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pobox-Relay-ID: ABBBAF68-E81C-11E3-A901-9903E9FBB39C-49531120!pb-smtp0.pobox.com X-Pg-Spam-Score: -2.7 (--) X-Mailing-List: pgsql-pkg-debian List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Precedence: bulk Sender: pgsql-pkg-debian-owner@postgresql.org --EuxKj2iCbKjpUGkD Content-Type: multipart/mixed; boundary="vtzGhvizbBRQ85DL" Content-Disposition: inline --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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: > > >=20 > > > Bug reference: 8177 > > > Logged by: stronny > > > Email address: stronny@celestia.ru > > > PostgreSQL version: 9.2.4 > > > Operating system: wheezy > > > Description: =20 > > >=20 > > > When installed from apt.postgresql.org Postgres fails to start on sys= tem > > > boot. > > >=20 > > > Wheezy changed /var/run to become memory-based so initscript should c= reate > > > /var/run/postgresql if necessary. > >=20 > > 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 > >=20 > > do_ctl_all start "$1" "Starting PostgreSQL $1 database server" > > } > >=20 > > We create the directory, what specifically doesn't work for you? >=20 > 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: >=20 > start|stop|restart|reload) > if [ -z "`pg_lsclusters -h`" ]; then > log_warning_msg 'No PostgreSQL clusters exist; see "man pg_cr= eatecluster"' > exit 0 > fi >=20 > 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. >=20 > 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. >=20 > The reproduction steps for this bug are as follows: >=20 > 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 >=20 > I've been able to reproduce this 100% of the time with the above > steps. >=20 > --=20 > Chris Nehren --=20 Chris Nehren --vtzGhvizbBRQ85DL Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="postgresql.mkdir.patch" Content-Transfer-Encoding: quoted-printable --- /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 @@ =20 case "$1" in start|stop|restart|reload) + # we need to create the /var/run/postgresql directory as root befo= re + # dropping privileges so that the postgres user can start the data= base + # later, even in the event of internal server crash at boot. this + # directory needs to exist for postgres to run, and things will fa= il 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_createclus= ter"' exit 0 --vtzGhvizbBRQ85DL-- --EuxKj2iCbKjpUGkD Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQJdBAABAgBHBQJTiLp2QBSAAAAAABUAInBrYS1hZGRyZXNzQGdudXBnLm9yZ2Nu ZWhyZW4rcGdzcWwtcGtnLWRlYmlhbkBwb2JveC5jb20ACgkQEcD4YkAzS89FvA// cmnmlMjb4fKloQv99GuVfrjqZ+OHqP3Da8At2+s3nOIra6hFnsQ/Auz0cuDBG8aN ux2O/GYAtFYNknkaBisLKn0dOIH1kO4hWanrGg4As/1hEUuERRUMPBthPURXc/7t oN8l7YVl4nHUYy2tJLx6N15awfpN5iSjVycoMRPNEUMT98zzCY5O2T5yK5AGESSl PyKK9zagOr9DPGJ0BpaLXxMNjlkQDGwBdaa1zGHETKmYfZEtUWEv/SZD7bqEVMpz 0tk8rB0K25dYkS6lvsmWJK++xJQhzQXWaWU+u0hU4rLoP7BWrNEm1aeRDmIYc3as tgoknhLTjDBuJxSVl0bvwAXRONje6Im/pvSCcbwqurBllkG7WxeRUz3tMCmMa/QO kiCdi5So5aoatXRzhwbWE+NQcqFGdSQ/OxCKgJyG5gd7jxixMvaUJOyc97zTM6F5 MAoiL4bQZ9pIv+KRscpQV5QJ0iQZShplNo6sm7+fKZxkX55sa8SjAa9+eHmOEyHQ Nr5Wxlaby0+ocNQXp5rlYbkl6CkEtl6fMNVVmrfRii0cKMcVK0sVo3WnEQbLjHSR JAs/b/2qUbg5dMROIos4I61M0dpTw9cEwFkuAsN/LAsZvlhPV+3e8Q8MPDsso36+ 2oSQnBkJua+i5H1LGawWMW2s8PgmbKBYO6qb0oUAqc4= =Bfmt -----END PGP SIGNATURE----- --EuxKj2iCbKjpUGkD--