Magellan Linux

Annotation of /trunk/apache2/patches/apache2-2.4.3-mod_systemd.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1928 - (hide annotations) (download)
Wed Oct 31 11:33:28 2012 UTC (11 years, 6 months ago) by niro
File size: 5396 byte(s)
-rediffed patches and added mod_systemd patch
1 niro 1928 --- httpd-2.4.3/modules/arch/unix/config5.m4.systemd
2     +++ httpd-2.4.3/modules/arch/unix/config5.m4
3     @@ -18,6 +18,19 @@ APACHE_MODULE(privileges, Per-virtualhos
4     fi
5     ])
6    
7     +
8     +APACHE_MODULE(systemd, Systemd support, , , $unixd_mods_enabled, [
9     + AC_CHECK_LIB(systemd-daemon, sd_notify, SYSTEMD_LIBS="-lsystemd-daemon")
10     + AC_CHECK_HEADERS(systemd/sd-daemon.h, [ap_HAVE_SD_DAEMON_H="yes"], [ap_HAVE_SD_DAEMON_H="no"])
11     + if test $ap_HAVE_SD_DAEMON_H = "no" || test -z "${SYSTEMD_LIBS}"; then
12     + AC_MSG_WARN([Your system does not support systemd.])
13     + enable_systemd="no"
14     + else
15     + APR_ADDTO(MOD_SYSTEMD_LDADD, [$SYSTEMD_LIBS])
16     + enable_systemd="yes"
17     + fi
18     +])
19     +
20     APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current])
21    
22     APACHE_MODPATH_FINISH
23     --- httpd-2.4.3/modules/arch/unix/mod_systemd.c.systemd
24     +++ httpd-2.4.3/modules/arch/unix/mod_systemd.c
25     @@ -0,0 +1,138 @@
26     +/* Licensed to the Apache Software Foundation (ASF) under one or more
27     + * contributor license agreements. See the NOTICE file distributed with
28     + * this work for additional information regarding copyright ownership.
29     + * The ASF licenses this file to You under the Apache License, Version 2.0
30     + * (the "License"); you may not use this file except in compliance with
31     + * the License. You may obtain a copy of the License at
32     + *
33     + * http://www.apache.org/licenses/LICENSE-2.0
34     + *
35     + * Unless required by applicable law or agreed to in writing, software
36     + * distributed under the License is distributed on an "AS IS" BASIS,
37     + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38     + * See the License for the specific language governing permissions and
39     + * limitations under the License.
40     + *
41     + */
42     +
43     +#include <stdint.h>
44     +#include <ap_config.h>
45     +#include "ap_mpm.h"
46     +#include <http_core.h>
47     +#include <http_log.h>
48     +#include <apr_version.h>
49     +#include <apr_pools.h>
50     +#include <apr_strings.h>
51     +#include "unixd.h"
52     +#include "scoreboard.h"
53     +#include "mpm_common.h"
54     +
55     +#include "systemd/sd-daemon.h"
56     +
57     +#if APR_HAVE_UNISTD_H
58     +#include <unistd.h>
59     +#endif
60     +
61     +#define KBYTE 1024
62     +
63     +static pid_t pid; /* PID of the main httpd instance */
64     +static int server_limit, thread_limit, threads_per_child, max_servers;
65     +static time_t last_update_time;
66     +static unsigned long last_update_access;
67     +static unsigned long last_update_kbytes;
68     +
69     +static int systemd_pre_mpm(apr_pool_t *p, ap_scoreboard_e sb_type)
70     +{
71     + int rv;
72     + last_update_time = time(0);
73     +
74     + ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
75     + ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
76     + ap_mpm_query(AP_MPMQ_MAX_THREADS, &threads_per_child);
77     + /* work around buggy MPMs */
78     + if (threads_per_child == 0)
79     + threads_per_child = 1;
80     + ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_servers);
81     +
82     + pid = getpid();
83     +
84     + rv = sd_notifyf(0, "READY=1\n"
85     + "STATUS=Processing requests...\n"
86     + "MAINPID=%lu",
87     + (unsigned long) pid);
88     + if (rv < 0) {
89     + ap_log_perror(APLOG_MARK, APLOG_ERR, 0, p,
90     + "sd_notifyf returned an error %d", rv);
91     + }
92     +
93     + return OK;
94     +}
95     +
96     +static int systemd_monitor(apr_pool_t *p, server_rec *s)
97     +{
98     + int i, j, res, rv;
99     + process_score *ps_record;
100     + worker_score *ws_record;
101     + unsigned long access = 0;
102     + unsigned long bytes = 0;
103     + unsigned long kbytes = 0;
104     + char bps[5];
105     + time_t now = time(0);
106     + time_t elapsed = now - last_update_time;
107     +
108     + for (i = 0; i < server_limit; ++i) {
109     + ps_record = ap_get_scoreboard_process(i);
110     + for (j = 0; j < thread_limit; ++j) {
111     + ws_record = ap_get_scoreboard_worker_from_indexes(i, j);
112     + if (ap_extended_status && !ps_record->quiescing && ps_record->pid) {
113     + res = ws_record->status;
114     + if (ws_record->access_count != 0 ||
115     + (res != SERVER_READY && res != SERVER_DEAD)) {
116     + access += ws_record->access_count;
117     + bytes += ws_record->bytes_served;
118     + if (bytes >= KBYTE) {
119     + kbytes += (bytes >> 10);
120     + bytes = bytes & 0x3ff;
121     + }
122     + }
123     + }
124     + }
125     + }
126     +
127     + apr_strfsize((unsigned long)(KBYTE *(float) (kbytes - last_update_kbytes)
128     + / (float) elapsed), bps);
129     +
130     + rv = sd_notifyf(0, "READY=1\n"
131     + "STATUS=Total requests: %lu; Current requests/sec: %.3g; "
132     + "Current traffic: %sB/sec\n", access,
133     + ((float)access - last_update_access) / (float) elapsed, bps);
134     + if (rv < 0) {
135     + ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00000)
136     + "sd_notifyf returned an error %d", rv);
137     + }
138     +
139     + last_update_access = access;
140     + last_update_kbytes = kbytes;
141     + last_update_time = now;
142     +
143     + return DECLINED;
144     +}
145     +
146     +static void systemd_register_hooks(apr_pool_t *p)
147     +{
148     + /* We know the PID in this hook ... */
149     + ap_hook_pre_mpm(systemd_pre_mpm, NULL, NULL, APR_HOOK_LAST);
150     + /* Used to update httpd's status line using sd_notifyf */
151     + ap_hook_monitor(systemd_monitor, NULL, NULL, APR_HOOK_MIDDLE);
152     +}
153     +
154     +module AP_MODULE_DECLARE_DATA systemd_module =
155     +{
156     + STANDARD20_MODULE_STUFF,
157     + NULL,
158     + NULL,
159     + NULL,
160     + NULL,
161     + NULL,
162     + systemd_register_hooks,
163     +};