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
25 POSTGRES_DATA_DIR=/var/lib/psql
26 POSTGRES_LOG=/var/log/pgsql
29 # Check that networking is up.
30 if is_no "${NETWORKING}"; then
31 msg_Network_Down Postgresql
35 # check if postmaster is realy alive
36 if [ -f /var/lib/pgsql/postmaster.pid ]; then
37 if ps -p `head -1 /var/lib/pgsql/postmaster.pid` > /dev/null ; then
42 rm -f /var/lock/subsys/postgresql
46 rm -f /var/lock/subsys/postgresql
50 # See how we were called.
53 # Check if the service is already running?
54 if [ -f /var/lock/subsys/postgresql ]; then
55 msg_Already_Running PostgreSQL
58 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
60 # Check for the PGDATA structure
61 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
62 # Check version of existing PGDATA
63 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.1' ]; then
64 show "Databases created under incompatibile version. Migrate them first."; fail
68 # Create sample database
69 if [ ! -d $POSTGRES_DATA_DIR ]; then
70 mkdir -p $POSTGRES_DATA_DIR
71 chown postgres.postgres $POSTGRES_DATA_DIR
72 chmod 700 $POSTGRES_DATA_DIR
74 TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
75 initdb --pgdata=$POSTGRES_DATA_DIR \
76 -L /usr/share/postgresql"
79 msg_starting PostgreSQL
81 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
82 $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
83 POSTMASTER_OPTIONS=" \
84 $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
85 $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
86 $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
88 TMPDIR=/tmp su postgres -c "\
89 $(echo "/usr/bin/pg_ctl start $PGSQL_CMDLINE -l $POSTGRES_LOG") \
90 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
91 $(echo "2>&1 >/dev/null")";
93 out=`status postmaster`
101 touch /var/lock/subsys/postgresql
105 if [ ! -f /var/lock/subsys/postgresql ]; then
106 msg_Not_Running PostgreSQL
109 msg_stopping postgreSQL
111 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
112 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
113 out=`status postmaster`
114 if [ $? -eq 0 ]; then
121 rm -f /var/run/postmaster.pid
122 rm -f /var/lock/subsys/postgresql
125 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
126 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
133 if [ ! -f /var/lock/subsys/postgresql ]; then
134 msg_Not_Running PostgreSQL
137 msg_reloading postgreSQL
140 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
141 $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
142 POSTMASTER_OPTIONS=" \
143 $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
144 $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
145 $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
147 TMPDIR=/tmp su postgres -c "\
148 $(echo "/usr/bin/pg_ctl restart $PGSQL_CMDLINE -l $POSTGRES_LOG") \
149 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
150 $(echo "2>&1 >/dev/null")";
152 out=`status postmaster`
153 if [ $? -eq 0 ]; then
162 msg_Usage "$0 {start|stop|status|restart|reload}"