3 # postgresql This is the init script for starting up the PostgreSQL
8 # description: Starts and stops the PostgreSQL backend daemon that handles \
9 # all database requests.
11 # processname: postmaster
12 # pidfile: $POSTGRES_DATA_DIR/postmaster.pid
14 # Source function library
15 . /etc/rc.d/init.d/functions
18 . /etc/sysconfig/network
21 if [ -f /etc/sysconfig/postgresql ] ; then
22 . /etc/sysconfig/postgresql
24 ALLOW_TCP_CONNECTIONS=no
26 POSTGRES_DATA_DIR=/var/lib/pgsql
27 POSTGRES_LOG=/var/log/pgsql
31 # Check that networking is up.
32 if is_no "${NETWORKING}"; then
33 msg_network_down PostgreSQL
37 # check if postmaster is realy alive
38 if [ -f $POSTGRES_DATA_DIR/postmaster.pid ]; then
39 if ps -p `head -1 $POSTGRES_DATA_DIR/postmaster.pid` > /dev/null ; then
44 rm -f /var/lock/subsys/postgresql
48 rm -f /var/lock/subsys/postgresql
52 # See how we were called.
55 # Check if the service is already running?
56 if [ -f /var/lock/subsys/postgresql ]; then
57 msg_already_running PostgreSQL
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"
63 elif [ ! -f "$POSTGRES_DATA_DIR/server.key" ]; then
64 nls "$POSTGRES_DATA_DIR/server.key not found!"
66 elif [ ! -f "$POSTGRES_DATA_DIR/server.crt" ]; then
67 nls "$POSTGRES_DATA_DIR/server.crt not found!"
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
76 # Check for the PGDATA structure
77 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
78 # Check version of existing PGDATA
79 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.2' ]; then
80 show "Databases created under incompatibile version. Migrate them first."; fail
84 # Create sample database
85 if [ ! -d $POSTGRES_DATA_DIR ]; then
86 mkdir -p $POSTGRES_DATA_DIR
87 chown postgres.postgres $POSTGRES_DATA_DIR
88 chmod 700 $POSTGRES_DATA_DIR
90 TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
91 initdb --pgdata=$POSTGRES_DATA_DIR \
92 -L /usr/share/postgresql -E $ENCODING"
95 msg_starting PostgreSQL
97 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
98 $(is_yes "$POSTGRES_QUIET" && echo '-s')";
99 POSTMASTER_OPTIONS=" \
100 $(is_yes "$POSTGRES_QUIET" && echo '-S') \
101 $(is_yes "$POSTGRES_DISABLE_FSYNC" && echo '-F') \
102 $(is_yes "$ALLOW_TCP_CONNECTIONS" && echo '-i') \
103 $(is_yes "$ALLOW_USE_SSL" && echo '-l') \
104 $([ "$BUFFERS" ] && echo \-B $BUFFERS) \
105 $([ "$MAXCONN" ] && echo \-N $MAXCONN)";
107 TMPDIR=/tmp su postgres -c "\
108 $(echo "/usr/bin/pg_ctl start -w $PGSQL_CMDLINE -l $POSTGRES_LOG") \
109 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
110 $(echo "2>&1 >/dev/null")";
112 out=`status postmaster`
113 if [ $? -eq 0 ]; then
120 touch /var/lock/subsys/postgresql
124 if [ ! -f /var/lock/subsys/postgresql ]; then
125 msg_not_running PostgreSQL
128 msg_stopping PostgreSQL
130 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
131 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
132 out=`status postmaster`
133 if [ $? -eq 0 ]; then
140 rm -f $POSTGRES_DATA_DIR/postmaster.pid
141 rm -f /var/lock/subsys/postgresql
144 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
145 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
152 if [ ! -f /var/lock/subsys/postgresql ]; then
153 msg_not_running PostgreSQL
156 msg_reloading PostgreSQL
159 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
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')";
166 TMPDIR=/tmp su postgres -c "\
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")";
171 out=`status postmaster`
172 if [ $? -eq 0 ]; then
181 msg_usage "$0 {start|stop|status|restart|reload}"