]> git.pld-linux.org Git - packages/postgresql.git/blob - postgresql.init
- adapterized, remaining pl translations, BuildRequires: automake
[packages/postgresql.git] / postgresql.init
1 #!/bin/sh
2 #
3 # postgresql    This is the init script for starting up the PostgreSQL
4 #               server
5 #
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
14 # Source function library
15 . /etc/rc.d/init.d/functions
16
17 # Get network config
18 . /etc/sysconfig/network
19
20 # Get service config
21 if [ -f /etc/sysconfig/postgresql ] ; then
22         . /etc/sysconfig/postgresql
23 else
24         ALLOW_TCP_CONNECTIONS=no
25         POSTGRES_DATA_DIR=/var/lib/psql
26         POSTGRES_LOG=/var/log/pgsql
27 fi
28
29 # Check that networking is up.
30 if is_no "${NETWORKING}"; then
31         msg_Network_Down Postgresql
32         exit 1
33 fi
34
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
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
44 else
45         # it's stoped. 
46         rm -f  /var/lock/subsys/postgresql
47 fi
48
49
50 # See how we were called.
51 case "$1" in
52   start)
53         # Check if the service is already running?
54         if [ -f /var/lock/subsys/postgresql ]; then
55                 msg_Already_Running PostgreSQL
56         else    
57                 # Sanity check
58                 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
59                 
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
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
72                         chmod 700 $POSTGRES_DATA_DIR
73                     fi
74                     TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
75                         initdb --pgdata=$POSTGRES_DATA_DIR \
76                         -L /usr/share/postgresql"
77                 fi
78                 
79                 msg_starting PostgreSQL 
80                 busy
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')";
87
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")";
92
93                 out=`status postmaster`
94                 if [ $? -eq 0 ]; then 
95                     deltext; ok
96                 else
97                     deltext; fail 
98                     exit 1      
99                 fi
100         fi
101         touch /var/lock/subsys/postgresql
102         ;;
103   stop)
104
105         if [ ! -f /var/lock/subsys/postgresql ]; then
106                 msg_Not_Running PostgreSQL
107                 exit 0  
108         fi
109         msg_stopping postgreSQL
110         busy
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
115                 deltext; fail
116                 echo -e "\n$out";
117                 exit 1
118         else
119                 deltext; ok
120         fi
121         rm -f /var/run/postmaster.pid
122         rm -f /var/lock/subsys/postgresql
123         ;;
124   status)
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"
127         ;;
128   restart)
129         $0 stop
130         $0 start
131         ;;
132   reload)
133         if [ ! -f /var/lock/subsys/postgresql ]; then
134                 msg_Not_Running PostgreSQL
135                 exit 0  
136         fi
137         msg_reloading postgreSQL
138         busy
139
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')";
146
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")";
151
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
160         ;;
161   *)
162         msg_Usage "$0 {start|stop|status|restart|reload}"
163         exit 1
164 esac
165
166 exit 0
This page took 0.042301 seconds and 4 git commands to generate.