]> git.pld-linux.org Git - packages/postgresql.git/blame - postgresql.init
- fixed postgresql.init, now will not show FAIL when succesfully started
[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
2a514bb5
SZ
25 ALLOW_USE_SSL=no
26 POSTGRES_DATA_DIR=/var/lib/pgsql
53dd1abd 27 POSTGRES_LOG=/var/log/pgsql
03af0381 28fi
29
c35cc882 30# Check that networking is up.
95633833
JR
31if is_no "${NETWORKING}"; then
32 msg_Network_Down Postgresql
d584f4fd 33 exit 1
34fi
d29ea5e3 35
15e46b8a 36# check if postmaster is realy alive
37if [ -f /var/lib/pgsql/postmaster.pid ]; then
38 if ps -p `head -1 /var/lib/pgsql/postmaster.pid` > /dev/null ; then
39 #ok. it's alive
40 echo > /dev/null;
41 else
42 # oh, it has crashed
43 rm -f /var/lock/subsys/postgresql
44 fi
45else
46 # it's stoped.
47 rm -f /var/lock/subsys/postgresql
48fi
49
50
d29ea5e3 51# See how we were called.
52case "$1" in
53 start)
c35cc882 54 # Check if the service is already running?
53dd1abd 55 if [ -f /var/lock/subsys/postgresql ]; then
56 msg_Already_Running PostgreSQL
57 else
2a514bb5
SZ
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"
61 exit 1
62 elif [ ! -f "$POSTGRES_DATA_DIR/server.key" ]; then
63 nls "$POSTGRES_DATA_DIR/server.key not found!"
64 exit 1
65 elif [ ! -f "$POSTGRES_DATA_DIR/server.crt" ]; then
66 nls "$POSTGRES_DATA_DIR/server.crt not found!"
67 exit 1
68 fi
69 fi
70
d4674174 71 # Sanity check
72 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
d4674174 73
74 # Check for the PGDATA structure
1884b875 75 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
d4674174 76 # Check version of existing PGDATA
cd89d644 77 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.1' ]; then
53dd1abd 78 show "Databases created under incompatibile version. Migrate them first."; fail
d4674174 79 exit 1
80 fi
81 else
82 # Create sample database
83 if [ ! -d $POSTGRES_DATA_DIR ]; then
84 mkdir -p $POSTGRES_DATA_DIR
85 chown postgres.postgres $POSTGRES_DATA_DIR
1884b875 86 chmod 700 $POSTGRES_DATA_DIR
d4674174 87 fi
02e6328b 88 TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
1884b875
JR
89 initdb --pgdata=$POSTGRES_DATA_DIR \
90 -L /usr/share/postgresql"
d4674174 91 fi
92
53dd1abd 93 msg_starting PostgreSQL
c35cc882 94 busy
1884b875 95 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
2a514bb5 96 $(is_yes "$POSTGRES_QUIET" && echo '-s')";
8e290e17 97 POSTMASTER_OPTIONS=" \
2a514bb5
SZ
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')";
8e290e17 102
02e6328b 103 TMPDIR=/tmp su postgres -c "\
8e290e17 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")";
107
53dd1abd 108 out=`status postmaster`
109 if [ $? -eq 0 ]; then
110 deltext; ok
70825085 111 else
53dd1abd 112 deltext; fail
113 exit 1
70825085 114 fi
c35cc882 115 fi
d29ea5e3 116 touch /var/lock/subsys/postgresql
d29ea5e3 117 ;;
118 stop)
8e290e17 119
53dd1abd 120 if [ ! -f /var/lock/subsys/postgresql ]; then
121 msg_Not_Running PostgreSQL
122 exit 0
123 fi
124 msg_stopping postgreSQL
1884b875
JR
125 busy
126 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 127 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
53dd1abd 128 out=`status postmaster`
1884b875
JR
129 if [ $? -eq 0 ]; then
130 deltext; fail
131 echo -e "\n$out";
132 exit 1
133 else
134 deltext; ok
53dd1abd 135 fi
d29ea5e3 136 rm -f /var/run/postmaster.pid
137 rm -f /var/lock/subsys/postgresql
138 ;;
139 status)
1884b875 140 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 141 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
d29ea5e3 142 ;;
962e37bd
AM
143 restart)
144 $0 stop
145 $0 start
146 ;;
147 reload)
1884b875
JR
148 if [ ! -f /var/lock/subsys/postgresql ]; then
149 msg_Not_Running PostgreSQL
150 exit 0
151 fi
152 msg_reloading postgreSQL
153 busy
8e290e17 154
1884b875 155 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
8e290e17 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')";
161
02e6328b 162 TMPDIR=/tmp su postgres -c "\
8e290e17 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")";
166
1884b875
JR
167 out=`status postmaster`
168 if [ $? -eq 0 ]; then
169 deltext; ok
170 else
171 deltext; fail
172 echo -e "\n$out";
173 exit 1
174 fi
d29ea5e3 175 ;;
176 *)
95633833 177 msg_Usage "$0 {start|stop|status|restart|reload}"
d29ea5e3 178 exit 1
179esac
180
181exit 0
This page took 0.112536 seconds and 4 git commands to generate.