]> git.pld-linux.org Git - packages/postgresql.git/blame - postgresql.init
- perl-devel build requirement is back to build Perl procedural language
[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 \
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
0128b781
JB
20# Service config defaults
21ALLOW_TCP_CONNECTIONS=no
22ALLOW_USE_SSL=no
23POSTGRES_DATA_DIR=/var/lib/pgsql
24POSTGRES_LOG=/var/log/pgsql
25ENCODING=UNICODE
ca611f3c 26LOCALE=${LANG:-C}
0128b781 27
c35cc882 28# Get service config
b57548c1 29if [ -f /etc/sysconfig/postgresql ] ; then
30 . /etc/sysconfig/postgresql
03af0381 31fi
32
c35cc882 33# Check that networking is up.
95633833 34if is_no "${NETWORKING}"; then
11f320d0 35 msg_network_down PostgreSQL
d584f4fd 36 exit 1
37fi
d29ea5e3 38
15e46b8a 39# check if postmaster is realy alive
d892b14a
JB
40if [ -f $POSTGRES_DATA_DIR/postmaster.pid ]; then
41 if ps -p `head -1 $POSTGRES_DATA_DIR/postmaster.pid` > /dev/null ; then
42 # ok. it's alive
15e46b8a 43 echo > /dev/null;
d892b14a
JB
44 else
45 # oh, it has crashed
46 rm -f /var/lock/subsys/postgresql
47 fi
15e46b8a 48else
d892b14a 49 # it's stopped.
15e46b8a 50 rm -f /var/lock/subsys/postgresql
51fi
52
53
d29ea5e3 54# See how we were called.
55case "$1" in
56 start)
c35cc882 57 # Check if the service is already running?
53dd1abd 58 if [ -f /var/lock/subsys/postgresql ]; then
11f320d0 59 msg_already_running PostgreSQL
53dd1abd 60 else
2a514bb5
SZ
61 if is_yes "$ALLOW_USE_SSL"; then
62 if is_no "$ALLOW_TCP_CONNECTIONS"; then
63 nls "You must enable ALLOW_TCP_CONNECTIONS in order to use SSL"
64 exit 1
65 elif [ ! -f "$POSTGRES_DATA_DIR/server.key" ]; then
66 nls "$POSTGRES_DATA_DIR/server.key not found!"
67 exit 1
68 elif [ ! -f "$POSTGRES_DATA_DIR/server.crt" ]; then
69 nls "$POSTGRES_DATA_DIR/server.crt not found!"
70 exit 1
71 fi
72 fi
73
d4674174 74 # Sanity check
12e13883
JB
75 [ -e /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
76 [ -f /tmp/.s.PGSQL.5432.lock ] || rm -f /tmp/.s.PGSQL.5432.lock
d4674174 77
78 # Check for the PGDATA structure
1884b875 79 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
d4674174 80 # Check version of existing PGDATA
12e13883 81 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.2' ]; then
53dd1abd 82 show "Databases created under incompatibile version. Migrate them first."; fail
d4674174 83 exit 1
84 fi
85 else
8d5c7b0d
AM
86 echo "Postgresql database not initialized. Try \"$0 init\" before start."
87 exit 1
d4674174 88 fi
89
53dd1abd 90 msg_starting PostgreSQL
c35cc882 91 busy
1884b875 92 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
2a514bb5 93 $(is_yes "$POSTGRES_QUIET" && echo '-s')";
8e290e17 94 POSTMASTER_OPTIONS=" \
2a514bb5
SZ
95 $(is_yes "$POSTGRES_QUIET" && echo '-S') \
96 $(is_yes "$POSTGRES_DISABLE_FSYNC" && echo '-F') \
97 $(is_yes "$ALLOW_TCP_CONNECTIONS" && echo '-i') \
4e273c82 98 $(is_yes "$ALLOW_USE_SSL" && echo '-l') \
99 $([ "$BUFFERS" ] && echo \-B $BUFFERS) \
100 $([ "$MAXCONN" ] && echo \-N $MAXCONN)";
8e290e17 101
02e6328b 102 TMPDIR=/tmp su postgres -c "\
2cf10168 103 $(echo "/usr/bin/pg_ctl start -w $PGSQL_CMDLINE -l $POSTGRES_LOG") \
8e290e17 104 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
105 $(echo "2>&1 >/dev/null")";
d09ccc4d 106
53dd1abd 107 out=`status postmaster`
108 if [ $? -eq 0 ]; then
109 deltext; ok
70825085 110 else
53dd1abd 111 deltext; fail
112 exit 1
70825085 113 fi
c35cc882 114 fi
d29ea5e3 115 touch /var/lock/subsys/postgresql
d29ea5e3 116 ;;
117 stop)
8e290e17 118
53dd1abd 119 if [ ! -f /var/lock/subsys/postgresql ]; then
11f320d0 120 msg_not_running PostgreSQL
53dd1abd 121 exit 0
122 fi
2cf10168 123 msg_stopping PostgreSQL
1884b875
JR
124 busy
125 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 126 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
53dd1abd 127 out=`status postmaster`
1884b875
JR
128 if [ $? -eq 0 ]; then
129 deltext; fail
130 echo -e "\n$out";
131 exit 1
132 else
133 deltext; ok
53dd1abd 134 fi
d892b14a 135 rm -f $POSTGRES_DATA_DIR/postmaster.pid
d29ea5e3 136 rm -f /var/lock/subsys/postgresql
137 ;;
138 status)
1884b875 139 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 140 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
d29ea5e3 141 ;;
962e37bd
AM
142 restart)
143 $0 stop
144 $0 start
145 ;;
146 reload)
1884b875 147 if [ ! -f /var/lock/subsys/postgresql ]; then
11f320d0 148 msg_not_running PostgreSQL
1884b875
JR
149 exit 0
150 fi
2cf10168 151 msg_reloading PostgreSQL
1884b875 152 busy
8e290e17 153
1884b875 154 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
8e290e17 155 $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
156 POSTMASTER_OPTIONS=" \
157 $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
158 $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
159 $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
160
02e6328b 161 TMPDIR=/tmp su postgres -c "\
8e290e17 162 $(echo "/usr/bin/pg_ctl restart $PGSQL_CMDLINE -l $POSTGRES_LOG") \
163 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
164 $(echo "2>&1 >/dev/null")";
165
1884b875
JR
166 out=`status postmaster`
167 if [ $? -eq 0 ]; then
168 deltext; ok
169 else
170 deltext; fail
171 echo -e "\n$out";
172 exit 1
173 fi
d29ea5e3 174 ;;
8d5c7b0d
AM
175 init)
176 if [ -f "$POSTGRES_DATA_DIR/PG_VERSION" ]; then
177 echo "Seems that database is initialized now. Remove by hand $POSTGRES_DATA_DIR"
178 echo "before initialize database."
179 exit 1
180 fi
181
ef885d78 182 echo -n "Specify encoding for pgsql database (eg: LATIN2, KOI8) [$ENCODING]: "
8d5c7b0d
AM
183 read new_encoding
184 ENCODING=${new_encoding:-$ENCODING}
ca611f3c
AM
185 echo -n "Specify locale for pgsql database (eg: pl_PL, de_DE) [$LOCALE]: "
186 read new_locale
187 LOCALE=${new_locale:-$LOCALE}
8d5c7b0d 188
ca611f3c 189 show "Creating initial postgresql database using $ENCODING/$LOCALE encoding/locale"
85b06983 190 started
8d5c7b0d
AM
191
192 # Create sample database
193 if [ ! -d $POSTGRES_DATA_DIR ]; then
194 mkdir -p $POSTGRES_DATA_DIR
195 chown postgres.postgres $POSTGRES_DATA_DIR
196 chmod 700 $POSTGRES_DATA_DIR
197 fi
198
199
ca611f3c 200 LC_ALL=$LOCALE; export LC_ALL
ef885d78 201 TMPDIR=/tmp su - postgres -s /bin/sh -c "LD_LIBRARY_PATH=/usr/lib \
8d5c7b0d
AM
202 initdb --pgdata=$POSTGRES_DATA_DIR \
203 -L /usr/share/postgresql -E $ENCODING"
85b06983
AM
204
205 echo "REMEMBER to setup password for user \"postgres\"!"
8d5c7b0d 206 ;;
d29ea5e3 207 *)
11f320d0 208 msg_usage "$0 {start|stop|status|restart|reload}"
d29ea5e3 209 exit 1
210esac
211
212exit 0
This page took 0.074152 seconds and 4 git commands to generate.