Gentoo Archives: gentoo-commits

From: "Fabio Erculiani (lxnay)" <lxnay@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in www-servers/apache/files: apache.conf httpd-2.4.3-mod_systemd.patch 00_systemd.conf apache2.4.service apache2.2.service
Date: Mon, 20 May 2013 08:58:08
Message-Id: 20130520085801.752BB2171D@flycatcher.gentoo.org
1 lxnay 13/05/20 08:58:01
2
3 Added: apache.conf httpd-2.4.3-mod_systemd.patch
4 00_systemd.conf apache2.4.service apache2.2.service
5 Log:
6 add systemd support to both 2.2 and 2.4 branches on behalf of the systemd team, fix bug #466096, overriding unresponsive maintainer
7
8 (Portage version: 2.2.0_alpha166/cvs/Linux x86_64, signed Manifest commit with key ADC916E5)
9
10 Revision Changes Path
11 1.1 www-servers/apache/files/apache.conf
12
13 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/apache.conf?rev=1.1&view=markup
14 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/apache.conf?rev=1.1&content-type=text/plain
15
16 Index: apache.conf
17 ===================================================================
18 d /run/apache2 710 root apache
19
20
21
22
23 1.1 www-servers/apache/files/httpd-2.4.3-mod_systemd.patch
24
25 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/httpd-2.4.3-mod_systemd.patch?rev=1.1&view=markup
26 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/httpd-2.4.3-mod_systemd.patch?rev=1.1&content-type=text/plain
27
28 Index: httpd-2.4.3-mod_systemd.patch
29 ===================================================================
30 --- httpd-2.4.3/modules/arch/unix/config5.m4.systemd
31 +++ httpd-2.4.3/modules/arch/unix/config5.m4
32 @@ -18,6 +18,19 @@ APACHE_MODULE(privileges, Per-virtualhos
33 fi
34 ])
35
36 +
37 +APACHE_MODULE(systemd, Systemd support, , , $unixd_mods_enabled, [
38 + AC_CHECK_LIB(systemd-daemon, sd_notify, SYSTEMD_LIBS="-lsystemd-daemon")
39 + AC_CHECK_HEADERS(systemd/sd-daemon.h, [ap_HAVE_SD_DAEMON_H="yes"], [ap_HAVE_SD_DAEMON_H="no"])
40 + if test $ap_HAVE_SD_DAEMON_H = "no" || test -z "${SYSTEMD_LIBS}"; then
41 + AC_MSG_WARN([Your system does not support systemd.])
42 + enable_systemd="no"
43 + else
44 + APR_ADDTO(MOD_SYSTEMD_LDADD, [$SYSTEMD_LIBS])
45 + enable_systemd="yes"
46 + fi
47 +])
48 +
49 APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current])
50
51 APACHE_MODPATH_FINISH
52 --- httpd-2.4.3/modules/arch/unix/mod_systemd.c.systemd
53 +++ httpd-2.4.3/modules/arch/unix/mod_systemd.c
54 @@ -0,0 +1,138 @@
55 +/* Licensed to the Apache Software Foundation (ASF) under one or more
56 + * contributor license agreements. See the NOTICE file distributed with
57 + * this work for additional information regarding copyright ownership.
58 + * The ASF licenses this file to You under the Apache License, Version 2.0
59 + * (the "License"); you may not use this file except in compliance with
60 + * the License. You may obtain a copy of the License at
61 + *
62 + * http://www.apache.org/licenses/LICENSE-2.0
63 + *
64 + * Unless required by applicable law or agreed to in writing, software
65 + * distributed under the License is distributed on an "AS IS" BASIS,
66 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67 + * See the License for the specific language governing permissions and
68 + * limitations under the License.
69 + *
70 + */
71 +
72 +#include <stdint.h>
73 +#include <ap_config.h>
74 +#include "ap_mpm.h"
75 +#include <http_core.h>
76 +#include <http_log.h>
77 +#include <apr_version.h>
78 +#include <apr_pools.h>
79 +#include <apr_strings.h>
80 +#include "unixd.h"
81 +#include "scoreboard.h"
82 +#include "mpm_common.h"
83 +
84 +#include "systemd/sd-daemon.h"
85 +
86 +#if APR_HAVE_UNISTD_H
87 +#include <unistd.h>
88 +#endif
89 +
90 +#define KBYTE 1024
91 +
92 +static pid_t pid; /* PID of the main httpd instance */
93 +static int server_limit, thread_limit, threads_per_child, max_servers;
94 +static time_t last_update_time;
95 +static unsigned long last_update_access;
96 +static unsigned long last_update_kbytes;
97 +
98 +static int systemd_pre_mpm(apr_pool_t *p, ap_scoreboard_e sb_type)
99 +{
100 + int rv;
101 + last_update_time = time(0);
102 +
103 + ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
104 + ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
105 + ap_mpm_query(AP_MPMQ_MAX_THREADS, &threads_per_child);
106 + /* work around buggy MPMs */
107 + if (threads_per_child == 0)
108 + threads_per_child = 1;
109 + ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_servers);
110 +
111 + pid = getpid();
112 +
113 + rv = sd_notifyf(0, "READY=1\n"
114 + "STATUS=Processing requests...\n"
115 + "MAINPID=%lu",
116 + (unsigned long) pid);
117 + if (rv < 0) {
118 + ap_log_perror(APLOG_MARK, APLOG_ERR, 0, p,
119 + "sd_notifyf returned an error %d", rv);
120 + }
121 +
122 + return OK;
123 +}
124 +
125 +static int systemd_monitor(apr_pool_t *p, server_rec *s)
126 +{
127 + int i, j, res, rv;
128 + process_score *ps_record;
129 + worker_score *ws_record;
130 + unsigned long access = 0;
131 + unsigned long bytes = 0;
132 + unsigned long kbytes = 0;
133 + char bps[5];
134 + time_t now = time(0);
135 + time_t elapsed = now - last_update_time;
136 +
137 + for (i = 0; i < server_limit; ++i) {
138 + ps_record = ap_get_scoreboard_process(i);
139 + for (j = 0; j < thread_limit; ++j) {
140 + ws_record = ap_get_scoreboard_worker_from_indexes(i, j);
141 + if (ap_extended_status && !ps_record->quiescing && ps_record->pid) {
142 + res = ws_record->status;
143 + if (ws_record->access_count != 0 ||
144 + (res != SERVER_READY && res != SERVER_DEAD)) {
145 + access += ws_record->access_count;
146 + bytes += ws_record->bytes_served;
147 + if (bytes >= KBYTE) {
148 + kbytes += (bytes >> 10);
149 + bytes = bytes & 0x3ff;
150 + }
151 + }
152 + }
153 + }
154 + }
155 +
156 + apr_strfsize((unsigned long)(KBYTE *(float) (kbytes - last_update_kbytes)
157 + / (float) elapsed), bps);
158 +
159 + rv = sd_notifyf(0, "READY=1\n"
160 + "STATUS=Total requests: %lu; Current requests/sec: %.3g; "
161 + "Current traffic: %sB/sec\n", access,
162 + ((float)access - last_update_access) / (float) elapsed, bps);
163 + if (rv < 0) {
164 + ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00000)
165 + "sd_notifyf returned an error %d", rv);
166 + }
167 +
168 + last_update_access = access;
169 + last_update_kbytes = kbytes;
170 + last_update_time = now;
171 +
172 + return DECLINED;
173 +}
174 +
175 +static void systemd_register_hooks(apr_pool_t *p)
176 +{
177 + /* We know the PID in this hook ... */
178 + ap_hook_pre_mpm(systemd_pre_mpm, NULL, NULL, APR_HOOK_LAST);
179 + /* Used to update httpd's status line using sd_notifyf */
180 + ap_hook_monitor(systemd_monitor, NULL, NULL, APR_HOOK_MIDDLE);
181 +}
182 +
183 +module AP_MODULE_DECLARE_DATA systemd_module =
184 +{
185 + STANDARD20_MODULE_STUFF,
186 + NULL,
187 + NULL,
188 + NULL,
189 + NULL,
190 + NULL,
191 + systemd_register_hooks,
192 +};
193
194
195
196 1.1 www-servers/apache/files/00_systemd.conf
197
198 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/00_systemd.conf?rev=1.1&view=markup
199 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/00_systemd.conf?rev=1.1&content-type=text/plain
200
201 Index: 00_systemd.conf
202 ===================================================================
203 # This file configures systemd module:
204 LoadModule systemd_module modules/mod_systemd.so
205
206
207
208 1.1 www-servers/apache/files/apache2.4.service
209
210 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/apache2.4.service?rev=1.1&view=markup
211 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/apache2.4.service?rev=1.1&content-type=text/plain
212
213 Index: apache2.4.service
214 ===================================================================
215 [Unit]
216 Description=The Apache HTTP Server
217 After=network.target remote-fs.target nss-lookup.target
218
219 [Service]
220 Type=notify
221 EnvironmentFile=/etc/conf.d/apache2
222 ExecStart=/usr/sbin/apache2 $APACHE2_OPTS -DFOREGROUND
223 ExecReload=/usr/sbin/apache2 $APACHE2_OPTS -k graceful
224 ExecStop=/usr/sbin/apache2 $APACHE2_OPTS -k graceful-stop
225 # We want systemd to give httpd some time to finish gracefully, but still want
226 # it to kill httpd after TimeoutStopSec if something went wrong during the
227 # graceful stop. Normally, Systemd sends SIGTERM signal right after the
228 # ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
229 # httpd time to finish.
230 KillSignal=SIGCONT
231 PrivateTmp=true
232
233 [Install]
234 WantedBy=multi-user.target
235
236
237
238 1.1 www-servers/apache/files/apache2.2.service
239
240 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/apache2.2.service?rev=1.1&view=markup
241 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-servers/apache/files/apache2.2.service?rev=1.1&content-type=text/plain
242
243 Index: apache2.2.service
244 ===================================================================
245 [Unit]
246 Description=The Apache HTTP Server
247 After=network.target remote-fs.target nss-lookup.target
248
249 [Service]
250 EnvironmentFile=/etc/conf.d/apache2
251 ExecStart=/usr/sbin/apache2 $APACHE2_OPTS -DFOREGROUND
252 ExecReload=/usr/sbin/apache2 $APACHE2_OPTS -k graceful
253 ExecStop=/usr/sbin/apache2 $APACHE2_OPTS -k graceful-stop
254 # We want systemd to give httpd some time to finish gracefully, but still want
255 # it to kill httpd after TimeoutStopSec if something went wrong during the
256 # graceful stop. Normally, Systemd sends SIGTERM signal right after the
257 # ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
258 # httpd time to finish.
259 KillSignal=SIGCONT
260 PrivateTmp=true
261
262 [Install]
263 WantedBy=multi-user.target