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