Skip to content

Commit

Permalink
Add a GTM startup script.
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jan 21, 2014
1 parent db66259 commit 5e1b04a
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 4 deletions.
22 changes: 19 additions & 3 deletions SOURCES/README.rpm-dist
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,31 @@ need to start Postgres-XC. Again as root, run:

service postgresxc-1.1 start

This command will start a data node postmaster that willl listen on localhost
This command will start a data node postmaster that will listen on localhost
and Unix socket 5432 only. Edit /var/lib/pgxc/1.1/data/postgresql.conf and
pg_hba.conf if you want to allow remote access -- see the section on Grand
Unified Configuration. Creat or edit /etc/sysconfig/pgxc/postgresxc to tweak
Unified Configuration. Create or edit /etc/sysconfig/pgxc/postgresxc to tweak
the startup configuration, especially if you need to start a coordinator
component than a data node:
component rather than a data node:

PGCOMPONENT=coordinator

If you want to run a GTM, first you'll need to initialize it:

service postgresgtm-1.1 initgtm

as root, and it will prepare a new GTM directory for you. Then you will need
to start the GTM. Again as root, run:

service postgresgtm-1.1 start

This command will start a GTM that will listen on localhost and Unix socket
6666 only. Edit /var/lib/pgxc/1.1/gtm/gtm.conf to tweak the configuration.
Create or edit /etc/sysconfig/pgxc/postgresgtm to tweak the GTM startup
configuration, especially if you need to start a GTM proxy rather than a GTM:

PGGTM=gtm_proxy

The file /var/lib/pgxc/1.1/.bash_profile is packaged to help with the
setting of environment variables. You may edit this file, and it won't be
overwritten during an upgrade. However, enhancements and bugfixes may
Expand Down
207 changes: 207 additions & 0 deletions SOURCES/postgresgtm.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
#!/bin/sh
#
# postgresgtm This is the init script for starting up the Postgres-XC
# global transaction manager.
#
# chkconfig: - 64 36
# description: Postgres-XC global transaction manager.
# processname: gtm
# pidfile="/var/run/${NAME}.pid"

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

# Version 1.1. David Wheeler <[email protected]>
# Based on PostgreSQL script by Devrim Gunduz <[email protected]>.

# PGXCVERSION is the full package version, e.g., 1.1.0
# Note: the specfile inserts the correct value during package build
PGVERSION=xxxx
# PGMAJORVERSION is major version, e.g., 1.1 (this should match PG_VERSION)
PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`

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

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

# Get network 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/pgxc-$PGMAJORVERSION/bin
PGGTM=gtm
#PGGTM=gtm_proxy
PGPORT=6666
PGDATA=/var/lib/pgxc/$PGMAJORVERSION/gtm
PGLOG=/var/lib/pgxc/$PGMAJORVERSION/${PGGTM}startup.log


lockfile="/var/lock/subsys/${NAME}"
pidfile="/var/run/${NAME}.pid"

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

export PGDATA
export PGPORT

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

script_result=0

start(){
[ -x "$PGENGINE/$PGGTM" ] || exit 5

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"
[ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG"
fi

# Check for the PGDATA structure
if [ ! -f "$PGDATA/gtm.conf" ]
then
# No existing PGDATA! Warn the user to initgtm it.

echo
echo "$PGDATA is missing. Use \"service $NAME initgtm\" to initialize the gtm first."
echo_failure
echo
exit 1
fi

echo -n "$PSQL_START"
$SU -l postgres -c "$PGENGINE/$PGGTM -p '$PGPORT' -D '$PGDATA' ${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null
sleep 2
pid=`head -n 1 "$PGDATA/$PGGTM.pid" 2>/dev/null`
if [ "x$pid" != x ]
then
success "$PSQL_START"
touch "$lockfile"
echo $pid > "$pidfile"
echo
else
failure "$PSQL_START"
echo
script_result=1
fi
}

stop(){
echo -n $"Stopping ${NAME} service: "
if [ -e "$lockfile" ]
then
$SU -l postgres -c "$PGENGINE/gtm_ctl stop -D '$PGDATA' -Z $PGGTM" > /dev/null 2>&1 < /dev/null
ret=$?
if [ $ret -eq 0 ]
then
echo_success
rm -f "$pidfile"
rm -f "$lockfile"
else
echo_failure
script_result=1
fi
else
# not running; per LSB standards this is "ok"
echo_success
fi
echo
}

restart(){
stop
start
}

initgtm(){
if [ -f "$PGDATA/gtm.conf" ]
then
echo "Data directory is not empty!"
echo_failure
else
echo -n $"Initializing GTM: "
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"

# Make sure the startup-time log file is OK, too
if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]
then
touch "$PGLOG" || exit 1
chown postgres:postgres "$PGLOG"
chmod go-rwx "$PGLOG"
[ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG"
fi

# Initialize the GTM.
$SU -l postgres -c "$PGENGINE/initgtm --pgdata='$PGDATA' -Z $PGGTM" >> "$PGLOG" 2>&1 < /dev/null

[ -f "$PGDATA/gtm.conf" ] && echo_success
[ ! -f "$PGDATA/gtm.conf" ] && echo_failure
echo
fi
}

condrestart(){
[ -e "$lockfile" ] && restart || :
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $pidfile $NAME
script_result=$?
;;
restart)
restart
;;
initgtm)
initgtm
;;
condrestart|try-restart)
condrestart
;;
force-reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|force-reload|initgtm}"
exit 2
esac

exit $script_result
2 changes: 1 addition & 1 deletion SOURCES/postgresxc.init
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# is not the same as the name of the subsystem (postgresxc)

# Version 1.1. David Wheeler <[email protected]>
# Based on Postgres-XC script by Devrim Gunduz <[email protected]>.
# Based on PostgreSQL script by Devrim Gunduz <[email protected]>.

# PGXCVERSION is the full package version, e.g., 1.1.0
# Note: the specfile inserts the correct value during package build
Expand Down
5 changes: 5 additions & 0 deletions SPECS/postgresxc-1.1.spec
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Source5: pg_config.h
Source6: README.rpm-dist
Source7: ecpg_config.h
Source8: %{oname}.pam
Source9: postgresgtm.init

Patch1: rpm-pgxc.patch
Patch2: %{oname}-logging.patch
Expand Down Expand Up @@ -399,6 +400,8 @@ esac
install -d %{buildroot}/etc/rc.d/init.d
sed -e 's/^PGVERSION=.*$/PGVERSION=%{version}/' -e 's/^PGSQLMAJORVERSION=.*$/PGSQLMAJORVERSION=%{pgmajorversion}/' <%{SOURCE1} > %{oname}.init
install -m 755 %{oname}.init %{buildroot}/etc/rc.d/init.d/%{oname}-%{majorversion}
sed -e 's/^PGVERSION=.*$/PGVERSION=%{version}/' <%{SOURCE9} > postgresgtm.init
install -m 755 postgresgtm.init %{buildroot}/etc/rc.d/init.d/postgresgtm-%{majorversion}

%if %pam
install -d %{buildroot}/etc/pam.d
Expand Down Expand Up @@ -500,6 +503,7 @@ chmod 0700 /var/log/%{sname}

%post server
chkconfig --add %{oname}-%{majorversion}
chkconfig --add postgresgtm-%{majorversion}
/sbin/ldconfig
# postgres' .bash_profile.
# We now don't install .bash_profile as we used to in pre 9.0. Instead, use cat,
Expand Down Expand Up @@ -796,6 +800,7 @@ fi
%files server -f pg_server.lst
%defattr(-,root,root)
%config(noreplace) /etc/rc.d/init.d/%{oname}-%{majorversion}
%config(noreplace) /etc/rc.d/init.d/postgresgtm-%{majorversion}
%if %pam
%config(noreplace) /etc/pam.d/%{oname}%{packageversion}
%endif
Expand Down

0 comments on commit 5e1b04a

Please sign in to comment.