summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-11 21:28:35 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-11 21:28:35 +0200
commit79354a389890a7ee4b6cd5b7d7044b521fb133a6 (patch)
tree72fdf922cbdf148b75b8e9d011dc080ace81fc65
parent684ce94729d68e84fd7ab6067998781fdc891358 (diff)
Add some basic systemd integration
-rw-r--r--main.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/main.c b/main.c
index 422443e..34fd2d2 100644
--- a/main.c
+++ b/main.c
@@ -12,6 +12,7 @@
#include <sys/signalfd.h>
#include <sys/eventfd.h>
#include <signal.h>
+#include <systemd/sd-daemon.h>
#include "main.h"
#include "uring.h"
@@ -198,9 +199,11 @@ signalfd_read(struct cfg *cfg, struct uring_task *task, int res)
if (sev->buf < 1000) {
fprintf(stderr, "Got a signal to quit\n");
+ sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting");
exit(EXIT_SUCCESS);
} else {
fprintf(stderr, "Got a signal to dump tree\n");
+ sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting");
dump_tree(cfg);
uring_task_put(cfg, &sev->task);
announce_delete(cfg);
@@ -301,6 +304,8 @@ int
main(int argc, char **argv)
{
struct cfg *cfg;
+ struct server *server;
+ unsigned server_count;
cfg = cfg_init(argc, argv);
@@ -320,6 +325,19 @@ main(int argc, char **argv)
uring_task_put(cfg, &cfg->task);
+ server_count = 0;
+ list_for_each_entry(server, &cfg->servers, list)
+ server_count++;
+
+ sd_notifyf(0, "READY=1\n"
+ "STATUS=Running, %u server configurations loaded\n"
+ "MAINPID=%lu",
+ server_count,
+ (unsigned long)getpid());
+
+ fprintf(stderr, "%s: started, %u server configurations loaded\n",
+ argv[0], server_count);
+
uring_event_loop(cfg);
fprintf(stderr, "Event loop exited\n");