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