Обсуждение: postgresql "init script" for postgres 9.2.15

Поиск
Список
Период
Сортировка

postgresql "init script" for postgres 9.2.15

От
Steve Langlois
Дата:


Hi, I've been searching for a 9.2.15 version of the postgresql script for "init script for starting up the PostgreSQL". I have managed to find older versions than what we are currently using, 8.2.5 but haven't had any luck finding a new version in the postgres 9.2.15 rpms. We are moving from CentOS 5 to CentOS 7 and need to update postgres from 8.2.5 to 9.2.15. 

Below is the version I have. Where can I find a version of this script for 9.2.15? Thank you.

#!/bin/sh
# postgresql This is the init script for starting up the PostgreSQL
# server
#
# chkconfig: - 64 36
# description: Starts and stops the PostgreSQL backend daemon that handles \
#       all database requests.
# processname: postmaster
# pidfile: $TV_HOME/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

# Version 7.4 Lamar Owen.

# Version 7.4.3 Tom Lane <tgl@sss.pgh.pa.us>
# Support condstop for uninstall
# Minor other changes suggested by Fernando Nasser.

# Version 7.4.5 Tom Lane <tgl@sss.pgh.pa.us>
# Rewrite to start postmaster directly, rather than via pg_ctl; this avoids
# fooling the postmaster's stale-lockfile check by having too many
# postgres-owned processes laying about.

# Version 8.1 Devrim Gunduz <devrim@PostgreSQL.org>
# Increased sleep time from 1 sec to 2 sec.

# Version 8.2 Devrim Gunduz <devrim@CommandPrompt.com>
# Set initdb as a seperate option.

. ${TV_ENV:-/usr/xxxx}/conf/environ.conf
TV_DB=${TV_DB:-/usr/xxxx/databases}
TV_PG_DEBUG=${TV_PG_DEBUG:-/dev/null}

# PGVERSION is the full package version, e.g., 8.2.0
# Note: the specfile ordinarily updates this during install
PGVERSION=8.2.5
# PGMAJORVERSION is major version, e.g., 8.2 (this should match PG_VERSION)
PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`

# Source function library.
. /etc/rc.d/init.d/functions

# Get function listing for cross-distribution logic.
TYPESET=`typeset -f|grep "declare"`

# Get config.
. /etc/sysconfig/network

# Find the name of the script
NAME=`basename $0`
if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]
then
NAME=${NAME:3}
fi

# For SELinux we need to use 'runuser' not 'su'
if [ -x /sbin/runuser ]
then
    SU=runuser
else
    SU=su
fi


# Set defaults for configuration variables
PGENGINE=/usr/bin
PGPORT=5432
PGDATA=$TV_DB/pgsql
if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base/template1" ]
then
echo "Using old-style directory structure"
else
PGDATA=$TV_DB/pgsql/data
fi
PGLOG=${TV_LOG:-/usr/xxxx/log}/pgstartup.log

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

export PGDATA
export PGPORT

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

[ -f "$PGENGINE/postmaster" ] || exit 1

script_result=0

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

# Make sure startup-time log file is valid
if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]
then
touch "$PGLOG" || exit 1
# chown postgres:postgres "$PGLOG"
chmod go-rwx "$PGLOG"
# do we need this?
# [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$PGLOG" 2>/dev/null
fi

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

if [ x`cat "$PGDATA/PG_VERSION"` != x"$PGMAJORVERSION" ]
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."
echo $"You need to upgrade the data format before using PostgreSQL."
echo $"See $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information."
exit 1
fi

# No existing PGDATA! Warn the user to initdb it.

else
echo
                echo "$PGDATA is missing. Use \"service postgresql initdb\" to initialize the cluster first."
echo_failure
echo
exit 1
  fi

echo -n "$PSQL_START"
# $SU -l postgres -c "$PGENGINE/postmaster -p '$PGPORT' -D '$PGDATA' ${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null
$PGENGINE/postmaster -p "$PGPORT" -D "$PGDATA" ${PGOPTS} >> "$PGLOG" 2>&1 < /dev/null &
sleep 2
pid=`pidof -s "$PGENGINE/postmaster"`
if [ $pid ] && [ -f "$PGDATA/postmaster.pid" ]
then
success "$PSQL_START"
touch $TV_HOME/lock/subsys/${NAME}
head -n 1 "$PGDATA/postmaster.pid" > "$TV_HOME/run/postmaster.${PGPORT}.pid"
echo
else
failure "$PSQL_START"
echo
script_result=1
fi
}

stop(){
echo -n $"Stopping ${NAME} service: "
# $SU -l postgres -c "$PGENGINE/pg_ctl stop -D '$PGDATA' -s -m fast" > /dev/null 2>&1 < /dev/null
$PGENGINE/pg_ctl stop -D "$PGDATA" -s -m fast > $TV_PG_DEBUG 2>&1 < /dev/null
ret=$? 
if [ $ret -eq 0 ]
then
echo_success
else
echo_failure
script_result=1
fi
echo
rm -f "$TV_HOME/run/postmaster.${PGPORT}.pid"
rm -f "$TV_HOME/lock/subsys/${NAME}"
}

restart(){
    stop
    start
}

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

condstop(){
    [ -e $TV_HOME/lock/subsys/${NAME} ] && stop
}

reload(){
#    $SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null 2>&1 < /dev/null
    $PGENGINE/pg_ctl reload -D "$PGDATA" -s > $TV_PG_DEBUG 2>&1 < /dev/null
}

initdb(){
    if [ -f "$PGDATA/PG_VERSION" ]
    then
echo "Data directory is not empty!"
echo_failure
script_result=1
    else
echo -n $"Initializing database: "
if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ]
then
mkdir -p "$PGDATA" || exit 1
# chown postgres:postgres "$PGDATA"
chmod go-rwx "$PGDATA"
fi
# Clean up SELinux tagging for PGDATA
# [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA"
# Initialize the database
# $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident sameuser'" >> "$PGLOG" 2>&1 < /dev/null
$PGENGINE/initdb --pgdata="$PGDATA" --auth='ident sameuser' >> "$PGLOG" 2>&1 < /dev/null
# Create directory for postmaster log
mkdir "$PGDATA/pg_log"
# chown postgres:postgres "$PGDATA/pg_log"
chmod go-rwx "$PGDATA/pg_log"

if [ -f "$PGDATA/PG_VERSION" ]
then
   echo_success
else
   echo_failure
   script_result=1
fi
    fi
}

# 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
script_result=$?
;;
  restart)
restart
;;
  condrestart)
condrestart
;;
  condstop)
condstop
;;
  reload|force-reload)
reload
;;
  initdb)
initdb
;;
  *)
echo $"Usage: $0 {start|stop|status|restart|condrestart|condstop|reload|force-reload|initdb}"
exit 1
esac

exit $script_result


Re: postgresql "init script" for postgres 9.2.15

От
Adrian Klaver
Дата:
On 07/13/2016 01:56 PM, Steve Langlois wrote:
>
> Hi, I've been searching for a 9.2.15 version of the postgresql script
> for "init script for starting up the PostgreSQL". I have managed to find
> older versions than what we are currently using, 8.2.5 but haven't had
> any luck finding a new version in the postgres 9.2.15 rpms. We are
> moving from CentOS 5 to CentOS 7 and need to update postgres from 8.2.5
> to 9.2.15.
>
> Below is the version I have. Where can I find a version of this script
> for 9.2.15? Thank you.

Given that it is Centos 7 they have moved to systemd:

https://wiki.postgresql.org/wiki/YUM_Installation#Startup


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: postgresql "init script" for postgres 9.2.15

От
Steve Langlois
Дата:


Thank you but in our appliance, we are not running postgres as a service, we are running it programatically with this script, call postmaster to start it for instance instead of using the service framework. Is there an equivalent in 9.x or does it now have to run as a service. I was able to modify the script to get 9.2 to run but I was hoping this script had been updated for 9.x. The current script uses --auth='ident sameuser' when calling initdb for instance which is not supported in 9.2.


Steve

steve.langlois@tavve.com


From: Adrian Klaver <adrian.klaver@aklaver.com>
Sent: Wednesday, July 13, 2016 5:11:24 PM
To: Steve Langlois; pgsql-general@postgresql.org
Subject: Re: [GENERAL] postgresql "init script" for postgres 9.2.15
 
On 07/13/2016 01:56 PM, Steve Langlois wrote:
>
> Hi, I've been searching for a 9.2.15 version of the postgresql script
> for "init script for starting up the PostgreSQL". I have managed to find
> older versions than what we are currently using, 8.2.5 but haven't had
> any luck finding a new version in the postgres 9.2.15 rpms. We are
> moving from CentOS 5 to CentOS 7 and need to update postgres from 8.2.5
> to 9.2.15.
>
> Below is the version I have. Where can I find a version of this script
> for 9.2.15? Thank you.

Given that it is Centos 7 they have moved to systemd:

https://wiki.postgresql.org/wiki/YUM_Installation#Startup


--
Adrian Klaver
adrian.klaver@aklaver.com

Re: postgresql "init script" for postgres 9.2.15

От
"David G. Johnston"
Дата:
Please don't top-post.

On Wed, Jul 13, 2016 at 5:35 PM, Steve Langlois <steve.langlois@tavve.com> wrote:

Thank you but in our appliance, we are not running postgres as a service, we are running it programatically with this script, call postmaster to start it for instance instead of using the service framework. Is there an equivalent in 9.x or does it now have to run as a service.

It is not surprising that a piece of code no longer required by the package for its main operation has not been maintained (maybe it has, I'm not familiar with the Centos assets).

​PostgreSQL is capable of being launched in any number of ways.  But as you move toward minority status (which initd on Centos 7 seems to be) the wealth of third-party maintained stuff to pick from tends to decrease.

David J.
 

Re: postgresql "init script" for postgres 9.2.15

От
Tom Lane
Дата:
Steve Langlois <steve.langlois@tavve.com> writes:
> Thank you but in our appliance, we are not running postgres as a service, we are running it programatically with this
script,call postmaster to start it for instance instead of using the service framework. Is there an equivalent in 9.x
ordoes it now have to run as a service. I was able to modify the script to get 9.2 to run but I was hoping this script
hadbeen updated for 9.x. The current script uses --auth='ident sameuser' when calling initdb for instance which is not
supportedin 9.2. 

You could try looking in the Fedora 15 RPMs --- that was the last
non-systemd Fedora release, I believe.  It looks like Fedora was on
Postgres 9.0.x at that point, so you might still need to do a bit more
fiddling to get it to work with PG 9.2; but it'd be closer than scripts
intended for 8.2, for sure.

Keep in mind that scripts like this are distro-maintained, not maintained
by the Postgres core project; and they tend to get a LOT more churn caused
by distro-specific issues than churn caused by Postgres changes.  It's
not really clear to me that you want to do anything except make whatever
changes you have to in the scripts you already have.  You may spend more
time dealing with useless-to-you changes than you save by not doing your
own research on what changed in Postgres.

            regards, tom lane


Re: postgresql "init script" for postgres 9.2.15

От
Adrian Klaver
Дата:
On 07/13/2016 02:35 PM, Steve Langlois wrote:
>
> Thank you but in our appliance, we are not running postgres as a
> service, we are running it programatically with this script, call
> postmaster to start it for instance instead of using the service
> framework. Is there an equivalent in 9.x or does it now have to run as a
> service. I was able to modify the script to get 9.2 to run but I was
> hoping this script had been updated for 9.x. The current script
> uses --auth='ident sameuser' when calling initdb for instance which is
> not supported in 9.2.

Well first:

systemctl enable postgresql-9.4.service

would make it a service that starts at boot.

If you just want to start and stop on demand then:

systemctl start postgresql-9.4.service

systemctl stop postgresql-9.4.service

If you set on using init.d/ scripts then:


https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=contrib/start-scripts/linux;hb=e9dca8ce147f32d7d64a9e64f9d8339310ad6535


>
>
> Steve
>
> steve.langlois@tavve.com
>
> ------------------------------------------------------------------------
> *From:* Adrian Klaver <adrian.klaver@aklaver.com>
> *Sent:* Wednesday, July 13, 2016 5:11:24 PM
> *To:* Steve Langlois; pgsql-general@postgresql.org
> *Subject:* Re: [GENERAL] postgresql "init script" for postgres 9.2.15
>
> On 07/13/2016 01:56 PM, Steve Langlois wrote:
>>
>> Hi, I've been searching for a 9.2.15 version of the postgresql script
>> for "init script for starting up the PostgreSQL". I have managed to find
>> older versions than what we are currently using, 8.2.5 but haven't had
>> any luck finding a new version in the postgres 9.2.15 rpms. We are
>> moving from CentOS 5 to CentOS 7 and need to update postgres from 8.2.5
>> to 9.2.15.
>>
>> Below is the version I have. Where can I find a version of this script
>> for 9.2.15? Thank you.
>
> Given that it is Centos 7 they have moved to systemd:
>
> https://wiki.postgresql.org/wiki/YUM_Installation#Startup
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: postgresql "init script" for postgres 9.2.15

От
Devrim Gündüz
Дата:
Hi,

On Wed, 2016-07-13 at 20:56 +0000, Steve Langlois wrote:
> I've been searching for a 9.2.15 version of the postgresql script for "init
> script for starting up the PostgreSQL". I have managed to find older versions
> than what we are currently using, 8.2.5 but haven't had any luck finding a
> new version in the postgres 9.2.15 rpms. We are moving from CentOS 5 to
> CentOS 7 and need to update postgres from 8.2.5 to 9.2.15.

Here is the 9.6 version: 


https://git.postgresql.org/gitweb/?p=pgrpms.git;a=blob;f=rpm/redhat/9.6/postgresql/EL-6/postgresql.init;h=daf436ec39f9038a7e3d73c50f80fc3492be15a1;hb=HEAD

You just need to change stuff starting line 92:


https://git.postgresql.org/gitweb/?p=pgrpms.git;a=blob;f=rpm/redhat/9.6/postgresql/EL-6/postgresql.init;h=daf436ec39f9038a7e3d73c50f80fc3492be15a1;hb=HEAD#l92

-HTH.

Regards,
--
Devrim GÜNDÜZ
Principal Systems Engineer @ EnterpriseDB: http://www.enterprisedb.com
PostgreSQL Danışmanı/Consultant, Red Hat Certified Engineer
Twitter: @DevrimGunduz , @DevrimGunduzTR

Вложения