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: 1554194310.74a5571d7fdae809663b0c16db2edb6aa9f8d42f.polynomial-c@gentoo
1 commit: 74a5571d7fdae809663b0c16db2edb6aa9f8d42f
2 Author: Jarod <jarodiv <AT> web <DOT> de>
3 AuthorDate: Tue Mar 26 22:27:31 2019 +0000
4 Commit: Lars Wendler <polynomial-c <AT> gentoo <DOT> org>
5 CommitDate: Tue Apr 2 08:38:30 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/apache.git/commit/?id=74a5571d
7
8 apache2ctl: Add suport for systemd
9
10 Signed-off-by: Lars Wendler <polynomial-c <AT> gentoo.org>
11
12 2.4/scripts/apache2ctl | 182 ++++++++++++++++++++++++++++++++++++++++++++-----
13 1 file changed, 165 insertions(+), 17 deletions(-)
14
15 diff --git a/2.4/scripts/apache2ctl b/2.4/scripts/apache2ctl
16 index 8031b8b..392ac4c 100644
17 --- a/2.4/scripts/apache2ctl
18 +++ b/2.4/scripts/apache2ctl
19 @@ -6,23 +6,171 @@ APACHE_RC_CONF="/etc/conf.d/apache2"
20 # List of init script verbs that should be passed forward
21 RC_VERBS="start stop restart checkconfd configtest modules virtualhosts configdump fullstatus graceful gracefulstop reload"
22
23 -load_rc_config() {
24 - [ -f "${APACHE_RC_CONF}" ] || return 1
25 - if ! grep -q '^[[:space:]]*APACHE2_OPTS' ${APACHE_RC_CONF} ; then
26 - echo "Cannot find APACHE2_OPTS in ${APACHE_RC_CONF}"
27 - exit 1
28 - fi
29 - . ${APACHE_RC_CONF}
30 - export APACHE2_OPTS
31 - export SERVERROOT="${SERVERROOT:-/usr/@LIBDIR@/apache2}"
32 - export CONFIGFILE="${CONFIGFILE:-/etc/apache2/httpd.conf}"
33 +
34 +function is_systemd() {
35 + [ $(ps --no-headers -o comm 1) == "systemd" ] && return 0
36 + return 1
37 +}
38 +
39 +function load_rc_config() {
40 + [ -f "${APACHE_RC_CONF}" ] || return 1
41 + if ! grep -q '^[[:space:]]*APACHE2_OPTS' ${APACHE_RC_CONF} ; then
42 + echo "Cannot find APACHE2_OPTS in ${APACHE_RC_CONF}"
43 + exit 1
44 + fi
45 + . ${APACHE_RC_CONF}
46 + export APACHE2_OPTS
47 + export SERVERROOT="${SERVERROOT:-/usr/lib64/apache2}"
48 + export CONFIGFILE="${CONFIGFILE:-/etc/apache2/httpd.conf}"
49 +}
50 +
51 +# Basically the code from '/etc/init.d/apache2::reload()', updated to run without open-rc
52 +function reload() {
53 + RELOAD_TYPE="${RELOAD_TYPE:-graceful}"
54 +
55 + if [ "${RELOAD_TYPE}" = "restart" ]; then
56 + ${APACHE2} ${APACHE2_OPTS} -k restart
57 + elif [ "${RELOAD_TYPE}" = "graceful" ]; then
58 + ${APACHE2} ${APACHE2_OPTS} -k graceful
59 + else
60 + echo "${RELOAD_TYPE} is not a valid RELOAD_TYPE. Please edit /etc/conf.d/apache2"
61 + fi
62 +}
63 +
64 +# Basically the code from '/etc/init.d/apache2::fullstatus()', updated to run without open-rc
65 +function fullstatus() {
66 + LYNX="${LYNX:-lynx -dump}"
67 + STATUSURL="${STATUSURL:-http://localhost/server-status}"
68 +
69 + if ! command -v $(set -- ${LYNX}; echo $1) 2>&1 >/dev/null; then
70 + echo 'lynx not found! you need to emerge www-client/lynx'
71 + else
72 + ${LYNX} ${STATUSURL}
73 + fi
74 + return $?
75 }
76
77 -# If first parameter is a verb defined in $RC_VERBS, pass the command to init script.
78 -# In other cases, compile command line and run the command on apache binary.
79 -if echo "${RC_VERBS}" | grep -q -- "${1}" ; then
80 - exec /etc/init.d/apache2 "${@}"
81 -else
82 - load_rc_config || exit 1
83 - ${APACHE2} ${APACHE2_OPTS} -d ${SERVERROOT} -f ${CONFIGFILE} "${@}"
84 +# Basically the code from '/etc/init.d/apache2::checkconfd()', updated to run without open-rc
85 +function checkconfd() {
86 + if [ ! -d ${SERVERROOT} ]; then
87 + echo "SERVERROOT does not exist: ${SERVERROOT}"
88 + return 1
89 + fi
90 +}
91 +
92 +# Basically the code from '/etc/init.d/apache2::checkconfig()', updated to run without open-rc
93 +function configtest() {
94 + checkconfd || return 1
95 +
96 + OUTPUT=$( ${APACHE2} ${APACHE2_OPTS} -t 2>&1 )
97 + ret=$?
98 + if [ $ret -ne 0 ]; then
99 + echo "apache2 has detected an error in your setup:"
100 + printf "%s\n" "${OUTPUT}"
101 + fi
102 +
103 + return $ret
104 +}
105 +
106 +# Basically the code from '/etc/init.d/apache2::configdump()', updated to run without open-rc
107 +function configdump() {
108 + INFOURL="${INFOURL:-http://localhost/server-info}"
109 +
110 + if ! command -v $(set -- ${LYNX}; echo $1) 2>&1 >/dev/null; then
111 + echo "lynx not found! you need to emerge www-client/lynx"
112 + else
113 + echo "${APACHE2} started with '${APACHE2_OPTS}'"
114 + for i in config server list; do
115 + ${LYNX} "${INFOURL}/?${i}" | sed '/Apache Server Information/d;/^[[:space:]]\+[_]\+$/Q'
116 + done
117 + fi
118 +}
119 +
120 +
121 +# If systemd IS NOT detected, run the legacy apache2ctl code
122 +if ! is_systemd; then
123 + # If first parameter is a verb defined in $RC_VERBS, pass the command to init script.
124 + # In other cases, compile command line and run the command on apache binary.
125 + if echo "${RC_VERBS}" | grep -q -- "${1}" ; then
126 + exec /etc/init.d/apache2 "${@}"
127 + else
128 + load_rc_config || exit 1
129 + ${APACHE2} ${APACHE2_OPTS} -d ${SERVERROOT} -f ${CONFIGFILE} "${@}"
130 + fi
131 + exit 0
132 fi
133 +
134 +# If systemd IS detected, load the config and parse the argument
135 +load_rc_config || exit 1
136 +
137 +# Append the server root and configuration file parameters to the
138 +# user's APACHE2_OPTS.
139 +APACHE2_OPTS="${APACHE2_OPTS} -d ${SERVERROOT}"
140 +APACHE2_OPTS="${APACHE2_OPTS} -f ${CONFIGFILE}"
141 +
142 +case $1 in
143 +# Original apachectl options
144 +# See: https://httpd.apache.org/docs/2.4/programs/apachectl.html
145 +start|stop|restart|status)
146 + /bin/systemctl $1 apache2.service
147 + ERROR=$?
148 + ;;
149 +
150 +reload)
151 + reload
152 + ERROR=$?
153 + ;;
154 +
155 +fullstatus)
156 + fullstatus
157 + ERROR=$?
158 + ;;
159 +
160 +graceful)
161 + configtest || exit 1
162 + /bin/systemctl reload apache2.service
163 + ERROR=$?
164 + ;;
165 +
166 +gracefulstop|graceful-stop)
167 + configtest || exit 1
168 + /bin/systemctl stop apache2.service
169 + ERROR=$?
170 + ;;
171 +
172 +configtest)
173 + configtest
174 + ERROR=$?
175 + ;;
176 +
177 +checkconfd)
178 + checkconfd
179 + ERROR=$?
180 + ;;
181 +
182 +configdump)
183 + configtest || exit 1
184 + configdump
185 + ERROR=$?
186 + ;;
187 +
188 +virtualhosts)
189 + configtest || exit 1
190 + ${APACHE2} ${APACHE2_OPTS} -S
191 + ERROR=$?
192 + ;;
193 +
194 +modules)
195 + configtest || exit 1
196 + ${APACHE2} ${APACHE2_OPTS} -M 2>&1
197 + ERROR=$?
198 + ;;
199 +
200 +# For all other options fall back to the legacy way of handling them
201 +*)
202 + ${APACHE2} ${APACHE2_OPTS} "${@}"
203 + ERROR=$?
204 + ;;
205 +esac
206 +
207 +exit $ERROR