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