]> git.pld-linux.org Git - packages/postgresql.git/blame - postgresql.init
- python subpackage group changed to Libraries/Python
[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#
c35cc882 6# chkconfig: 345 85 15
7#
8# description: Starts and stops the PostgreSQL backend daemon that handles \
9# all database requests.
10#
11# processname: postmaster
d892b14a 12# pidfile: $POSTGRES_DATA_DIR/postmaster.pid
c35cc882 13
c35cc882 14# Source function library
d29ea5e3 15. /etc/rc.d/init.d/functions
16
c35cc882 17# Get network config
d29ea5e3 18. /etc/sysconfig/network
19
c35cc882 20# Get service config
b57548c1 21if [ -f /etc/sysconfig/postgresql ] ; then
22 . /etc/sysconfig/postgresql
03af0381 23else
b57548c1 24 ALLOW_TCP_CONNECTIONS=no
2a514bb5
SZ
25 ALLOW_USE_SSL=no
26 POSTGRES_DATA_DIR=/var/lib/pgsql
53dd1abd 27 POSTGRES_LOG=/var/log/pgsql
03af0381 28fi
29
c35cc882 30# Check that networking is up.
95633833 31if is_no "${NETWORKING}"; then
11f320d0 32 msg_network_down PostgreSQL
d584f4fd 33 exit 1
34fi
d29ea5e3 35
15e46b8a 36# check if postmaster is realy alive
d892b14a
JB
37if [ -f $POSTGRES_DATA_DIR/postmaster.pid ]; then
38 if ps -p `head -1 $POSTGRES_DATA_DIR/postmaster.pid` > /dev/null ; then
39 # ok. it's alive
15e46b8a 40 echo > /dev/null;
d892b14a
JB
41 else
42 # oh, it has crashed
43 rm -f /var/lock/subsys/postgresql
44 fi
15e46b8a 45else
d892b14a 46 # it's stopped.
15e46b8a 47 rm -f /var/lock/subsys/postgresql
48fi
49
50
d29ea5e3 51# See how we were called.
52case "$1" in
53 start)
c35cc882 54 # Check if the service is already running?
53dd1abd 55 if [ -f /var/lock/subsys/postgresql ]; then
11f320d0 56 msg_already_running PostgreSQL
53dd1abd 57 else
2a514bb5
SZ
58 if is_yes "$ALLOW_USE_SSL"; then
59 if is_no "$ALLOW_TCP_CONNECTIONS"; then
60 nls "You must enable ALLOW_TCP_CONNECTIONS in order to use SSL"
61 exit 1
62 elif [ ! -f "$POSTGRES_DATA_DIR/server.key" ]; then
63 nls "$POSTGRES_DATA_DIR/server.key not found!"
64 exit 1
65 elif [ ! -f "$POSTGRES_DATA_DIR/server.crt" ]; then
66 nls "$POSTGRES_DATA_DIR/server.crt not found!"
67 exit 1
68 fi
69 fi
70
d4674174 71 # Sanity check
12e13883
JB
72 [ -e /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
73 [ -f /tmp/.s.PGSQL.5432.lock ] || rm -f /tmp/.s.PGSQL.5432.lock
d4674174 74
75 # Check for the PGDATA structure
1884b875 76 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
d4674174 77 # Check version of existing PGDATA
12e13883 78 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.2' ]; then
53dd1abd 79 show "Databases created under incompatibile version. Migrate them first."; fail
d4674174 80 exit 1
81 fi
82 else
83 # Create sample database
84 if [ ! -d $POSTGRES_DATA_DIR ]; then
85 mkdir -p $POSTGRES_DATA_DIR
86 chown postgres.postgres $POSTGRES_DATA_DIR
1884b875 87 chmod 700 $POSTGRES_DATA_DIR
d4674174 88 fi
02e6328b 89 TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
1884b875
JR
90 initdb --pgdata=$POSTGRES_DATA_DIR \
91 -L /usr/share/postgresql"
d4674174 92 fi
93
53dd1abd 94 msg_starting PostgreSQL
c35cc882 95 busy
1884b875 96 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
2a514bb5 97 $(is_yes "$POSTGRES_QUIET" && echo '-s')";
8e290e17 98 POSTMASTER_OPTIONS=" \
2a514bb5
SZ
99 $(is_yes "$POSTGRES_QUIET" && echo '-S') \
100 $(is_yes "$POSTGRES_DISABLE_FSYNC" && echo '-F') \
101 $(is_yes "$ALLOW_TCP_CONNECTIONS" && echo '-i') \
102 $(is_yes "$ALLOW_USE_SSL" && echo '-l')";
8e290e17 103
02e6328b 104 TMPDIR=/tmp su postgres -c "\
2cf10168 105 $(echo "/usr/bin/pg_ctl start -w $PGSQL_CMDLINE -l $POSTGRES_LOG") \
8e290e17 106 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
107 $(echo "2>&1 >/dev/null")";
d09ccc4d 108
53dd1abd 109 out=`status postmaster`
110 if [ $? -eq 0 ]; then
111 deltext; ok
70825085 112 else
53dd1abd 113 deltext; fail
114 exit 1
70825085 115 fi
c35cc882 116 fi
d29ea5e3 117 touch /var/lock/subsys/postgresql
d29ea5e3 118 ;;
119 stop)
8e290e17 120
53dd1abd 121 if [ ! -f /var/lock/subsys/postgresql ]; then
11f320d0 122 msg_not_running PostgreSQL
53dd1abd 123 exit 0
124 fi
2cf10168 125 msg_stopping PostgreSQL
1884b875
JR
126 busy
127 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 128 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
53dd1abd 129 out=`status postmaster`
1884b875
JR
130 if [ $? -eq 0 ]; then
131 deltext; fail
132 echo -e "\n$out";
133 exit 1
134 else
135 deltext; ok
53dd1abd 136 fi
d892b14a 137 rm -f $POSTGRES_DATA_DIR/postmaster.pid
d29ea5e3 138 rm -f /var/lock/subsys/postgresql
139 ;;
140 status)
1884b875 141 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 142 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
d29ea5e3 143 ;;
962e37bd
AM
144 restart)
145 $0 stop
146 $0 start
147 ;;
148 reload)
1884b875 149 if [ ! -f /var/lock/subsys/postgresql ]; then
11f320d0 150 msg_not_running PostgreSQL
1884b875
JR
151 exit 0
152 fi
2cf10168 153 msg_reloading PostgreSQL
1884b875 154 busy
8e290e17 155
1884b875 156 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
8e290e17 157 $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
158 POSTMASTER_OPTIONS=" \
159 $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
160 $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
161 $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
162
02e6328b 163 TMPDIR=/tmp su postgres -c "\
8e290e17 164 $(echo "/usr/bin/pg_ctl restart $PGSQL_CMDLINE -l $POSTGRES_LOG") \
165 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
166 $(echo "2>&1 >/dev/null")";
167
1884b875
JR
168 out=`status postmaster`
169 if [ $? -eq 0 ]; then
170 deltext; ok
171 else
172 deltext; fail
173 echo -e "\n$out";
174 exit 1
175 fi
d29ea5e3 176 ;;
177 *)
11f320d0 178 msg_usage "$0 {start|stop|status|restart|reload}"
d29ea5e3 179 exit 1
180esac
181
182exit 0
This page took 0.050441 seconds and 4 git commands to generate.