]>
Commit | Line | Data |
---|---|---|
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 | 21 | if [ -f /etc/sysconfig/postgresql ] ; then |
22 | . /etc/sysconfig/postgresql | |
03af0381 | 23 | else |
b57548c1 | 24 | ALLOW_TCP_CONNECTIONS=no |
a869aa78 | 25 | POSTGRES_DATA_DIR=/var/lib/psql |
53dd1abd | 26 | POSTGRES_LOG=/var/log/pgsql |
03af0381 | 27 | fi |
28 | ||
c35cc882 | 29 | # Check that networking is up. |
95633833 JR |
30 | if is_no "${NETWORKING}"; then |
31 | msg_Network_Down Postgresql | |
d584f4fd | 32 | exit 1 |
33 | fi | |
d29ea5e3 | 34 | |
d29ea5e3 | 35 | # See how we were called. |
36 | case "$1" in | |
37 | start) | |
c35cc882 | 38 | # Check if the service is already running? |
53dd1abd | 39 | if [ -f /var/lock/subsys/postgresql ]; then |
40 | msg_Already_Running PostgreSQL | |
41 | else | |
d4674174 | 42 | # Sanity check |
43 | [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432 | |
d4674174 | 44 | |
45 | # Check for the PGDATA structure | |
46 | if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -d $POSTGRES_DATA_DIR/base/template1 ]; then | |
47 | # Check version of existing PGDATA | |
cd89d644 | 48 | if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.1' ]; then |
53dd1abd | 49 | show "Databases created under incompatibile version. Migrate them first."; fail |
d4674174 | 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 | fi | |
d4674174 | 58 | su postgres -c "LD_LIBRARY_PATH=/usr/lib \ |
1ed1579a | 59 | initdb --pgdata=$POSTGRES_DATA_DIR" |
d4674174 | 60 | fi |
61 | ||
53dd1abd | 62 | msg_starting PostgreSQL |
c35cc882 | 63 | busy |
53dd1abd | 64 | PGSQL_CMDLINE="$([ "$ALLOW_TCP_CONNECTIONS" = yes ] && echo "-i") \ |
65 | $([ -n "$MAX_NUM_BACKENDS" ] && echo "-N $MAX_NUM_BACKENDS") \ | |
66 | $([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \ | |
67 | $([ "$POSTGRES_QUIET". = yes. ] && echo '-o -Q') \ | |
a57096f6 | 68 | $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-o -F')"; |
53dd1abd | 69 | su postgres -c "/usr/bin/postmaster $PGSQL_CMDLINE >>$POSTGRES_LOG 2>&1 &" |
70 | out=`status postmaster` | |
71 | if [ $? -eq 0 ]; then | |
72 | deltext; ok | |
70825085 | 73 | else |
53dd1abd | 74 | deltext; fail |
75 | exit 1 | |
70825085 | 76 | fi |
c35cc882 | 77 | fi |
d29ea5e3 | 78 | touch /var/lock/subsys/postgresql |
d29ea5e3 | 79 | ;; |
80 | stop) | |
53dd1abd | 81 | if [ ! -f /var/lock/subsys/postgresql ]; then |
82 | msg_Not_Running PostgreSQL | |
83 | exit 0 | |
84 | fi | |
85 | msg_stopping postgreSQL | |
d29ea5e3 | 86 | killproc postmaster |
53dd1abd | 87 | out=`status postmaster` |
88 | if [ $? -eq 0 ]; then | |
89 | deltext; fail | |
90 | echo -e "\n$out"; | |
91 | exit 1 | |
92 | fi | |
93 | ||
d29ea5e3 | 94 | rm -f /var/run/postmaster.pid |
95 | rm -f /var/lock/subsys/postgresql | |
96 | ;; | |
97 | status) | |
98 | status postmaster | |
99 | ;; | |
c35cc882 | 100 | restart|reload) |
d29ea5e3 | 101 | $0 stop |
102 | $0 start | |
103 | ;; | |
104 | *) | |
95633833 | 105 | msg_Usage "$0 {start|stop|status|restart|reload}" |
d29ea5e3 | 106 | exit 1 |
107 | esac | |
108 | ||
109 | exit 0 |