3 # postgresql This is the init script for starting up the PostgreSQL
8 # description: Starts and stops the PostgreSQL backend daemon that handles \
9 # all database requests.
11 # processname: postmaster
13 # Source function library
14 . /etc/rc.d/init.d/functions
17 . /etc/sysconfig/network
20 if [ -f /etc/sysconfig/postgresql ] ; then
21 . /etc/sysconfig/postgresql
23 echo "Error: /etc/sysconfig/postgresql not found"
24 echo " PostgreSQL can't be run."
28 # Check that networking is up.
29 if is_no "${NETWORKING}"; then
30 msg_network_down PostgreSQL
37 status=`/usr/bin/pg_ctl -D $1 status`
39 if echo "$status" | grep -q 'pg_ctl: postmaster or postgres is not running'; then
40 PG_STATUS="not running"
41 elif echo "$status" | grep -q 'pg_ctl: postmaster is running'; then
43 PG_PID=`echo "$status" | sed 's/^pg_ctl:.*pid: \([0-9]\+\).*/\1/' | head -1`
49 # any db cluster as command line argument?
52 POSTGRES_DB_CLUSTERS="$@"
55 # See how we were called.
58 for pgdir in $POSTGRES_DB_CLUSTERS; do
60 if [ "$PG_STATUS" = "running" ]; then
61 if ps ax | grep -v grep | grep -q "$PG_PID"; then
62 msg_already_running "PostgreSQL $pgdir"
64 msg_not_running "PostgreSQL $pgdir"
65 rm -f $pgdir/postmaster.pid
69 msg_starting "PostgreSQL $pgdir"
71 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -w -D $pgdir start 2>&1 >/dev/null"
74 if [ "$PG_STATUS" != "unknown" -a "$PG_PID" != "unknown" ]; then
83 for pgdir in $POSTGRES_DB_CLUSTERS; do
85 if [ "$PG_STATUS" = "not running" ]; then
86 msg_not_running "PostgreSQL $pgdir"
88 msg_stopping "PostgreSQL $pgdir"
91 if ps ax | grep -v grep | grep -q "$PG_PID"; then
92 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -w -D $pgdir stop -m fast 2>&1 >/dev/null"
94 if [ "$PG_STATUS" != "not running" ]; then
103 rm -f $pgdir/postmaster.pid
108 for pgdir in $POSTGRES_DB_CLUSTERS; do
109 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -D $pgdir status"
113 $0 stop "$POSTGRES_DB_CLUSTERS"
114 $0 start "$POSTGRES_DB_CLUSTERS"
117 for pgdir in $POSTGRES_DB_CLUSTERS; do
119 if [ "$PG_STATUS" = "not running" ]; then
120 msg_not_running "PostgreSQL $pgdir"
122 msg_reloading "PostgreSQL $pgdir"
125 if ps ax | grep -v grep | grep -q "$PG_PID"; then
126 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -D $pgdir restart 2>&1 >/dev/null"
129 if [ "$PG_STATUS" = "running" ]; then
136 rm -f $pgdir/postmaster.pid
143 msg_usage "$0 {start|stop|status|restart|reload}"