mod_systemd: show bound ports in status and log to journal

at startup.
This commit is contained in:
Joe Orton 2018-06-12 15:31:38 +01:00
parent c189ca4f3d
commit 3778b45de1
2 changed files with 84 additions and 23 deletions

View File

@ -1,9 +1,5 @@
diff -uap httpd-2.4.27/modules/arch/unix/config5.m4.systemd httpd-2.4.27/modules/arch/unix/config5.m4 --- httpd-2.4.33/modules/arch/unix/config5.m4.systemd
diff -uap httpd-2.4.27/modules/arch/unix/config5.m4.systemd httpd-2.4.27/modules/arch/unix/config5.m4 +++ httpd-2.4.33/modules/arch/unix/config5.m4
diff -uap httpd-2.4.27/modules/arch/unix/config5.m4.systemd httpd-2.4.27/modules/arch/unix/config5.m4
diff -uap httpd-2.4.27/modules/arch/unix/config5.m4.systemd httpd-2.4.27/modules/arch/unix/config5.m4
--- httpd-2.4.27/modules/arch/unix/config5.m4.systemd
+++ httpd-2.4.27/modules/arch/unix/config5.m4
@@ -18,6 +18,16 @@ @@ -18,6 +18,16 @@
fi fi
]) ])
@ -21,10 +17,9 @@ diff -uap httpd-2.4.27/modules/arch/unix/config5.m4.systemd httpd-2.4.27/modules
APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current]) APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current])
APACHE_MODPATH_FINISH APACHE_MODPATH_FINISH
diff -uap httpd-2.4.27/modules/arch/unix/mod_systemd.c.systemd httpd-2.4.27/modules/arch/unix/mod_systemd.c --- httpd-2.4.33/modules/arch/unix/mod_systemd.c.systemd
--- httpd-2.4.27/modules/arch/unix/mod_systemd.c.systemd +++ httpd-2.4.33/modules/arch/unix/mod_systemd.c
+++ httpd-2.4.27/modules/arch/unix/mod_systemd.c @@ -0,0 +1,223 @@
@@ -0,0 +1,161 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more +/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with + * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. + * this work for additional information regarding copyright ownership.
@ -56,6 +51,7 @@ diff -uap httpd-2.4.27/modules/arch/unix/mod_systemd.c.systemd httpd-2.4.27/modu
+#include "mpm_common.h" +#include "mpm_common.h"
+ +
+#include "systemd/sd-daemon.h" +#include "systemd/sd-daemon.h"
+#include "systemd/sd-journal.h"
+ +
+#if APR_HAVE_UNISTD_H +#if APR_HAVE_UNISTD_H
+#include <unistd.h> +#include <unistd.h>
@ -65,6 +61,7 @@ diff -uap httpd-2.4.27/modules/arch/unix/mod_systemd.c.systemd httpd-2.4.27/modu
+static int shutdown_counter = 0; +static int shutdown_counter = 0;
+static unsigned long bytes_served; +static unsigned long bytes_served;
+static pid_t mainpid; +static pid_t mainpid;
+static char describe_listeners[50];
+ +
+static int systemd_pre_config(apr_pool_t *pconf, apr_pool_t *plog, +static int systemd_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
+ apr_pool_t *ptemp) + apr_pool_t *ptemp)
@ -76,6 +73,55 @@ diff -uap httpd-2.4.27/modules/arch/unix/mod_systemd.c.systemd httpd-2.4.27/modu
+ return OK; + return OK;
+} +}
+ +
+static char *dump_listener(ap_listen_rec *lr, apr_pool_t *p)
+{
+ apr_sockaddr_t *sa = lr->bind_addr;
+ char addr[128];
+
+ if (apr_sockaddr_is_wildcard(sa)) {
+ return apr_pstrcat(p, "port ", apr_itoa(p, sa->port), NULL);
+ }
+
+ apr_sockaddr_ip_getbuf(addr, sizeof addr, sa);
+
+ return apr_psprintf(p, "%s port %u", addr, sa->port);
+}
+
+static int systemd_post_config(apr_pool_t *pconf, apr_pool_t *plog,
+ apr_pool_t *ptemp, server_rec *s)
+{
+ ap_listen_rec *lr;
+ apr_size_t plen = sizeof describe_listeners;
+ char *p = describe_listeners;
+
+ if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG)
+ return OK;
+
+ for (lr = ap_listeners; lr; lr = lr->next) {
+ char *s = dump_listener(lr, ptemp);
+
+ if (strlen(s) + 3 < plen) {
+ char *newp = apr_cpystrn(p, s, plen);
+ if (lr->next)
+ newp = apr_cpystrn(newp, ", ", 3);
+ plen -= newp - p;
+ p = newp;
+ }
+ else {
+ if (plen < 4) {
+ p = describe_listeners + sizeof describe_listeners - 4;
+ plen = 4;
+ }
+ apr_cpystrn(p, "...", plen);
+ break;
+ }
+ }
+
+ sd_journal_print(LOG_INFO, "Server configured, listening on: %s", describe_listeners);
+
+ return OK;
+}
+
+static int systemd_pre_mpm(apr_pool_t *p, ap_scoreboard_e sb_type) +static int systemd_pre_mpm(apr_pool_t *p, ap_scoreboard_e sb_type)
+{ +{
+ int rv; + int rv;
@ -83,8 +129,9 @@ diff -uap httpd-2.4.27/modules/arch/unix/mod_systemd.c.systemd httpd-2.4.27/modu
+ mainpid = getpid(); + mainpid = getpid();
+ +
+ rv = sd_notifyf(0, "READY=1\n" + rv = sd_notifyf(0, "READY=1\n"
+ "STATUS=Processing requests...\n" + "STATUS=Started, listening on: %s\n"
+ "MAINPID=%" APR_PID_T_FMT, mainpid); + "MAINPID=%" APR_PID_T_FMT,
+ describe_listeners, mainpid);
+ if (rv < 0) { + if (rv < 0) {
+ ap_log_perror(APLOG_MARK, APLOG_ERR, 0, p, APLOGNO(02395) + ap_log_perror(APLOG_MARK, APLOG_ERR, 0, p, APLOGNO(02395)
+ "sd_notifyf returned an error %d", rv); + "sd_notifyf returned an error %d", rv);
@ -106,6 +153,13 @@ diff -uap httpd-2.4.27/modules/arch/unix/mod_systemd.c.systemd httpd-2.4.27/modu
+ } + }
+ +
+ ap_get_sload(&sload); + ap_get_sload(&sload);
+
+ if (sload.access_count == 0) {
+ rv = sd_notifyf(0, "READY=1\n"
+ "STATUS=Running, listening on: %s\n",
+ describe_listeners);
+ }
+ else {
+ /* up_time in seconds */ + /* up_time in seconds */
+ up_time = (apr_uint32_t) apr_time_sec(apr_time_now() - + up_time = (apr_uint32_t) apr_time_sec(apr_time_now() -
+ ap_scoreboard_image->global->restart_time); + ap_scoreboard_image->global->restart_time);
@ -118,6 +172,7 @@ diff -uap httpd-2.4.27/modules/arch/unix/mod_systemd.c.systemd httpd-2.4.27/modu
+ "Requests/sec: %.3g; Bytes served/sec: %sB/sec\n", + "Requests/sec: %.3g; Bytes served/sec: %sB/sec\n",
+ sload.access_count, sload.idle, sload.busy, + sload.access_count, sload.idle, sload.busy,
+ ((float) sload.access_count) / (float) up_time, bps); + ((float) sload.access_count) / (float) up_time, bps);
+ }
+ +
+ if (rv < 0) { + if (rv < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(02396) + ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(02396)
@ -152,6 +207,8 @@ diff -uap httpd-2.4.27/modules/arch/unix/mod_systemd.c.systemd httpd-2.4.27/modu
+{ +{
+ /* Enable ap_extended_status. */ + /* Enable ap_extended_status. */
+ ap_hook_pre_config(systemd_pre_config, NULL, NULL, APR_HOOK_LAST); + ap_hook_pre_config(systemd_pre_config, NULL, NULL, APR_HOOK_LAST);
+ /* Grab the listener config. */
+ ap_hook_post_config(systemd_post_config, NULL, NULL, APR_HOOK_LAST);
+ /* We know the PID in this hook ... */ + /* We know the PID in this hook ... */
+ ap_hook_pre_mpm(systemd_pre_mpm, NULL, NULL, APR_HOOK_LAST); + ap_hook_pre_mpm(systemd_pre_mpm, NULL, NULL, APR_HOOK_LAST);
+ /* Used to update httpd's status line using sd_notifyf */ + /* Used to update httpd's status line using sd_notifyf */

View File

@ -13,7 +13,7 @@
Summary: Apache HTTP Server Summary: Apache HTTP Server
Name: httpd Name: httpd
Version: 2.4.33 Version: 2.4.33
Release: 5%{?dist} Release: 6%{?dist}
URL: https://httpd.apache.org/ URL: https://httpd.apache.org/
Source0: https://www.apache.org/dist/httpd/httpd-%{version}.tar.bz2 Source0: https://www.apache.org/dist/httpd/httpd-%{version}.tar.bz2
Source1: index.html Source1: index.html
@ -725,6 +725,10 @@ exit $rv
%{_rpmconfigdir}/macros.d/macros.httpd %{_rpmconfigdir}/macros.d/macros.httpd
%changelog %changelog
* Tue Jun 12 2018 Joe Orton <jorton@redhat.com> - 2.4.33-6
- mod_systemd: show bound ports in status and log to journal
at startup.
* Thu Apr 19 2018 Joe Orton <jorton@redhat.com> - 2.4.33-5 * Thu Apr 19 2018 Joe Orton <jorton@redhat.com> - 2.4.33-5
- add httpd@.service; update httpd.service(8) and add new stub - add httpd@.service; update httpd.service(8) and add new stub