[arch-commits] Commit in postgresql/trunk (postgresql)
Dan McGee
dan at archlinux.org
Fri Apr 1 18:24:43 UTC 2011
Date: Friday, April 1, 2011 @ 14:24:42
Author: dan
Revision: 117420
Update postgresql init script
* Address FS#23529 - add -m smart to shutdown
* Add reload/status commands
* Rework restart to use pg_ctl restart command
* Make output quieter via -s flag
* Make all commands wait via -w
Modified:
postgresql/trunk/postgresql
------------+
postgresql | 85 ++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 58 insertions(+), 27 deletions(-)
Modified: postgresql
===================================================================
--- postgresql 2011-04-01 17:42:20 UTC (rev 117419)
+++ postgresql 2011-04-01 18:24:42 UTC (rev 117420)
@@ -4,34 +4,42 @@
. /etc/rc.d/functions
. /etc/conf.d/postgresql
+# Default PGROOT if it wasn't defined in the conf.d file
+PGROOT=${PGROOT:-/var/lib/postgres}
+PG_CTL="/usr/bin/pg_ctl -D $PGROOT/data -l /var/log/postgresql.log -s -w"
+
+postgres_init() {
+ # initialization
+ if [ ! $(egrep '^postgres:' /etc/group) ]; then
+ stat_busy "Adding postgres group"
+ groupadd -g 88 postgres
+ stat_done
+ fi
+ if [ ! $(egrep '^postgres:' /etc/passwd) ]; then
+ stat_busy "Adding postgres user"
+ useradd -u 88 -g postgres -d $PGROOT -s /bin/bash postgres
+ [ -d $PGROOT ] && chown -R postgres:postgres $PGROOT
+ stat_done
+ fi
+ if [ ! -d $PGROOT/data ]; then
+ mkdir -p $PGROOT/data && chown -R postgres:postgres $PGROOT
+ su - postgres -c "/usr/bin/initdb $INITOPTS -D $PGROOT/data"
+ fi
+ if [ ! -e /var/log/postgresql.log ]; then
+ touch /var/log/postgresql.log
+ chown postgres /var/log/postgresql.log
+ fi
+}
+
case "$1" in
start)
+ postgres_init
stat_busy "Starting PostgreSQL"
- # initialization
- if [ ! `egrep '^postgres:' /etc/group` ]; then
- stat_busy "Adding postgres group"
- groupadd -g 88 postgres
- stat_done
- fi
- if [ ! `egrep '^postgres:' /etc/passwd` ]; then
- stat_busy "Adding postgres user"
- useradd -u 88 -g postgres -d $PGROOT -s /bin/bash postgres
- [ -d $PGROOT ] && chown -R postgres:postgres $PGROOT
- stat_done
- fi
- if [ ! -d $PGROOT/data ]; then
- mkdir -p $PGROOT/data && chown -R postgres:postgres $PGROOT
- su - postgres -c "/usr/bin/initdb $INITOPTS -D $PGROOT/data"
- fi
- if [ ! -e /var/log/postgresql.log ]; then
- touch /var/log/postgresql.log
- chown postgres /var/log/postgresql.log
- fi
- # start the process
su - postgres -c \
- "/usr/bin/pg_ctl -D $PGROOT/data -l /var/log/postgresql.log -W start"
+ "$PG_CTL start"
if [ $? -gt 0 ]; then
stat_fail
+ exit 1
else
add_daemon postgresql
stat_done
@@ -40,7 +48,7 @@
stop)
stat_busy "Stopping PostgreSQL"
su - postgres -c \
- "/usr/bin/pg_ctl -D $PGROOT/data -l /var/log/postgresql.log -w stop"
+ "$PG_CTL stop -m fast"
if [ $? -gt 0 ]; then
stat_fail
else
@@ -48,12 +56,35 @@
stat_done
fi
;;
+ reload)
+ stat_busy "Reloading PostgreSQL"
+ su - postgres -c \
+ "$PG_CTL reload"
+ if [ $? -gt 0 ]; then
+ stat_fail
+ exit 1
+ else
+ stat_done
+ fi
+ ;;
restart)
- $0 stop
- sleep 3
- $0 start
+ postgres_init
+ stat_busy "Restarting PostgreSQL"
+ su - postgres -c \
+ "$PG_CTL restart -m fast"
+ if [ $? -gt 0 ]; then
+ stat_fail
+ exit 1
+ else
+ add_daemon postgresql
+ stat_done
+ fi
;;
+ status)
+ stat_busy "Checking PostgreSQL status";
+ ck_status postgresql
+ ;;
*)
- echo "usage: $0 {start|stop|restart}"
+ echo "usage: $0 {start|stop|reload|restart|status}"
esac
exit 0
More information about the arch-commits
mailing list