]> git.pld-linux.org Git - packages/postgresql.git/blob - postgresql.init
- updated to 7.1.x
[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 # See how we were called.
36 case "$1" in
37   start)
38         # Check if the service is already running?
39         if [ -f /var/lock/subsys/postgresql ]; then
40                 msg_Already_Running PostgreSQL
41         else    
42                 # Sanity check
43                 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
44                 
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
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
57                         chmod 700 $POSTGRES_DATA_DIR
58                     fi
59                     su postgres -c "LD_LIBRARY_PATH=/usr/lib \
60                         initdb --pgdata=$POSTGRES_DATA_DIR \
61                         -L /usr/share/postgresql"
62                 fi
63                 
64                 msg_starting PostgreSQL 
65                 busy
66                 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
67                     $([ "$POSTGRES_QUIET". = yes. ] && echo '-s -o -S') \
68                     $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-o -F')";
69                 su postgres -c "/usr/bin/pg_ctl start $PGSQL_CMDLINE -l $POSTGRES_LOG 2>&1 >/dev/null"
70                 out=`status postmaster`
71                 if [ $? -eq 0 ]; then 
72                     deltext; ok
73                 else
74                     deltext; fail 
75                     exit 1      
76                 fi
77         fi
78         touch /var/lock/subsys/postgresql
79         ;;
80   stop)
81         if [ ! -f /var/lock/subsys/postgresql ]; then
82                 msg_Not_Running PostgreSQL
83                 exit 0  
84         fi
85         msg_stopping postgreSQL
86         busy
87         PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
88         su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
89         out=`status postmaster`
90         if [ $? -eq 0 ]; then
91                 deltext; fail
92                 echo -e "\n$out";
93                 exit 1
94         else
95                 deltext; ok
96         fi
97         rm -f /var/run/postmaster.pid
98         rm -f /var/lock/subsys/postgresql
99         ;;
100   status)
101         PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
102         su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
103         ;;
104   restart|reload)
105         if [ ! -f /var/lock/subsys/postgresql ]; then
106                 msg_Not_Running PostgreSQL
107                 exit 0  
108         fi
109         msg_reloading postgreSQL
110         busy
111         PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
112                 $([ "$POSTGRES_QUIET". = yes. ] && echo '-s -o -S') \
113                 $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-o -F')";
114         su postgres -c "/usr/bin/pg_ctl restart $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
115         out=`status postmaster`
116         if [ $? -eq 0 ]; then
117                 deltext; ok
118         else
119                 deltext; fail
120                 echo -e "\n$out";
121                 exit 1
122         fi
123         ;;
124   *)
125         msg_Usage "$0 {start|stop|status|restart|reload}"
126         exit 1
127 esac
128
129 exit 0
This page took 0.066107 seconds and 4 git commands to generate.