From e8b94c1773f5ec9fee6fab1e57722686c641da0a Mon Sep 17 00:00:00 2001 From: default Date: Tue, 26 Dec 2023 10:41:55 +0100 Subject: [PATCH] New page status.txt. It just return an empty page as a query, but some status logging is done. --- httpd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/httpd.c b/httpd.c index d401d7d..0d52d23 100644 --- a/httpd.c +++ b/httpd.c @@ -30,6 +30,8 @@ int use_fcgi = 0; int srv_running = 0; +time_t srv_start_time = 0; + /* nodeinfo 2.0 template */ const char *nodeinfo_2_0_template = "" "{\"version\":\"2.0\"," @@ -209,6 +211,15 @@ int server_get_handler(xs_dict *req, const char *q_path, *body = xs_str_new("User-agent: *\n" "Disallow: /\n"); } + else + if (strcmp(q_path, "/status.txt") == 0) { + status = 200; + *ctype = "text/plain"; + *body = xs_str_new("UP\n"); + + xs *uptime = xs_str_time_diff(time(NULL) - srv_start_time); + srv_log(xs_fmt("status: uptime: %s", uptime)); + } if (status != 0) srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); @@ -591,10 +602,11 @@ void httpd(void) pthread_t threads[MAX_THREADS] = {0}; int n_threads = 0; int n; - time_t start_time = time(NULL); char sem_name[24]; sem_t anon_job_sem; + srv_start_time = time(NULL); + use_fcgi = xs_type(xs_dict_get(srv_config, "fastcgi")) == XSTYPE_TRUE; address = xs_dict_get(srv_config, "address"); @@ -697,7 +709,7 @@ void httpd(void) sem_close(job_sem); sem_unlink(sem_name); - xs *uptime = xs_str_time_diff(time(NULL) - start_time); + xs *uptime = xs_str_time_diff(time(NULL) - srv_start_time); srv_log(xs_fmt("httpd%s stop %s:%s (run time: %s)", use_fcgi ? " (FastCGI)" : "", address, port, uptime));