]> git.pld-linux.org Git - packages/postgresql.git/blame - postgresql.init
- updated to 7.1.3,
[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
12# pidfile: /var/run/postmaster.pid
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
a869aa78 25 POSTGRES_DATA_DIR=/var/lib/psql
53dd1abd 26 POSTGRES_LOG=/var/log/pgsql
03af0381 27fi
28
c35cc882 29# Check that networking is up.
95633833
JR
30if is_no "${NETWORKING}"; then
31 msg_Network_Down Postgresql
d584f4fd 32 exit 1
33fi
d29ea5e3 34
d29ea5e3 35# See how we were called.
36case "$1" in
37 start)
c35cc882 38 # Check if the service is already running?
53dd1abd 39 if [ -f /var/lock/subsys/postgresql ]; then
40 msg_Already_Running PostgreSQL
41 else
d4674174 42 # Sanity check
43 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
d4674174 44
45 # Check for the PGDATA structure
1884b875 46 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
d4674174 47 # Check version of existing PGDATA
cd89d644 48 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.1' ]; then
53dd1abd 49 show "Databases created under incompatibile version. Migrate them first."; fail
d4674174 50 exit 1
51 fi
52 else
53 # Create sample database
54 if [ ! -d $POSTGRES_DATA_DIR ]; then
55 mkdir -p $POSTGRES_DATA_DIR
56 chown postgres.postgres $POSTGRES_DATA_DIR
1884b875 57 chmod 700 $POSTGRES_DATA_DIR
d4674174 58 fi
02e6328b 59 TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
1884b875
JR
60 initdb --pgdata=$POSTGRES_DATA_DIR \
61 -L /usr/share/postgresql"
d4674174 62 fi
63
53dd1abd 64 msg_starting PostgreSQL
c35cc882 65 busy
1884b875 66 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
8e290e17 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')";
72
02e6328b 73 TMPDIR=/tmp su postgres -c "\
8e290e17 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")";
77
53dd1abd 78 out=`status postmaster`
79 if [ $? -eq 0 ]; then
80 deltext; ok
70825085 81 else
53dd1abd 82 deltext; fail
83 exit 1
70825085 84 fi
c35cc882 85 fi
d29ea5e3 86 touch /var/lock/subsys/postgresql
d29ea5e3 87 ;;
88 stop)
8e290e17 89
53dd1abd 90 if [ ! -f /var/lock/subsys/postgresql ]; then
91 msg_Not_Running PostgreSQL
92 exit 0
93 fi
94 msg_stopping postgreSQL
1884b875
JR
95 busy
96 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 97 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
53dd1abd 98 out=`status postmaster`
1884b875
JR
99 if [ $? -eq 0 ]; then
100 deltext; fail
101 echo -e "\n$out";
102 exit 1
103 else
104 deltext; ok
53dd1abd 105 fi
d29ea5e3 106 rm -f /var/run/postmaster.pid
107 rm -f /var/lock/subsys/postgresql
108 ;;
109 status)
1884b875 110 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 111 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
d29ea5e3 112 ;;
962e37bd
AM
113 restart)
114 $0 stop
115 $0 start
116 ;;
117 reload)
1884b875
JR
118 if [ ! -f /var/lock/subsys/postgresql ]; then
119 msg_Not_Running PostgreSQL
120 exit 0
121 fi
122 msg_reloading postgreSQL
123 busy
8e290e17 124
1884b875 125 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
8e290e17 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')";
131
02e6328b 132 TMPDIR=/tmp su postgres -c "\
8e290e17 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")";
136
1884b875
JR
137 out=`status postmaster`
138 if [ $? -eq 0 ]; then
139 deltext; ok
140 else
141 deltext; fail
142 echo -e "\n$out";
143 exit 1
144 fi
d29ea5e3 145 ;;
146 *)
95633833 147 msg_Usage "$0 {start|stop|status|restart|reload}"
d29ea5e3 148 exit 1
149esac
150
151exit 0
This page took 0.085497 seconds and 4 git commands to generate.