]> git.pld-linux.org Git - packages/postgresql.git/blame - postgresql.init
- adapterized, remaining pl translations, BuildRequires: automake
[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
15e46b8a 35# check if postmaster is realy alive
36if [ -f /var/lib/pgsql/postmaster.pid ]; then
37 if ps -p `head -1 /var/lib/pgsql/postmaster.pid` > /dev/null ; then
38 #ok. it's alive
39 echo > /dev/null;
40 else
41 # oh, it has crashed
42 rm -f /var/lock/subsys/postgresql
43 fi
44else
45 # it's stoped.
46 rm -f /var/lock/subsys/postgresql
47fi
48
49
d29ea5e3 50# See how we were called.
51case "$1" in
52 start)
c35cc882 53 # Check if the service is already running?
53dd1abd 54 if [ -f /var/lock/subsys/postgresql ]; then
55 msg_Already_Running PostgreSQL
56 else
d4674174 57 # Sanity check
58 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
d4674174 59
60 # Check for the PGDATA structure
1884b875 61 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
d4674174 62 # Check version of existing PGDATA
cd89d644 63 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.1' ]; then
53dd1abd 64 show "Databases created under incompatibile version. Migrate them first."; fail
d4674174 65 exit 1
66 fi
67 else
68 # Create sample database
69 if [ ! -d $POSTGRES_DATA_DIR ]; then
70 mkdir -p $POSTGRES_DATA_DIR
71 chown postgres.postgres $POSTGRES_DATA_DIR
1884b875 72 chmod 700 $POSTGRES_DATA_DIR
d4674174 73 fi
02e6328b 74 TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
1884b875
JR
75 initdb --pgdata=$POSTGRES_DATA_DIR \
76 -L /usr/share/postgresql"
d4674174 77 fi
78
53dd1abd 79 msg_starting PostgreSQL
c35cc882 80 busy
1884b875 81 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
8e290e17 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')";
87
02e6328b 88 TMPDIR=/tmp su postgres -c "\
8e290e17 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")";
92
53dd1abd 93 out=`status postmaster`
94 if [ $? -eq 0 ]; then
95 deltext; ok
70825085 96 else
53dd1abd 97 deltext; fail
98 exit 1
70825085 99 fi
c35cc882 100 fi
d29ea5e3 101 touch /var/lock/subsys/postgresql
d29ea5e3 102 ;;
103 stop)
8e290e17 104
53dd1abd 105 if [ ! -f /var/lock/subsys/postgresql ]; then
106 msg_Not_Running PostgreSQL
107 exit 0
108 fi
109 msg_stopping postgreSQL
1884b875
JR
110 busy
111 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 112 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
53dd1abd 113 out=`status postmaster`
1884b875
JR
114 if [ $? -eq 0 ]; then
115 deltext; fail
116 echo -e "\n$out";
117 exit 1
118 else
119 deltext; ok
53dd1abd 120 fi
d29ea5e3 121 rm -f /var/run/postmaster.pid
122 rm -f /var/lock/subsys/postgresql
123 ;;
124 status)
1884b875 125 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
02e6328b 126 TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
d29ea5e3 127 ;;
962e37bd
AM
128 restart)
129 $0 stop
130 $0 start
131 ;;
132 reload)
1884b875
JR
133 if [ ! -f /var/lock/subsys/postgresql ]; then
134 msg_Not_Running PostgreSQL
135 exit 0
136 fi
137 msg_reloading postgreSQL
138 busy
8e290e17 139
1884b875 140 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
8e290e17 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')";
146
02e6328b 147 TMPDIR=/tmp su postgres -c "\
8e290e17 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")";
151
1884b875
JR
152 out=`status postmaster`
153 if [ $? -eq 0 ]; then
154 deltext; ok
155 else
156 deltext; fail
157 echo -e "\n$out";
158 exit 1
159 fi
d29ea5e3 160 ;;
161 *)
95633833 162 msg_Usage "$0 {start|stop|status|restart|reload}"
d29ea5e3 163 exit 1
164esac
165
166exit 0
This page took 0.386466 seconds and 4 git commands to generate.