Apache HTTPD
mod_systemd.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#include <stdint.h>
19#include <ap_config.h>
20#include "ap_mpm.h"
21#include <http_core.h>
22#include <httpd.h>
23#include <http_log.h>
24#include <apr_version.h>
25#include <apr_pools.h>
26#include <apr_strings.h>
27#include "unixd.h"
28#include "scoreboard.h"
29#include "mpm_common.h"
30
31#include "systemd/sd-daemon.h"
32
33#if APR_HAVE_UNISTD_H
34#include <unistd.h>
35#endif
36
38 apr_pool_t *ptemp)
39{
40 sd_notify(0,
41 "RELOADING=1\n"
42 "STATUS=Reading configuration...\n");
44 return OK;
45}
46
47/* Report the service is ready in post_config, which could be during
48 * startup or after a reload. The server could still hit a fatal
49 * startup error after this point during ap_run_mpm(), so this is
50 * perhaps too early, but by post_config listen() has been called on
51 * the TCP ports so new connections will not be rejected. There will
52 * always be a possible async failure event simultaneous to the
53 * service reporting "ready", so this should be good enough. */
56{
57 sd_notify(0, "READY=1\n"
58 "STATUS=Configuration loaded.\n");
59 return OK;
60}
61
63{
64 sd_notifyf(0, "READY=1\n"
65 "STATUS=Processing requests...\n"
66 "MAINPID=%" APR_PID_T_FMT, getpid());
67
68 return OK;
69}
70
72{
75 char bps[5];
76
77 if (!ap_extended_status) {
78 /* Nothing useful to report with ExtendedStatus disabled. */
79 return DECLINED;
80 }
81
83 /* up_time in seconds */
86
87 apr_strfsize((unsigned long)((float) (sload.bytes_served)
88 / (float) up_time), bps);
89
90 sd_notifyf(0, "READY=1\n"
91 "STATUS=Total requests: %lu; Idle/Busy workers %d/%d;"
92 "Requests/sec: %.3g; Bytes served/sec: %sB/sec\n",
93 sload.access_count, sload.idle, sload.busy,
94 ((float) sload.access_count) / (float) up_time, bps);
95
96 return DECLINED;
97}
98
100{
101 /* Enable ap_extended_status. */
103 /* Signal service is ready. */
105 /* We know the PID in this hook ... */
107 /* Used to update httpd's status line using sd_notifyf */
109}
110
113 NULL,
114 NULL,
115 NULL,
116 NULL,
117 NULL,
119};
Symbol export macros and hook functions.
Apache Multi-Processing Module library.
APR memory allocation.
APR Strings library.
APR Versioning Interface.
static apr_pool_t * pconf
Definition event.c:441
void ap_hook_post_config(ap_HOOK_post_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:105
#define AP_DECLARE_MODULE(foo)
void ap_hook_pre_config(ap_HOOK_pre_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:91
const char server_rec * main_server
#define DECLINED
Definition httpd.h:457
#define OK
Definition httpd.h:456
void ap_hook_monitor(ap_HOOK_monitor_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition mpm_common.c:91
#define APR_HOOK_LAST
Definition apr_hooks.h:305
#define APR_HOOK_MIDDLE
Definition apr_hooks.h:303
#define APR_HOOK_REALLY_LAST
Definition apr_hooks.h:307
#define STANDARD20_MODULE_STUFF
void ap_get_sload(ap_sload_t *ld)
Definition util.c:3305
apr_size_t size
const char * s
Definition apr_strings.h:95
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
#define apr_time_sec(time)
Definition apr_time.h:63
CORE HTTP Daemon.
Apache Logging library.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
static int systemd_monitor(apr_pool_t *p, server_rec *s)
Definition mod_systemd.c:71
static int systemd_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
Definition mod_systemd.c:37
static int systemd_pre_mpm(apr_pool_t *p, ap_scoreboard_e sb_type)
Definition mod_systemd.c:62
static void systemd_register_hooks(apr_pool_t *p)
Definition mod_systemd.c:99
static int systemd_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server)
Definition mod_systemd.c:54
Multi-Processing Modules functions.
Apache scoreboard library.
scoreboard * ap_scoreboard_image
Definition scoreboard.c:44
int ap_extended_status
Definition scoreboard.c:61
ap_scoreboard_e
Definition scoreboard.h:83
void ap_hook_pre_mpm(ap_HOOK_pre_mpm_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition scoreboard.c:102
A structure to hold server load params.
Definition httpd.h:1411
apr_time_t restart_time
Definition scoreboard.h:129
global_score * global
Definition scoreboard.h:161
A structure to store information for each virtual server.
Definition httpd.h:1322