File postgresql-init of Package postgresql
x
1
#!/bin/sh
2
# Copyright (c) 1995-2004 SUSE Linux AG, Nuernberg, Germany.
3
# All rights reserved.
4
#
5
# Author: Kurt Garloff
6
# Please send feedback to http://www.suse.de/feedback/
7
#
8
# /etc/init.d/postgresql
9
# and its symbolic link
10
# /(usr/)sbin/rcpostgresql
11
#
12
# This program is free software; you can redistribute it and/or modify
13
# it under the terms of the GNU General Public License as published by
14
# the Free Software Foundation; either version 2 of the License, or
15
# (at your option) any later version.
16
#
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
21
#
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
#
26
# System startup script for PostgreSQL
27
#
28
# LSB compatible service control script; see http://www.linuxbase.org/spec/
29
#
30
### BEGIN INIT INFO
31
# Provides: postgresql
32
# Required-Start: $network $remote_fs
33
# Required-Stop: $network $remote_fs
34
# Default-Start: 3 5
35
# Default-Stop:
36
# Description: Start the PostgreSQL master daemon
37
### END INIT INFO
38
39
# Source SuSE config
40
PG_SYSCONFIG=/etc/sysconfig/postgresql
41
test -f $PG_SYSCONFIG && . $PG_SYSCONFIG
42
43
# Shell functions sourced from /etc/rc.status:
44
# rc_check check and set local and overall rc status
45
# rc_status check and set local and overall rc status
46
# rc_status -v ditto but be verbose in local rc status
47
# rc_status -v -r ditto and clear the local rc status
48
# rc_failed set local and overall rc status to failed
49
# rc_reset clear local rc status (overall remains)
50
# rc_exit exit appropriate to overall rc status
51
. /etc/rc.status
52
53
eval DATADIR=${POSTGRES_DATADIR:-~postgres/data}
54
OPTIONS=${POSTGRES_OPTIONS}
55
H=/usr/bin/postmaster
56
test -x $H || exit 5
57
PIDFILE=$DATADIR/postmaster.pid
58
59
if [ -r $DATADIR/PG_VERSION ] ; then
60
BIN_VERSION=$($H --version|sed 's/.* \([0-9]\+\.[0-9]\+\).*/\1/')
61
DATA_VERSION=$(cat $DATADIR/PG_VERSION)
62
if [ "$BIN_VERSION" != "$DATA_VERSION" ]; then
63
for libdir in /usr/lib64 /usr/lib; do
64
H=$libdir/postgresql/backup/$DATA_VERSION/postmaster
65
test -x $H && break
66
done
67
if test -x $H; then
68
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$libdir/postgresql/backup"
69
echo " Your databases are still using the format of PostgreSQL $DATA_VERSION."
70
echo " Therefore a backup of the old PostgreSQL server program will be used"
71
echo " until you have saved and removed your old database files"
72
echo " See also /usr/share/doc/packages/postgresql/README.SuSE.{de,en} ."
73
else
74
echo " Your databases are still using the format of PostgreSQL $DATA_VERSION,"
75
echo " but no backup of the old PostgreSQL server program was found."
76
echo " See /usr/share/doc/packages/postgresql/README.SuSE.{en,de}"
77
echo " for details on updating PostgeSQL."
78
exit 5
79
fi
80
fi
81
fi
82
83
# The echo return value for success (defined in /etc/rc.config).
84
rc_reset
85
86
# Return values acc. to LSB for all commands but status:
87
# 0 - success
88
# 1 - generic or unspecified error
89
# 2 - invalid or excess argument(s)
90
# 3 - unimplemented feature (e.g. "reload")
91
# 4 - insufficient privilege
92
# 5 - program is not installed
93
# 6 - program is not configured
94
# 7 - program is not running
95
#
96
# Note that starting an already running service, stopping
97
# or restarting a not-running service as well as the restart
98
# with force-reload (in case signalling is not supported) are
99
# considered a success.
100
101
pg_ctl () {
102
CMD="/usr/bin/pg_ctl $@"
103
su - postgres -c "LD_LIBRARY_PATH=$LD_LIBRARY_PATH $CMD"
104
}
105
106
case "$1" in
107
start)
108
if [ ! -f $DATADIR/PG_VERSION ]; then
109
echo -n "Initializing the PostgreSQL database at location ${DATADIR}"
110
LANG_SYSCONFIG=/etc/sysconfig/language
111
test -f "$LANG_SYSCONFIG" && . $LANG_SYSCONFIG
112
LANG=${POSTGRES_LANG:-$RC_LANG}
113
INITDB=/usr/bin/initdb
114
install -d -o postgres -g postgres -m 700 ${DATADIR} && su - postgres -c \
115
"$INITDB --locale=$LANG --auth=\"ident sameuser\" $DATADIR &> initlog" ||
116
rc_failed
117
rc_status -v
118
rc_status || {
119
echo "You can find a log of the initialisation in ~postgres/initlog ."
120
rc_exit
121
}
122
fi
123
echo -n "Starting PostgreSQL"
124
## remove old socket, if it exists and no daemon is running.
125
checkproc -p $PIDFILE $H || {
126
rm -f /tmp/.s.PGSQL.5432 $PIDFILE
127
}
128
129
## Start daemon with startproc(8). If this fails
130
## the echo return value is set appropriate.
131
pg_ctl start -s -w -p $H -D $DATADIR -o "\"$OPTIONS\""
132
rc_status -v
133
;;
134
135
stop)
136
echo -n "Shutting down PostgreSQL"
137
## Stop daemon with killproc(8) and if this fails
138
## set the echo return value.
139
140
pg_ctl stop -s -D $DATADIR -m fast
141
rc_status -v
142
;;
143
144
try-restart)
145
## Stop the service and if this succeeds (i.e. the
146
## service was running before), start it again.
147
## Note: try-restart is not (yet) part of LSB (as of 0.7.5)
148
$0 status && $0 restart
149
;;
150
151
restart)
152
## Stop the service and regardless of whether it was
153
## running or not, start it again.
154
$0 stop
155
$0 start
156
rc_status
157
;;
158
159
force-reload | reload)
160
echo -n "Reloading configuration for PostgreSQL"
161
pg_ctl reload -s -D $DATADIR
162
rc_status -v
163
;;
164
165
status)
166
echo -n "Checking for PostgreSQL: "
167
## Check status with checkproc(8), if process is running
168
## checkproc will return with exit status 0.
169
170
# Status has a slightly different for the status command:
171
# 0 - service running
172
# 1 - service dead, but /var/run/ pid file exists
173
# 2 - service dead, but /var/lock/ lock file exists
174
# 3 - service not running
175
176
# NOTE: checkproc returns LSB compliant status values.
177
checkproc -p $PIDFILE $H
178
rc_status -v
179
;;
180
181
probe)
182
rc_failed 3
183
rc_status -v
184
;;
185
186
*)
187
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
188
exit 1
189
;;
190
esac
191
192
# Inform the caller not only verbosely and set an exit status.
193
rc_exit
194