|
|
28b219 |
--- httpd-2.4.3/modules/arch/unix/config5.m4.systemd
|
|
|
28b219 |
+++ httpd-2.4.3/modules/arch/unix/config5.m4
|
|
|
28b219 |
@@ -18,6 +18,19 @@ APACHE_MODULE(privileges, Per-virtualhos
|
|
|
28b219 |
fi
|
|
|
28b219 |
])
|
|
|
28b219 |
|
|
|
28b219 |
+
|
|
|
28b219 |
+APACHE_MODULE(systemd, Systemd support, , , $unixd_mods_enabled, [
|
|
|
28b219 |
+ AC_CHECK_LIB(systemd-daemon, sd_notify, SYSTEMD_LIBS="-lsystemd-daemon")
|
|
|
28b219 |
+ AC_CHECK_HEADERS(systemd/sd-daemon.h, [ap_HAVE_SD_DAEMON_H="yes"], [ap_HAVE_SD_DAEMON_H="no"])
|
|
|
28b219 |
+ if test $ap_HAVE_SD_DAEMON_H = "no" || test -z "${SYSTEMD_LIBS}"; then
|
|
|
28b219 |
+ AC_MSG_WARN([Your system does not support systemd.])
|
|
|
28b219 |
+ enable_systemd="no"
|
|
|
28b219 |
+ else
|
|
|
28b219 |
+ APR_ADDTO(MOD_SYSTEMD_LDADD, [$SYSTEMD_LIBS])
|
|
|
28b219 |
+ enable_systemd="yes"
|
|
|
28b219 |
+ fi
|
|
|
28b219 |
+])
|
|
|
28b219 |
+
|
|
|
28b219 |
APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current])
|
|
|
28b219 |
|
|
|
28b219 |
APACHE_MODPATH_FINISH
|
|
|
28b219 |
--- httpd-2.4.3/modules/arch/unix/mod_systemd.c.systemd
|
|
|
28b219 |
+++ httpd-2.4.3/modules/arch/unix/mod_systemd.c
|
|
|
28b219 |
@@ -0,0 +1,138 @@
|
|
|
28b219 |
+/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
28b219 |
+ * contributor license agreements. See the NOTICE file distributed with
|
|
|
28b219 |
+ * this work for additional information regarding copyright ownership.
|
|
|
28b219 |
+ * The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
28b219 |
+ * (the "License"); you may not use this file except in compliance with
|
|
|
28b219 |
+ * the License. You may obtain a copy of the License at
|
|
|
28b219 |
+ *
|
|
|
28b219 |
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
28b219 |
+ *
|
|
|
28b219 |
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
28b219 |
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
28b219 |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
28b219 |
+ * See the License for the specific language governing permissions and
|
|
|
28b219 |
+ * limitations under the License.
|
|
|
28b219 |
+ *
|
|
|
28b219 |
+ */
|
|
|
28b219 |
+
|
|
|
28b219 |
+#include <stdint.h>
|
|
|
28b219 |
+#include <ap_config.h>
|
|
|
28b219 |
+#include "ap_mpm.h"
|
|
|
28b219 |
+#include <http_core.h>
|
|
|
28b219 |
+#include <http_log.h>
|
|
|
28b219 |
+#include <apr_version.h>
|
|
|
28b219 |
+#include <apr_pools.h>
|
|
|
28b219 |
+#include <apr_strings.h>
|
|
|
28b219 |
+#include "unixd.h"
|
|
|
28b219 |
+#include "scoreboard.h"
|
|
|
28b219 |
+#include "mpm_common.h"
|
|
|
28b219 |
+
|
|
|
28b219 |
+#include "systemd/sd-daemon.h"
|
|
|
28b219 |
+
|
|
|
28b219 |
+#if APR_HAVE_UNISTD_H
|
|
|
28b219 |
+#include <unistd.h>
|
|
|
28b219 |
+#endif
|
|
|
28b219 |
+
|
|
|
28b219 |
+#define KBYTE 1024
|
|
|
28b219 |
+
|
|
|
28b219 |
+static pid_t pid; /* PID of the main httpd instance */
|
|
|
28b219 |
+static int server_limit, thread_limit, threads_per_child, max_servers;
|
|
|
28b219 |
+static time_t last_update_time;
|
|
|
28b219 |
+static unsigned long last_update_access;
|
|
|
28b219 |
+static unsigned long last_update_kbytes;
|
|
|
28b219 |
+
|
|
|
28b219 |
+static int systemd_pre_mpm(apr_pool_t *p, ap_scoreboard_e sb_type)
|
|
|
28b219 |
+{
|
|
|
28b219 |
+ int rv;
|
|
|
28b219 |
+ last_update_time = time(0);
|
|
|
28b219 |
+
|
|
|
28b219 |
+ ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
|
|
|
28b219 |
+ ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
|
|
|
28b219 |
+ ap_mpm_query(AP_MPMQ_MAX_THREADS, &threads_per_child);
|
|
|
28b219 |
+ /* work around buggy MPMs */
|
|
|
28b219 |
+ if (threads_per_child == 0)
|
|
|
28b219 |
+ threads_per_child = 1;
|
|
|
28b219 |
+ ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_servers);
|
|
|
28b219 |
+
|
|
|
28b219 |
+ pid = getpid();
|
|
|
28b219 |
+
|
|
|
28b219 |
+ rv = sd_notifyf(0, "READY=1\n"
|
|
|
28b219 |
+ "STATUS=Processing requests...\n"
|
|
|
28b219 |
+ "MAINPID=%lu",
|
|
|
28b219 |
+ (unsigned long) pid);
|
|
|
28b219 |
+ if (rv < 0) {
|
|
|
28b219 |
+ ap_log_perror(APLOG_MARK, APLOG_ERR, 0, p,
|
|
|
28b219 |
+ "sd_notifyf returned an error %d", rv);
|
|
|
28b219 |
+ }
|
|
|
28b219 |
+
|
|
|
28b219 |
+ return OK;
|
|
|
28b219 |
+}
|
|
|
28b219 |
+
|
|
|
28b219 |
+static int systemd_monitor(apr_pool_t *p, server_rec *s)
|
|
|
28b219 |
+{
|
|
|
28b219 |
+ int i, j, res, rv;
|
|
|
28b219 |
+ process_score *ps_record;
|
|
|
28b219 |
+ worker_score *ws_record;
|
|
|
28b219 |
+ unsigned long access = 0;
|
|
|
28b219 |
+ unsigned long bytes = 0;
|
|
|
28b219 |
+ unsigned long kbytes = 0;
|
|
|
28b219 |
+ char bps[5];
|
|
|
28b219 |
+ time_t now = time(0);
|
|
|
28b219 |
+ time_t elapsed = now - last_update_time;
|
|
|
28b219 |
+
|
|
|
28b219 |
+ for (i = 0; i < server_limit; ++i) {
|
|
|
28b219 |
+ ps_record = ap_get_scoreboard_process(i);
|
|
|
28b219 |
+ for (j = 0; j < thread_limit; ++j) {
|
|
|
28b219 |
+ ws_record = ap_get_scoreboard_worker_from_indexes(i, j);
|
|
|
28b219 |
+ if (ap_extended_status && !ps_record->quiescing && ps_record->pid) {
|
|
|
28b219 |
+ res = ws_record->status;
|
|
|
28b219 |
+ if (ws_record->access_count != 0 ||
|
|
|
28b219 |
+ (res != SERVER_READY && res != SERVER_DEAD)) {
|
|
|
28b219 |
+ access += ws_record->access_count;
|
|
|
28b219 |
+ bytes += ws_record->bytes_served;
|
|
|
28b219 |
+ if (bytes >= KBYTE) {
|
|
|
28b219 |
+ kbytes += (bytes >> 10);
|
|
|
28b219 |
+ bytes = bytes & 0x3ff;
|
|
|
28b219 |
+ }
|
|
|
28b219 |
+ }
|
|
|
28b219 |
+ }
|
|
|
28b219 |
+ }
|
|
|
28b219 |
+ }
|
|
|
28b219 |
+
|
|
|
28b219 |
+ apr_strfsize((unsigned long)(KBYTE *(float) (kbytes - last_update_kbytes)
|
|
|
28b219 |
+ / (float) elapsed), bps);
|
|
|
28b219 |
+
|
|
|
28b219 |
+ rv = sd_notifyf(0, "READY=1\n"
|
|
|
28b219 |
+ "STATUS=Total requests: %lu; Current requests/sec: %.3g; "
|
|
|
28b219 |
+ "Current traffic: %sB/sec\n", access,
|
|
|
28b219 |
+ ((float)access - last_update_access) / (float) elapsed, bps);
|
|
|
28b219 |
+ if (rv < 0) {
|
|
|
28b219 |
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00000)
|
|
|
28b219 |
+ "sd_notifyf returned an error %d", rv);
|
|
|
28b219 |
+ }
|
|
|
28b219 |
+
|
|
|
28b219 |
+ last_update_access = access;
|
|
|
28b219 |
+ last_update_kbytes = kbytes;
|
|
|
28b219 |
+ last_update_time = now;
|
|
|
28b219 |
+
|
|
|
28b219 |
+ return DECLINED;
|
|
|
28b219 |
+}
|
|
|
28b219 |
+
|
|
|
28b219 |
+static void systemd_register_hooks(apr_pool_t *p)
|
|
|
28b219 |
+{
|
|
|
28b219 |
+ /* We know the PID in this hook ... */
|
|
|
28b219 |
+ ap_hook_pre_mpm(systemd_pre_mpm, NULL, NULL, APR_HOOK_LAST);
|
|
|
28b219 |
+ /* Used to update httpd's status line using sd_notifyf */
|
|
|
28b219 |
+ ap_hook_monitor(systemd_monitor, NULL, NULL, APR_HOOK_MIDDLE);
|
|
|
28b219 |
+}
|
|
|
28b219 |
+
|
|
|
28b219 |
+module AP_MODULE_DECLARE_DATA systemd_module =
|
|
|
28b219 |
+{
|
|
|
28b219 |
+ STANDARD20_MODULE_STUFF,
|
|
|
28b219 |
+ NULL,
|
|
|
28b219 |
+ NULL,
|
|
|
28b219 |
+ NULL,
|
|
|
28b219 |
+ NULL,
|
|
|
28b219 |
+ NULL,
|
|
|
28b219 |
+ systemd_register_hooks,
|
|
|
28b219 |
+};
|