-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
232 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters