1 |
commit: 4795d6dffdd82a8948ff95d39ec23266094d983c |
2 |
Author: Aaron W. Swenson <titanofold <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Nov 30 13:50:33 2011 +0000 |
4 |
Commit: Aaron Swenson <titanofold <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Nov 30 13:50:33 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pgsql-patches.git;a=commit;h=4795d6df |
7 |
|
8 |
Move to start-stop-daemon. Create run directory if it doesn't exist. |
9 |
Parse postgresql.conf for port, unix_socket_directory, and |
10 |
log_destination allowing postgresql.conf to override |
11 |
/etc/conf.d/postgresql. |
12 |
|
13 |
--- |
14 |
postgresql.init | 165 +++++++++++++++++-------------------------------------- |
15 |
1 files changed, 50 insertions(+), 115 deletions(-) |
16 |
|
17 |
diff --git a/postgresql.init b/postgresql.init |
18 |
index fa0f90c..a00c9c9 100644 |
19 |
--- a/postgresql.init |
20 |
+++ b/postgresql.init |
21 |
@@ -3,19 +3,33 @@ |
22 |
# Distributed under the terms of the GNU General Public License v2 |
23 |
# $Header: $ |
24 |
|
25 |
-opts="${opts} reload" |
26 |
+extra_started_command="reload" |
27 |
+ |
28 |
+get_config() { |
29 |
+ [ -f ${PGDATA}/postgresql.conf ] || return 1 |
30 |
+ |
31 |
+ eval echo $(sed -e 's:#.*::' ${PGDATA}/postgresql.conf | awk '$1 == "'$1'" { print $2 == "=" ? $3 : $2 }') |
32 |
+} |
33 |
|
34 |
depend() { |
35 |
- use net |
36 |
- provide postgresql |
37 |
- provide postgresql-@SLOT@ |
38 |
+ use net |
39 |
+ provide postgresql |
40 |
+ |
41 |
+ if [ "$(get_config log_destination)" = "syslog" ]; then |
42 |
+ use logger |
43 |
+ fi |
44 |
} |
45 |
|
46 |
+configured_port=$(get_config port) |
47 |
+: ${configured_port:=${PGPORT}} |
48 |
+socket_path=$(get_config unix_socket_path) |
49 |
+: ${socket_path:=@RUNDIR@/run/postgresql} |
50 |
+ |
51 |
checkconfig() { |
52 |
# Check that DATA_DIR has been set and exists |
53 |
if [ -z ${DATA_DIR} ] ; then |
54 |
eerror "DATA_DIR not set" |
55 |
- eerror "HINT: Did you not update /etc/conf.d/postgresql-@SLOT@" |
56 |
+ eerror "HINT: Perhaps you need to update /etc/conf.d/postgresql-@SLOT@" |
57 |
fi |
58 |
if [ ! -d ${DATA_DIR} ] ; then |
59 |
eerror "Directory not found: ${DATA_DIR}" |
60 |
@@ -32,10 +46,11 @@ checkconfig() { |
61 |
[ ! -f ${PGDATA}/postgresql.conf ] && eerror " postgresql.conf" |
62 |
[ ! -f ${PGDATA}/pg_hba.conf ] && eerror " pg_hba.conf" |
63 |
[ ! -f ${PGDATA}/pg_ident.conf ] && eerror " pg_ident.conf" |
64 |
- eerror "HINT: Try:" |
65 |
- eerror "mv ${DATA_DIR}/*.conf ${PGDATA}" |
66 |
+ eerror "HINT: Try:" |
67 |
+ eerror " mv ${DATA_DIR}/*.conf ${PGDATA}" |
68 |
return 1 |
69 |
fi |
70 |
+ |
71 |
local file |
72 |
local failed |
73 |
for file in pg_hba pg_ident postgresql ; do |
74 |
@@ -52,15 +67,11 @@ checkconfig() { |
75 |
return 1 |
76 |
fi |
77 |
|
78 |
- # Ensures @RUN@ exists for those who have it on tmpfs. |
79 |
- if [ ! -d @RUN@ ] ; then |
80 |
- mkdir -p @RUN@ |
81 |
- chown postgres:postgres @RUN@ |
82 |
- fi |
83 |
- if [ -e @RUN@/.s.PGSQL.${PGPORT} ] ; then |
84 |
- eerror "Socket conflict." |
85 |
+ checkpath -d -m 0770 -o postgres:postgres ${socket_path} |
86 |
+ if [ -e ${socket_path}/.s.PGSQL.${configured_port} ] ; then |
87 |
+ eerror "Socket conflict." |
88 |
eerror "A server is already listening on:" |
89 |
- eerror " @RUN@/.s.PGSQL.${PGPORT}" |
90 |
+ eerror " ${socket_path}/.s.PGSQL.${configured_port}" |
91 |
eerror "HINT: Change PGPORT to listen on a different socket." |
92 |
return 1 |
93 |
fi |
94 |
@@ -71,17 +82,17 @@ start() { |
95 |
|
96 |
ebegin "Starting PostgreSQL" |
97 |
|
98 |
- if [ -f ${DATA_DIR}/postmaster.pid ] ; then |
99 |
- rm -f ${DATA_DIR}/postmaster.pid |
100 |
- fi |
101 |
+ rm -f ${DATA_DIR}/postmaster.pid |
102 |
|
103 |
local retval |
104 |
|
105 |
- su -l postgres \ |
106 |
- -c "env PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} \ |
107 |
- /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ |
108 |
- start ${WAIT_FOR_START} -t ${START_TIMEOUT} -s -D ${DATA_DIR} \ |
109 |
- -o '-D ${PGDATA} --data-directory=${DATA_DIR} --silent-mode=true ${PGOPTS}'" |
110 |
+ start-stop-daemon --start \ |
111 |
+ --user postgres \ |
112 |
+ --exec /usr/lib/postgresql-@SLOT@/bin/postgres \ |
113 |
+ --env "PGPORT=${configured_port} ${PG_EXTRA_ENV}" \ |
114 |
+ --wait $((${START_TIMEOUT}*1000)) \ |
115 |
+ --pidfile ${DATA_DIR}/postmaster.pid \ |
116 |
+ -- -D ${PGDATA} --data-directory=${DATA_DIR} --silent-mode=true ${PGOPTS} |
117 |
retval=$? |
118 |
|
119 |
if [ $retval -ne 0 ] ; then |
120 |
@@ -90,112 +101,36 @@ start() { |
121 |
return $retval |
122 |
fi |
123 |
|
124 |
- # The following is to catch the case of an already running server |
125 |
- # in which pg_ctl doesn't know to which server it connected to and |
126 |
- # falsely reports the server as 'up' |
127 |
- if [ ! -f ${DATA_DIR}/postmaster.pid ] ; then |
128 |
- eerror "The PID file doesn't exist but pg_ctl reported a running server." |
129 |
- eerror "Please check whether there is another server running on the same port or read the log-file." |
130 |
- eend 1 |
131 |
- return 1 |
132 |
- fi |
133 |
- |
134 |
eend $retval |
135 |
} |
136 |
|
137 |
stop() { |
138 |
- ebegin "Stopping PostgreSQL (this can take up to $(( ${NICE_TIMEOUT} + ${RUDE_TIMEOUT} + ${FORCE_TIMEOUT} )) seconds)" |
139 |
+ local seconds=$(( ${NICE_TIMEOUT} + ${RUDE_TIMEOUT} + ${FORCE_TIMEOUT} )) |
140 |
+ ebegin "Stopping PostgreSQL (this can take up to ${seconds} seconds)" |
141 |
|
142 |
local retval |
143 |
- |
144 |
- if [ "${NICE_QUIT}" != "NO" ] ; then |
145 |
- su -l postgres \ |
146 |
- -c "env PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} \ |
147 |
- /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ |
148 |
- stop ${WAIT_FOR_STOP} -t ${NICE_TIMEOUT} -s -D ${DATA_DIR} \ |
149 |
- -m smart" |
150 |
- retval=$? |
151 |
- |
152 |
- if [ $retval -eq 0 ] ; then |
153 |
- eend $retval |
154 |
- return $retval |
155 |
- fi |
156 |
- |
157 |
- ewarn "Shutting down the server gracefully failed." |
158 |
- ewarn "Probably because some clients did not disconnect within ${NICE_TIMEOUT} seconds." |
159 |
- else |
160 |
- ewarn "NICE_QUIT disabled." |
161 |
- ewarn "You really should have it enabled." |
162 |
- fi |
163 |
+ local retries=SIGTERM/$((${NICE_TIMEOUT}*1000)) |
164 |
|
165 |
if [ "${RUDE_QUIT}" != "NO" ] ; then |
166 |
- ewarn "RUDE_QUIT enabled." |
167 |
- ewarn "Going to shutdown the server anyway." |
168 |
- |
169 |
- su -l postgres \ |
170 |
- -c "env PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} \ |
171 |
- /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ |
172 |
- stop ${WAIT_FOR_STOP} -t ${RUDE_TIMEOUT} -s -D ${DATA_DIR} \ |
173 |
- -m fast" |
174 |
- retval=$? |
175 |
- |
176 |
- if [ $retval -eq 0 ] ; then |
177 |
- eend $retval |
178 |
- return $retval |
179 |
- fi |
180 |
- |
181 |
- eerror "Failed to shutdown server." |
182 |
- else |
183 |
- ewarn "RUDE_QUIT disabled." |
184 |
+ einfo "RUDE_QUIT enabled." |
185 |
+ retries="${retries}/SIGINT/$((${RUDE_TIMEOUT}*1000))" |
186 |
fi |
187 |
- |
188 |
if [ "${FORCE_QUIT}" = "YES" ] ; then |
189 |
- ewarn "FORCE_QUIT enabled." |
190 |
- ewarn "Forcing server to shutdown." |
191 |
- ewarn "A recover-run will be executed on the next startup." |
192 |
- |
193 |
- su -l postgres \ |
194 |
- -c "env PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} \ |
195 |
- /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ |
196 |
- stop ${WAIT_FOR_STOP} -t ${FORCE_TIMEOUT} -s -D ${DATA_DIR} \ |
197 |
- -m immediate" |
198 |
- |
199 |
- retval=$? |
200 |
- |
201 |
- if [ $retval -eq 0 ] ; then |
202 |
- ewarn "Server forced down." |
203 |
- eend $retval |
204 |
- return $retval |
205 |
- fi |
206 |
- |
207 |
- eerror "Forced shutdown failed!!!" |
208 |
- eerror "Something is wrong with your system." |
209 |
- eerror "Please take care of it manually." |
210 |
- eerror "Unable to stop server." |
211 |
- eend $retval |
212 |
- return $retval |
213 |
- else |
214 |
- ewarn "FORCE_QUIT disabled." |
215 |
- eerror "Unable to shutdown server." |
216 |
- eend 1 |
217 |
- return 1 |
218 |
+ einfo "FORCE_QUIT enabled." |
219 |
+ ewarn "A recover-run might be executed on next startup." |
220 |
+ retries="${retries}/SIGQUIT/$((${FORCE_TIMEOUT}*1000))" |
221 |
fi |
222 |
-} |
223 |
|
224 |
-reload() { |
225 |
- ebegin "Reloading PostgreSQL configuration" |
226 |
- su -l postgres \ |
227 |
- -c "env PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} \ |
228 |
- /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ |
229 |
- reload -s -D ${DATA_DIR}" |
230 |
- eend $? |
231 |
+ start-stop-daemon --stop \ |
232 |
+ --exec /usr/lib/postgresql-@SLOT@/bin/postgres \ |
233 |
+ --retry ${retries} \ |
234 |
+ --pidfile ${DATA_DIR}/postmaster.pid |
235 |
+ |
236 |
+ eend |
237 |
} |
238 |
|
239 |
-status() { |
240 |
+reload() { |
241 |
ebegin "Reloading PostgreSQL configuration" |
242 |
- su -l postgres \ |
243 |
- -c "env PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} \ |
244 |
- /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ |
245 |
- status -D ${DATA_DIR}" |
246 |
+ kill -HUP $(head -n1 ${DATA_DIR}/postmaster.pid) |
247 |
eend $? |
248 |
} |