Re: Eliminating start error message: "unary operator - Mailing list pgsql-general

From Carlos Oliva
Subject Re: Eliminating start error message: "unary operator
Date
Msg-id E148BE531B8AD311922E005004D3EEA1010F1E06@xchserver.pbsinet.com
Whole thread Raw
Responses Re: Eliminating start error message: "unary operator  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi Scott,
There it goes.  I also enclosed it in a text file.

Thanks you for your help


#! /bin/sh
# postgresql    This is the init script for starting up the PostgreSQL
#        server
#
# chkconfig: - 85 15
# description: Starts and stops the PostgreSQL backend daemon that
handles \
#           all database requests.
# processname: postmaster
# pidfile: /var/run/postmaster.pid

# Version 6.5.3-2 Lamar Owen
# Added code to determine if PGDATA exists, whether it is current
version
#     or not, and initdb if no PGDATA (initdb will not overwrite a
database).

# Version 7.0 Lamar Owen
# Added logging code
# Changed PGDATA.
#

# Version 7.0.2 Trond Eivind Glomsrd <teg@redhat.com>
# use functions, add conditional restart

# Version 7.0.3 Lamar Owen <lamar@postgresql.org>
# Check for the existence of functions before blindly using them
# in particular -- check for success () and failure () before using.
# More Cross-distribution support -- PGVERSION variable, and docdir
checks.

# Version 7.1 Release Candidate Lamar Owen <lamar@postgresql.org>
# initdb parameters have changed.

# Version 7.1.2 Trond Eivind Glomsrd <teg@redhat.com>
# Specify shell for su
# Handle stop better - kill unwanted output, make it wait until the
database is ready
# Handle locales slightly differently - always using "C" isn't a valid
option
# Kill output from database initialization
# Mark messages for translation

# Version 7.1.2-2.PGDG Lamar Owen <lamar.owen@wgcr.org>
# sync up.
# Karl's fixes for some quoting issues.

# Version 7.2b2 Lamar Owen <lamar.owen@wgcr.org>
# version change.

# Version 7.2 final.  Lamar Owen <lamar.owen@wgcr.org>
# reload from Peter E.
# Eliminate the pidof postmaster test in stop -- we're using pg_ctl so
we don't need pidof.
# Tested the $? return for the stop script -- it does in fact propagate.
# TODO: multiple postmasters.

# VErsion 7.3 Lamar OWen <lamar.owen@ramifordistat.net>
# Multiple postmasters, courtesy Karl DeBisschop

# PGVERSION is:
PGVERSION=7.3

# Source function library.
INITD=/etc/rc.d/init.d
. $INITD/functions

# Get function listing for cross-distribution logic.
TYPESET=`typeset -F`
# Get config.
. /etc/sysconfig/network

# Find the name of the script
NAME=`basename $0`

# Set defaults for port and database directory
PGPORT=5432
export PGDATA=/var/lib/pgsql
if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base/template1 ]
then
    echo "Using old-style directory structure"
else
    export PGDATA=/var/lib/pgsql/data
fi

# Override defaults from /etc/sysconfig/pgsql if file is present
[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}
export PGDATA
export PGPORT
export PGOPTS

# Check that networking is up.
# Pretty much need it for postmaster.
[ "${NETWORKING}" = "no" ] && exit 0

[ -f /usr/bin/postmaster ] || exit 0

start(){
    PSQL_START=$"Starting ${NAME} service: "

    # Check for the PGDATA structure
    if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base ]
    then
    # Check version of existing PGDATA

        if [ `cat $PGDATA/PG_VERSION` != '7.3' ]
        then
            SYSDOCDIR="(Your System's documentation
directory)"
            if [ -d /usr/doc/postgresql-$PGVERSION ]
            then
                SYSDOCDIR=/usr/doc
            fi
            if [ -d /usr/share/doc/postgresql-$PGVERSION ]
            then
                SYSDOCDIR=/usr/share/doc
            fi
            if [ -d /usr/doc/packages/postgresql-$PGVERSION
]
            then
                SYSDOCDIR=/usr/doc/packages
            fi
            if [ -d
/usr/share/doc/packages/postgresql-$PGVERSION ]
            then
                SYSDOCDIR=/usr/share/doc/packages
            fi
            echo
            echo $"An old version of the database format was
found.\nYou need to upgrade the data format before using
PostgreSQL.\nSee $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for
more information."
            exit 1
        fi

    # No existing PGDATA! Initdb it.

    else
            echo -n $"Initializing database: "
                if [ ! -d $PGDATA ]
        then
            mkdir -p $PGDATA
            chown postgres.postgres $PGDATA
            chmod go-rwx $PGDATA
        fi
        # Make sure the locale from the initdb is preserved for
later startups...
        [ -f /etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n
$PGDATA/../initdb.i18n
        # Just in case no locale was set, use en_US
        [ ! -f /etc/sysconfig/i18n ] && echo "LANG=en_US" >
$PGDATA/../initdb.i18n
        # Is expanded this early to be used in the command su
runs
        echo "export LANG LC_ALL LC_CTYPE LC_COLLATE LC_NUMERIC
LC_CTYPE LC_TIME" >> $PGDATA/../initdb.i18n
        # Initialize the database
        su -l postgres -s /bin/sh -c "/usr/bin/initdb
--pgdata=$PGDATA > /dev/null 2>&1" < /dev/null
        [ -f $PGDATA/PG_VERSION ] && echo_success
        [ ! -f $PGDATA/PG_VERSION ] && echo_failure
        echo
     fi

    # Check for postmaster already running...
  # note that pg_ctl only looks at the data structures in PGDATA
  # you really do need the pidof()
    pid=`pidof -s /usr/bin/postmaster`
    if [ $pid ] && /usr/bin/pg_ctl status -D $PGDATA > /dev/null
2>&1
    then
        echo $"Postmaster already running."
    else
        #all systems go -- remove any stale lock files
        rm -f /tmp/.s.PGSQL.${PGPORT} > /dev/null
        echo -n "$PSQL_START"
        su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl  -D
$PGDATA -p /usr/bin/postmaster -o '-p ${PGPORT}' start  > /dev/null
2>&1" < /dev/null
         sleep 1
         pid=`pidof -s /usr/bin/postmaster`
         if [ $pid ]
        then
            if echo "$TYPESET"|grep "declare -f success"
>/dev/null
            then
                success "$PSQL_START"
            else
                echo "  [ OK ]"
            fi
            touch /var/lock/subsys/${NAME}
            echo $pid > /var/run/postmaster.${PGPORT}.pid
            echo
        else
            if echo "$TYPESET"|grep "declare -f failure"
>/dev/null
            then
                failure "$PSQL_START"
            else
                echo " [ FAILED ]"
            fi
            echo
        fi
    fi
}

stop(){
    PSQL_STOP=$"Stopping ${NAME} service: "
    su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl stop -D $PGDATA -s
-m fast" > /dev/null 2>&1
    ret=$?
    if [ $ret -eq 0 ]
    then
        if echo "$TYPESET"|grep "declare -f success" >/dev/null
        then
            success "$PSQL_STOP"
        else
            echo "  [ OK ]"
        fi

    else
        if echo "$TYPESET"|grep "declare -f failure" >/dev/null
        then
            failure "$PSQL_START"
        else
            echo "  [ FAILED ]"
        fi

    fi
    echo
    rm -f /var/run/postmaster.${PGPORT}.pid
    rm -f /var/lock/subsys/${NAME}
}

restart(){
    stop
    start
}

condrestart(){
    [ -e /var/lock/subsys/${NAME} ] && restart
}

reload(){
    su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl reload -D $PGDATA -s"
> /dev/null 2>&1
}

# This script is slightly unusual in that the name of the daemon
(postmaster)
# is not the same as the name of the subsystem (postgresql)

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status postmaster
    ;;
  restart)
    restart
    ;;
  condrestart)
    condrestart
    ;;
  reload|force-reload)
    reload
    ;;
  *)
    echo $"Usage: $0
{start|stop|status|restart|condrestart|reload|force-reload}"
    exit 1
esac

exit 0


-----Original Message-----
From: scott.marlowe [mailto:scott.marlowe@ihs.com]
Sent: Monday, June 23, 2003 4:20 PM
To: Carlos
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Eliminating start error message: "unary operator


Could you post a copy of the /etc/rc.d/init.d/postgresql file here?  It
may have gotten corrupted or have a simple syntax error in it.

On Mon, 23 Jun 2003, Carlos Oliva wrote:

> Postgresql was installed from RPMS, downloaded from the following url:

> ftp://ftp5.us.postgresql.org/pub/PostgreSQL/binary/v7.3.2/RPMS/redhat-
> 7.
> 3/
> The startup script was created when the rpms were installed.
>
>
> -----Original Message-----
> From: pgsql-general-owner@postgresql.org
> [mailto:pgsql-general-owner@postgresql.org] On Behalf Of scott.marlowe
> Sent: Monday, June 23, 2003 3:35 PM
> To: Carlos
> Cc: 'pgsql-general@postgresql.org'
> Subject: Re: [GENERAL] Eliminating start error message: "unary
> operator
>
>
> On Mon, 23 Jun 2003, Carlos wrote:
>
> > Hi Forum,
> > What should I correct in order to eliminate the following error
> > message on
> > start:
> > Executing /etc/rc.d/init.d/postgresql start ..
> > Starting postgresql service: -sh: [: ==: unary operator expected
> > [  OK  ]
> >
> > We installed a v7.3.2 and PostgreSQL seems to be running very well
> > but
>
> > we want to get rid of this message.
>
> How did you install postgresql (rpms, source code) and where did the
> startup script come from?
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to
majordomo@postgresql.org)
>

Attachment

pgsql-general by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: Eliminating start error message: "unary operator
Next
From: Erik Price
Date:
Subject: Re: [pgsql-advocacy] interesting PHP/MySQL thread