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: /var/run/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
30 # Check that networking is up.
31 if is_no "${NETWORKING}"; then
32 msg_Network_Down Postgresql
36 # check if postmaster is realy alive
37 if [ -f /var/lib/pgsql/postmaster.pid ]; then
38 if ps -p `head -1 /var/lib/pgsql/postmaster.pid` > /dev/null ; then
43 rm -f /var/lock/subsys/postgresql
47 rm -f /var/lock/subsys/postgresql
51 # See how we were called.
54 # Check if the service is already running?
55 if [ -f /var/lock/subsys/postgresql ]; then
56 msg_Already_Running PostgreSQL
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"
62 elif [ ! -f "$POSTGRES_DATA_DIR/server.key" ]; then
63 nls "$POSTGRES_DATA_DIR/server.key not found!"
65 elif [ ! -f "$POSTGRES_DATA_DIR/server.crt" ]; then
66 nls "$POSTGRES_DATA_DIR/server.crt not found!"
72 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
74 # Check for the PGDATA structure
75 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
76 # Check version of existing PGDATA
77 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.1' ]; then
78 show "Databases created under incompatibile version. Migrate them first."; fail
82 # Create sample database
83 if [ ! -d $POSTGRES_DATA_DIR ]; then
84 mkdir -p $POSTGRES_DATA_DIR
85 chown postgres.postgres $POSTGRES_DATA_DIR
86 chmod 700 $POSTGRES_DATA_DIR
88 TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
89 initdb --pgdata=$POSTGRES_DATA_DIR \
90 -L /usr/share/postgresql"
93 msg_starting PostgreSQL
95 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
96 $(is_yes "$POSTGRES_QUIET" && echo '-s')";
97 POSTMASTER_OPTIONS=" \
98 $(is_yes "$POSTGRES_QUIET" && echo '-S') \
99 $(is_yes "$POSTGRES_DISABLE_FSYNC" && echo '-F') \
100 $(is_yes "$ALLOW_TCP_CONNECTIONS" && echo '-i') \
101 $(is_yes "$ALLOW_USE_SSL" && echo '-l')";
103 TMPDIR=/tmp su postgres -c "\
104 $(echo "/usr/bin/pg_ctl start $PGSQL_CMDLINE -l $POSTGRES_LOG") \
105 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
106 $(echo "2>&1 >/dev/null")";
108 out=`status postmaster`
109 if [ $? -eq 0 ]; then
116 touch /var/lock/subsys/postgresql
120 if [ ! -f /var/lock/subsys/postgresql ]; then
121 msg_Not_Running PostgreSQL
124 msg_stopping postgreSQL
126 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
127 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
128 out=`status postmaster`
129 if [ $? -eq 0 ]; then
136 rm -f /var/run/postmaster.pid
137 rm -f /var/lock/subsys/postgresql
140 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
141 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
148 if [ ! -f /var/lock/subsys/postgresql ]; then
149 msg_Not_Running PostgreSQL
152 msg_reloading postgreSQL
155 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
156 $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
157 POSTMASTER_OPTIONS=" \
158 $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
159 $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
160 $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
162 TMPDIR=/tmp su postgres -c "\
163 $(echo "/usr/bin/pg_ctl restart $PGSQL_CMDLINE -l $POSTGRES_LOG") \
164 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
165 $(echo "2>&1 >/dev/null")";
167 out=`status postmaster`
168 if [ $? -eq 0 ]; then
177 msg_Usage "$0 {start|stop|status|restart|reload}"