]> git.pld-linux.org Git - packages/postgresql.git/blame - postgresql.init
- more todo
[packages/postgresql.git] / postgresql.init
CommitLineData
c35cc882 1#!/bin/sh
2#
d29ea5e3 3# postgresql This is the init script for starting up the PostgreSQL
4# server
5#
4f7ddd24 6# chkconfig: 345 84 25
c35cc882 7#
8# description: Starts and stops the PostgreSQL backend daemon that handles \
24852107 9# all database requests.
c35cc882 10#
11# processname: postmaster
c35cc882 12
c35cc882 13# Source function library
d29ea5e3 14. /etc/rc.d/init.d/functions
15
c35cc882 16# Get network config
d29ea5e3 17. /etc/sysconfig/network
18
c35cc882 19# Get service config
b57548c1 20if [ -f /etc/sysconfig/postgresql ] ; then
24852107 21 . /etc/sysconfig/postgresql
22else
23 echo "Error: /etc/sysconfig/postgresql not found"
24 echo " PostgreSQL can't be run."
25 exit 1
03af0381 26fi
27
c35cc882 28# Check that networking is up.
95633833 29if is_no "${NETWORKING}"; then
11f320d0 30 msg_network_down PostgreSQL
d584f4fd 31 exit 1
32fi
d29ea5e3 33
24852107 34pgstatus () {
35 PG_STATUS="unknown"
36 PG_PID="unknown"
37 status=`/usr/bin/pg_ctl -D $1 status`
15e46b8a 38
24852107 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
42 PG_STATUS="running"
43 PG_PID=`echo "$status" | sed 's/^pg_ctl:.*pid: \([0-9]\+\).*/\1/' | head -1`
44 fi
45}
46
47action="$1"
48
49# any db cluster as command line argument?
50if [ $# -gt 1 ]; then
51 shift
52 POSTGRES_DB_CLUSTERS="$@"
53fi
15e46b8a 54
d29ea5e3 55# See how we were called.
24852107 56case "$action" in
57 start)
58 for pgdir in $POSTGRES_DB_CLUSTERS; do
59 pgstatus "$pgdir"
60 if [ "$PG_STATUS" = "running" ]; then
61 if ps ax | grep -v grep | grep -q "$PG_PID"; then
62 msg_already_running "PostgreSQL $pgdir"
63 else
64 msg_not_running "PostgreSQL $pgdir"
65 rm -f $pgdir/postmaster.pid
66 $0 start "$pgdir"
67 fi
68 else
69 msg_starting "PostgreSQL $pgdir"
70 busy
71 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -w -D $pgdir start 2>&1 >/dev/null"
72
73 pgstatus "$pgdir"
74 if [ "$PG_STATUS" != "unknown" -a "$PG_PID" != "unknown" ]; then
75 deltext; ok
76 else
77 deltext; fail
78 fi
2a514bb5 79 fi
24852107 80 done
d29ea5e3 81 ;;
24852107 82 stop)
83 for pgdir in $POSTGRES_DB_CLUSTERS; do
84 pgstatus "$pgdir"
85 if [ "$PG_STATUS" = "not running" ]; then
86 msg_not_running "PostgreSQL $pgdir"
87 else
88 msg_stopping "PostgreSQL $pgdir"
89 busy
90
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"
93 pgstatus "$pgdir"
94 if [ "$PG_STATUS" != "not running" ]; then
95 deltext; fail
96 else
97 deltext; ok
98 fi
99 else
100 deltext; died
101 fi
102
103 rm -f $pgdir/postmaster.pid
104 fi
105 done
d29ea5e3 106 ;;
24852107 107 status)
108 for pgdir in $POSTGRES_DB_CLUSTERS; do
109 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -D $pgdir status"
110 done
d29ea5e3 111 ;;
24852107 112 restart)
113 $0 stop "$POSTGRES_DB_CLUSTERS"
114 $0 start "$POSTGRES_DB_CLUSTERS"
962e37bd 115 ;;
24852107 116 reload)
117 for pgdir in $POSTGRES_DB_CLUSTERS; do
118 pgstatus "$pgdir"
119 if [ "$PG_STATUS" = "not running" ]; then
120 msg_not_running "PostgreSQL $pgdir"
121 else
122 msg_reloading "PostgreSQL $pgdir"
123 busy
124
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"
127
128 pgstatus "$pgdir"
129 if [ "$PG_STATUS" = "running" ]; then
130 deltext; ok
131 else
132 deltext; fail
133 fi
134 else
135 deltext; died
136 rm -f $pgdir/postmaster.pid
137 $0 start
138 fi
139 fi
140 done
8d5c7b0d 141 ;;
24852107 142 *)
143 msg_usage "$0 {start|stop|status|restart|reload}"
144 exit 1
d29ea5e3 145esac
146
147exit 0
This page took 0.045308 seconds and 4 git commands to generate.