Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 325709 - postgresql-server init script uses bash extensions
Summary: postgresql-server init script uses bash extensions
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High major with 1 vote (vote)
Assignee: PgSQL Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-26 13:16 UTC by Henning Schild
Modified: 2011-03-21 04:18 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Henning Schild 2010-06-26 13:16:36 UTC
I am using dev-db/postgresql-server-8.4.4-r1 on gentoo freebsd where the init script does not work at all. The init script uses a syntax for conditions that does not seem to be supported by the version of bash i am using. I do not know whether this is related to freebsd, but i do not think so.



Reproducible: Always

Steps to Reproduce:
1. install dev-db/postgresql-server-8.4.4-r1 together with app-shells/bash-4.1_p7
2. (you might need feebsd ...)
3. /etc/init.d/postgresql-8.4 start|stop

Actual Results:  
start:
postgresql-8.4       | * Starting PostgreSQL ...
postgresql-8.4       |[[: not found
postgresql-8.4       |  PID  TT  STAT      TIME COMMAND
postgresql-8.4       | 6156  ??  Ss     0:00.67 /usr/lib/postgresql-8.4/bin/postgres --silent-mode=true                                                                                                 [ ok ]esql-8.4       |

The server is started but the output shows ("[[: not found") that there is something going wrong.

stop:

postgresql-8.4       | * Stopping PostgreSQL (this can take up to 92 seconds) ...
postgresql-8.4       |[[: not found
postgresql-8.4       | * NICE_QUIT disabled.
postgresql-8.4       | * You really should have it enabled.
postgresql-8.4       |[[: not found
postgresql-8.4       | * RUDE_QUIT disabled.
postgresql-8.4       |[[: not found
postgresql-8.4       | * FORCE_QUIT disabled.
postgresql-8.4       | * Unable to shutdown server.                                                 [ !! ]esql-8.4       |
postgresql-8.4       | * ERROR: postgresql-8.4 failed to stop

The init script can not be used to stop the server. We need pg_ctl and zap the service.

Expected Results:  
The init script should be useable to start/stop the server.

The [[ ]] syntax does not seem to be supported by bash-4.1_p7 (maybe only on freebsd).
The following patch fixes the problem. I did test it with the versions of postgresql and bash mentioned in this report on freebsd. It should work for linux as well, if the problems exists for linux.

Bugwranglers please do not put this bug into GentooAlt since it is likely to be a general problem.

--- /etc/init.d/postgresql-8.4_backup   2010-06-25 22:46:58.000000000 +0200
+++ /etc/init.d/postgresql-8.4  2010-06-25 23:36:45.000000000 +0200
@@ -35,7 +35,7 @@
        -c "env PGDATA=\"${PGDATA}\" PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} /usr/lib/postgresql-8.4/bin/pg_ctl start ${WAIT_FOR_START} -t ${START_TIMEOUT} -s -o '--silent-mode=true ${PGOPTS}'"
     retval=$?
 
-    if [[ $retval != 0 ]] ; then
+    if [ $retval -ne 0 ] ; then
        eend $retval
        return $retval
     fi
@@ -61,12 +61,12 @@
 
     local retval
 
-    if [[ "${NICE_QUIT}" != "NO" ]] ; then
+    if [ "${NICE_QUIT}" != "NO" ] ; then
        su -l ${PGUSER} \
            -c "env PGDATA=\"${PGDATA}\" PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} /usr/lib/postgresql-8.4/bin/pg_ctl stop ${WAIT_FOR_STOP} -t ${NICE_TIMEOUT} -s -m smart"
        retval=$?
 
-       if [[ $retval == 0 ]] ; then
+       if [ $retval -eq 0 ] ; then
            eend $retval
            return $retval
        fi
@@ -78,7 +78,7 @@
        ewarn "You really should have it enabled."
     fi
 
-    if [[ "${RUDE_QUIT}" != "NO" ]] ; then
+    if [ "${RUDE_QUIT}" != "NO" ] ; then
        ewarn "RUDE_QUIT enabled."
        ewarn "Going to shutdown the server anyway."
 
@@ -86,7 +86,7 @@
            -c "env PGDATA=\"${PGDATA}\" PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} /usr/lib/postgresql-8.4/bin/pg_ctl stop ${WAIT_FOR_STOP} -t ${RUDE_TIMEOUT} -s -m fast"
        retval=$?
 
-       if [[ $retval == 0 ]] ; then
+       if [ $retval -eq 0 ] ; then
            eend $retval
            return $retval
        fi
@@ -96,7 +96,7 @@
        ewarn "RUDE_QUIT disabled."
     fi
 
-    if [[ "${FORCE_QUIT}" == "YES" ]] ; then
+    if [ "${FORCE_QUIT}" == "YES" ] ; then
        ewarn "FORCE_QUIT enabled."
        ewarn "Forcing server to shutdown."
        ewarn "A recover-run will be executed on the next startup."
@@ -106,7 +106,7 @@
 
        retval=$?
 
-       if [[ $retval == 0 ]] ; then
+       if [ $retval -eq 0 ] ; then
            ewarn "Server forced down."
            eend $retval
            return $retval
Comment 1 Harald van Dijk (RETIRED) gentoo-dev 2010-06-26 13:51:28 UTC
> The [[ ]] syntax does not seem to be supported by bash-4.1_p7 (maybe only on
> freebsd).

initscripts are run using /bin/sh, which is not bash on freebsd, and need not be bash on linux either.
Comment 2 Henning Schild 2010-06-27 09:19:20 UTC
(In reply to comment #1)
> initscripts are run using /bin/sh, which is not bash on freebsd, and need not
> be bash on linux either.

Ok than the shell causing the problem is /bin/sh from =sys-freebsd/freebsd-bin-7.2. Still there might be a problem on linux when /bin/sh is not bash.

Comment 3 Jens Rutschmann 2010-09-29 07:52:20 UTC
I want to confirm that the init script works with dash after applying the changes from the report.

Furthermore I added these lines to checkconfig():

if [ ! -d "/var/run/postgresql" ] ; then
        mkdir /var/run/postgresql
        chown "$PGUSER" /var/run/postgresql
fi

This is needed on my system as I have /var/run mounted on tmpfs.
Comment 4 Aaron W. Swenson gentoo-dev 2011-03-21 04:18:07 UTC
Fixed.

  21 Mar 2011; Aaron W. Swenson <titanofold@gentoo.org>
  +postgresql-server-8.2.20-r1.ebuild, +postgresql-server-8.3.14-r1.ebuild,
  +postgresql-server-8.4.7-r1.ebuild, +postgresql-server-9.0.3-r1.ebuild:
  Fixes bugs 274836, 302384, 323683, 325709, 347005, 347223, 353687 and
  353750.