Gentoo Archives: gentoo-commits

From: Lars Wendler <polynomial-c@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/apache:master commit in: 2.4/scripts/
Date: Tue, 02 Apr 2019 08:39:53
Message-Id: 1554194352.fcc7da95dd75910085a8c688b8ec5d25ba11bd1e.polynomial-c@gentoo
1 commit: fcc7da95dd75910085a8c688b8ec5d25ba11bd1e
2 Author: Lars Wendler <polynomial-c <AT> gentoo <DOT> org>
3 AuthorDate: Tue Apr 2 08:31:45 2019 +0000
4 Commit: Lars Wendler <polynomial-c <AT> gentoo <DOT> org>
5 CommitDate: Tue Apr 2 08:39:12 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/apache.git/commit/?id=fcc7da95
7
8 Several fixes to previous apache2ctl systemd enhancement
9
10 - Attempt to keep the script POSIX sh compliant
11 - Don't use "function" prefix
12 - Use curly braces for variables
13 - Fixed indentation
14 - Put code for systemd into an "else" part
15 - Renamed "ERROR" variable to "retval"
16 - Made some variables local
17 - Put the systemd apache2 service file reference into a variable
18
19 Bug: https://bugs.gentoo.org/673530
20 Signed-off-by: Lars Wendler <polynomial-c <AT> gentoo.org>
21
22 2.4/scripts/apache2ctl | 198 ++++++++++++++++++++++++-------------------------
23 1 file changed, 97 insertions(+), 101 deletions(-)
24
25 diff --git a/2.4/scripts/apache2ctl b/2.4/scripts/apache2ctl
26 index 392ac4c..55975d4 100644
27 --- a/2.4/scripts/apache2ctl
28 +++ b/2.4/scripts/apache2ctl
29 @@ -1,18 +1,18 @@
30 #!/bin/sh
31
32 APACHE2="/usr/sbin/apache2"
33 -APACHE_OPTS=""
34 +APACHE2_OPTS=""
35 APACHE_RC_CONF="/etc/conf.d/apache2"
36 # List of init script verbs that should be passed forward
37 RC_VERBS="start stop restart checkconfd configtest modules virtualhosts configdump fullstatus graceful gracefulstop reload"
38
39
40 -function is_systemd() {
41 - [ $(ps --no-headers -o comm 1) == "systemd" ] && return 0
42 +is_systemd() {
43 + [ $(ps -o comm= 1) = "systemd" ] && return 0
44 return 1
45 }
46
47 -function load_rc_config() {
48 +load_rc_config() {
49 [ -f "${APACHE_RC_CONF}" ] || return 1
50 if ! grep -q '^[[:space:]]*APACHE2_OPTS' ${APACHE_RC_CONF} ; then
51 echo "Cannot find APACHE2_OPTS in ${APACHE_RC_CONF}"
52 @@ -20,12 +20,12 @@ function load_rc_config() {
53 fi
54 . ${APACHE_RC_CONF}
55 export APACHE2_OPTS
56 - export SERVERROOT="${SERVERROOT:-/usr/lib64/apache2}"
57 + export SERVERROOT="${SERVERROOT:-/usr/@LIBDIR@/apache2}"
58 export CONFIGFILE="${CONFIGFILE:-/etc/apache2/httpd.conf}"
59 }
60
61 # Basically the code from '/etc/init.d/apache2::reload()', updated to run without open-rc
62 -function reload() {
63 +reload() {
64 RELOAD_TYPE="${RELOAD_TYPE:-graceful}"
65
66 if [ "${RELOAD_TYPE}" = "restart" ]; then
67 @@ -33,12 +33,12 @@ function reload() {
68 elif [ "${RELOAD_TYPE}" = "graceful" ]; then
69 ${APACHE2} ${APACHE2_OPTS} -k graceful
70 else
71 - echo "${RELOAD_TYPE} is not a valid RELOAD_TYPE. Please edit /etc/conf.d/apache2"
72 + echo "${RELOAD_TYPE} is not a valid RELOAD_TYPE. Please edit ${APACHE_RC_CONF}"
73 fi
74 }
75
76 # Basically the code from '/etc/init.d/apache2::fullstatus()', updated to run without open-rc
77 -function fullstatus() {
78 +fullstatus() {
79 LYNX="${LYNX:-lynx -dump}"
80 STATUSURL="${STATUSURL:-http://localhost/server-status}"
81
82 @@ -51,35 +51,37 @@ function fullstatus() {
83 }
84
85 # Basically the code from '/etc/init.d/apache2::checkconfd()', updated to run without open-rc
86 -function checkconfd() {
87 - if [ ! -d ${SERVERROOT} ]; then
88 +checkconfd() {
89 + if [ ! -d "${SERVERROOT}" ]; then
90 echo "SERVERROOT does not exist: ${SERVERROOT}"
91 return 1
92 fi
93 }
94
95 # Basically the code from '/etc/init.d/apache2::checkconfig()', updated to run without open-rc
96 -function configtest() {
97 +configtest() {
98 checkconfd || return 1
99
100 - OUTPUT=$( ${APACHE2} ${APACHE2_OPTS} -t 2>&1 )
101 + local ret
102 + OUTPUT="$(${APACHE2} ${APACHE2_OPTS} -t 2>&1)"
103 ret=$?
104 - if [ $ret -ne 0 ]; then
105 + if [ ${ret} -ne 0 ]; then
106 echo "apache2 has detected an error in your setup:"
107 printf "%s\n" "${OUTPUT}"
108 fi
109
110 - return $ret
111 + return ${ret}
112 }
113
114 # Basically the code from '/etc/init.d/apache2::configdump()', updated to run without open-rc
115 -function configdump() {
116 +configdump() {
117 INFOURL="${INFOURL:-http://localhost/server-info}"
118
119 - if ! command -v $(set -- ${LYNX}; echo $1) 2>&1 >/dev/null; then
120 + if ! command -v $(set -- ${LYNX}; echo ${1}) 2>&1 >/dev/null; then
121 echo "lynx not found! you need to emerge www-client/lynx"
122 else
123 echo "${APACHE2} started with '${APACHE2_OPTS}'"
124 + local i
125 for i in config server list; do
126 ${LYNX} "${INFOURL}/?${i}" | sed '/Apache Server Information/d;/^[[:space:]]\+[_]\+$/Q'
127 done
128 @@ -87,90 +89,84 @@ function configdump() {
129 }
130
131
132 -# If systemd IS NOT detected, run the legacy apache2ctl code
133 if ! is_systemd; then
134 - # If first parameter is a verb defined in $RC_VERBS, pass the command to init script.
135 - # In other cases, compile command line and run the command on apache binary.
136 - if echo "${RC_VERBS}" | grep -q -- "${1}" ; then
137 - exec /etc/init.d/apache2 "${@}"
138 - else
139 - load_rc_config || exit 1
140 - ${APACHE2} ${APACHE2_OPTS} -d ${SERVERROOT} -f ${CONFIGFILE} "${@}"
141 - fi
142 - exit 0
143 + # If systemd IS NOT detected, run the legacy apache2ctl code
144 +
145 + # If first parameter is a verb defined in $RC_VERBS, pass the command to init script.
146 + # In other cases, compile command line and run the command on apache binary.
147 + if echo "${RC_VERBS}" | grep -q -- "${1}" ; then
148 + exec /etc/init.d/apache2 "${@}"
149 + else
150 + load_rc_config || exit 1
151 + ${APACHE2} ${APACHE2_OPTS} -d ${SERVERROOT} -f ${CONFIGFILE} "${@}"
152 + fi
153 +else
154 + # If systemd IS detected, load the config and parse the argument
155 +
156 + # Yes, we load config from apache's openrc conf.d file.
157 + # Feel free to provide a more suitable solution.
158 + load_rc_config || exit 1
159 +
160 + # Append the server root and configuration file parameters to the
161 + # user's APACHE2_OPTS.
162 + APACHE2_OPTS="${APACHE2_OPTS} -d ${SERVERROOT}"
163 + APACHE2_OPTS="${APACHE2_OPTS} -f ${CONFIGFILE}"
164 +
165 + apache_service="apache2.service"
166 +
167 + case ${1} in
168 + # Original apachectl options
169 + # See: https://httpd.apache.org/docs/2.4/programs/apachectl.html
170 + start|stop|restart|status)
171 + systemctl ${1} ${apache_service}
172 + retval=$?
173 + ;;
174 + reload)
175 + reload
176 + retval=$?
177 + ;;
178 + fullstatus)
179 + fullstatus
180 + retval=$?
181 + ;;
182 + graceful)
183 + configtest || exit 1
184 + systemctl reload ${apache_service}
185 + retval=$?
186 + ;;
187 + gracefulstop|graceful-stop)
188 + configtest || exit 1
189 + systemctl stop ${apache_service}
190 + retval=$?
191 + ;;
192 + configtest)
193 + configtest
194 + retval=$?
195 + ;;
196 + checkconfd)
197 + checkconfd
198 + retval=$?
199 + ;;
200 + configdump)
201 + configtest || exit 1
202 + configdump
203 + retval=$?
204 + ;;
205 + virtualhosts)
206 + configtest || exit 1
207 + ${APACHE2} ${APACHE2_OPTS} -S
208 + retval=$?
209 + ;;
210 + modules)
211 + configtest || exit 1
212 + ${APACHE2} ${APACHE2_OPTS} -M 2>&1
213 + retval=$?
214 + ;;
215 + # For all other options fall back to the legacy way of handling them
216 + *)
217 + ${APACHE2} ${APACHE2_OPTS} "${@}"
218 + retval=$?
219 + ;;
220 + esac
221 + exit ${retval}
222 fi
223 -
224 -# If systemd IS detected, load the config and parse the argument
225 -load_rc_config || exit 1
226 -
227 -# Append the server root and configuration file parameters to the
228 -# user's APACHE2_OPTS.
229 -APACHE2_OPTS="${APACHE2_OPTS} -d ${SERVERROOT}"
230 -APACHE2_OPTS="${APACHE2_OPTS} -f ${CONFIGFILE}"
231 -
232 -case $1 in
233 -# Original apachectl options
234 -# See: https://httpd.apache.org/docs/2.4/programs/apachectl.html
235 -start|stop|restart|status)
236 - /bin/systemctl $1 apache2.service
237 - ERROR=$?
238 - ;;
239 -
240 -reload)
241 - reload
242 - ERROR=$?
243 - ;;
244 -
245 -fullstatus)
246 - fullstatus
247 - ERROR=$?
248 - ;;
249 -
250 -graceful)
251 - configtest || exit 1
252 - /bin/systemctl reload apache2.service
253 - ERROR=$?
254 - ;;
255 -
256 -gracefulstop|graceful-stop)
257 - configtest || exit 1
258 - /bin/systemctl stop apache2.service
259 - ERROR=$?
260 - ;;
261 -
262 -configtest)
263 - configtest
264 - ERROR=$?
265 - ;;
266 -
267 -checkconfd)
268 - checkconfd
269 - ERROR=$?
270 - ;;
271 -
272 -configdump)
273 - configtest || exit 1
274 - configdump
275 - ERROR=$?
276 - ;;
277 -
278 -virtualhosts)
279 - configtest || exit 1
280 - ${APACHE2} ${APACHE2_OPTS} -S
281 - ERROR=$?
282 - ;;
283 -
284 -modules)
285 - configtest || exit 1
286 - ${APACHE2} ${APACHE2_OPTS} -M 2>&1
287 - ERROR=$?
288 - ;;
289 -
290 -# For all other options fall back to the legacy way of handling them
291 -*)
292 - ${APACHE2} ${APACHE2_OPTS} "${@}"
293 - ERROR=$?
294 - ;;
295 -esac
296 -
297 -exit $ERROR