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 # See how we were called.
38 # Check if the service is already running?
39 if [ -f /var/lock/subsys/postgresql ]; then
40 msg_Already_Running PostgreSQL
43 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
45 # Check for the PGDATA structure
46 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
47 # Check version of existing PGDATA
48 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.1' ]; then
49 show "Databases created under incompatibile version. Migrate them first."; fail
53 # Create sample database
54 if [ ! -d $POSTGRES_DATA_DIR ]; then
55 mkdir -p $POSTGRES_DATA_DIR
56 chown postgres.postgres $POSTGRES_DATA_DIR
57 chmod 700 $POSTGRES_DATA_DIR
59 TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
60 initdb --pgdata=$POSTGRES_DATA_DIR \
61 -L /usr/share/postgresql"
64 msg_starting PostgreSQL
66 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
67 $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
68 POSTMASTER_OPTIONS=" \
69 $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
70 $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
71 $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
73 TMPDIR=/tmp su postgres -c "\
74 $(echo "/usr/bin/pg_ctl start $PGSQL_CMDLINE -l $POSTGRES_LOG") \
75 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
76 $(echo "2>&1 >/dev/null")";
78 out=`status postmaster`
86 touch /var/lock/subsys/postgresql
90 if [ ! -f /var/lock/subsys/postgresql ]; then
91 msg_Not_Running PostgreSQL
94 msg_stopping postgreSQL
96 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
97 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
98 out=`status postmaster`
106 rm -f /var/run/postmaster.pid
107 rm -f /var/lock/subsys/postgresql
110 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
111 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
118 if [ ! -f /var/lock/subsys/postgresql ]; then
119 msg_Not_Running PostgreSQL
122 msg_reloading postgreSQL
125 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
126 $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
127 POSTMASTER_OPTIONS=" \
128 $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
129 $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
130 $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
132 TMPDIR=/tmp su postgres -c "\
133 $(echo "/usr/bin/pg_ctl restart $PGSQL_CMDLINE -l $POSTGRES_LOG") \
134 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
135 $(echo "2>&1 >/dev/null")";
137 out=`status postmaster`
138 if [ $? -eq 0 ]; then
147 msg_Usage "$0 {start|stop|status|restart|reload}"