]> git.pld-linux.org Git - packages/postgresql.git/blob - postgresql.init
- added encoding selection support
[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:      $POSTGRES_DATA_DIR/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         ALLOW_USE_SSL=no
26         POSTGRES_DATA_DIR=/var/lib/pgsql
27         POSTGRES_LOG=/var/log/pgsql
28         ENCODING=UNICODE
29 fi
30
31 # Check that networking is up.
32 if is_no "${NETWORKING}"; then
33         msg_network_down PostgreSQL
34         exit 1
35 fi
36
37 # check if postmaster is realy alive
38 if [ -f $POSTGRES_DATA_DIR/postmaster.pid ]; then
39     if ps -p `head -1 $POSTGRES_DATA_DIR/postmaster.pid` > /dev/null ; then
40         # ok. it's alive
41         echo > /dev/null;
42     else
43         # oh, it has crashed
44         rm -f  /var/lock/subsys/postgresql
45     fi
46 else
47         # it's stopped.
48         rm -f  /var/lock/subsys/postgresql
49 fi
50
51
52 # See how we were called.
53 case "$1" in
54   start)
55         # Check if the service is already running?
56         if [ -f /var/lock/subsys/postgresql ]; then
57                 msg_already_running PostgreSQL
58         else    
59                 if is_yes "$ALLOW_USE_SSL"; then
60                         if is_no "$ALLOW_TCP_CONNECTIONS"; then
61                                 nls "You must enable ALLOW_TCP_CONNECTIONS in order to use SSL"
62                                 exit 1
63                         elif [ ! -f "$POSTGRES_DATA_DIR/server.key" ]; then
64                                 nls "$POSTGRES_DATA_DIR/server.key not found!"
65                                 exit 1
66                         elif [ ! -f "$POSTGRES_DATA_DIR/server.crt" ]; then
67                                 nls "$POSTGRES_DATA_DIR/server.crt not found!"
68                                 exit 1
69                         fi
70                 fi
71                 
72                 # Sanity check
73                 [ -e /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
74                 [ -f /tmp/.s.PGSQL.5432.lock ] || rm -f /tmp/.s.PGSQL.5432.lock
75                 
76                 # Check for the PGDATA structure
77                 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
78                     # Check version of existing PGDATA
79                     if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.2' ]; then
80                         show "Databases created under incompatibile version. Migrate them first."; fail
81                         exit 1
82                     fi
83                 else
84                     # Create sample database
85                     if [ ! -d $POSTGRES_DATA_DIR ]; then
86                         mkdir -p $POSTGRES_DATA_DIR
87                         chown postgres.postgres $POSTGRES_DATA_DIR
88                         chmod 700 $POSTGRES_DATA_DIR
89                     fi
90                     TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
91                         initdb --pgdata=$POSTGRES_DATA_DIR \
92                         -L /usr/share/postgresql -E $ENCODING"
93                 fi
94                 
95                 msg_starting PostgreSQL 
96                 busy
97                 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
98                     $(is_yes "$POSTGRES_QUIET" && echo '-s')";
99                 POSTMASTER_OPTIONS=" \
100                     $(is_yes "$POSTGRES_QUIET" && echo '-S') \
101                     $(is_yes "$POSTGRES_DISABLE_FSYNC" && echo '-F') \
102                     $(is_yes "$ALLOW_TCP_CONNECTIONS" && echo '-i') \
103                     $(is_yes "$ALLOW_USE_SSL" && echo '-l') \
104                     $([ "$BUFFERS" ] && echo \-B $BUFFERS) \
105                     $([ "$MAXCONN" ] && echo \-N $MAXCONN)";
106
107                 TMPDIR=/tmp su postgres -c "\
108                         $(echo "/usr/bin/pg_ctl start -w $PGSQL_CMDLINE -l $POSTGRES_LOG") \
109                         $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
110                         $(echo "2>&1 >/dev/null")";
111                 
112                 out=`status postmaster`
113                 if [ $? -eq 0 ]; then 
114                     deltext; ok
115                 else
116                     deltext; fail 
117                     exit 1      
118                 fi
119         fi
120         touch /var/lock/subsys/postgresql
121         ;;
122   stop)
123
124         if [ ! -f /var/lock/subsys/postgresql ]; then
125                 msg_not_running PostgreSQL
126                 exit 0  
127         fi
128         msg_stopping PostgreSQL
129         busy
130         PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
131         TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
132         out=`status postmaster`
133         if [ $? -eq 0 ]; then
134                 deltext; fail
135                 echo -e "\n$out";
136                 exit 1
137         else
138                 deltext; ok
139         fi
140         rm -f $POSTGRES_DATA_DIR/postmaster.pid
141         rm -f /var/lock/subsys/postgresql
142         ;;
143   status)
144         PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
145         TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
146         ;;
147   restart)
148         $0 stop
149         $0 start
150         ;;
151   reload)
152         if [ ! -f /var/lock/subsys/postgresql ]; then
153                 msg_not_running PostgreSQL
154                 exit 0  
155         fi
156         msg_reloading PostgreSQL
157         busy
158
159         PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
160             $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
161         POSTMASTER_OPTIONS=" \
162             $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
163             $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
164             $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
165
166         TMPDIR=/tmp su postgres -c "\
167                 $(echo "/usr/bin/pg_ctl restart $PGSQL_CMDLINE -l $POSTGRES_LOG") \
168                 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
169                 $(echo "2>&1 >/dev/null")";
170
171         out=`status postmaster`
172         if [ $? -eq 0 ]; then
173                 deltext; ok
174         else
175                 deltext; fail
176                 echo -e "\n$out";
177                 exit 1
178         fi
179         ;;
180   *)
181         msg_usage "$0 {start|stop|status|restart|reload}"
182         exit 1
183 esac
184
185 exit 0
This page took 0.123429 seconds and 4 git commands to generate.