From: Gergely Nagy <algernon@madhouse-project.org> When compiling with systemd support, notify systemd about our status and readiness via sd_notify(). Also set the service type to Type=notify in the systemd unit file. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> --- contrib/systemd/syslog-ng.service | 1 + lib/Makefile.am | 3 ++- lib/mainloop.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/contrib/systemd/syslog-ng.service b/contrib/systemd/syslog-ng.service index ee8d28b..46e61bf 100644 --- a/contrib/systemd/syslog-ng.service +++ b/contrib/systemd/syslog-ng.service @@ -3,6 +3,7 @@ Description=System Logger Daemon Documentation=man:syslog-ng(8) [Service] +Type=notify Sockets=syslog.socket ExecStart=/usr/sbin/syslog-ng -F ExecReload=/bin/kill -HUP $MAINPID diff --git a/lib/Makefile.am b/lib/Makefile.am index f572499..a735df2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -10,7 +10,8 @@ export top_srcdir include logproto/logproto.am lib_LTLIBRARIES = libsyslog-ng.la -libsyslog_ng_la_LIBADD = @CORE_DEPS_LIBS@ +libsyslog_ng_la_CPPFLAGS = $(libsystemd_daemon_CFLAGS) +libsyslog_ng_la_LIBADD = @CORE_DEPS_LIBS@ $(libsystemd_daemon_LIBS) libsyslog_ng_la_LDFLAGS = -no-undefined -release @VERSION@ # this is intentionally formatted so conflicts are less likely to arise. one name in every line. diff --git a/lib/mainloop.c b/lib/mainloop.c index 6dd1979..68b8bf5 100644 --- a/lib/mainloop.c +++ b/lib/mainloop.c @@ -33,6 +33,7 @@ #include "dnscache.h" #include "tls-support.h" #include "scratch-buffers.h" +#include "config.h" #include <sys/types.h> #include <sys/wait.h> @@ -45,6 +46,12 @@ #include <iv_work.h> #include <iv_event.h> +#if ENABLE_SYSTEMD +#include <systemd/sd-daemon.h> +#else +#define sd_notify(...) +#endif + /** * Processing model * ================ @@ -506,10 +513,12 @@ main_loop_reload_config_apply(void) main_loop_new_config->persist = NULL; cfg_free(main_loop_old_config); current_configuration = main_loop_new_config; + sd_notify(0, "STATUS="); } else { msg_error("Error initializing new configuration, reverting to old config", NULL); + sd_notify(0, "STATUS=Error initializing new configuration, using the old config"); cfg_persist_config_move(main_loop_new_config, main_loop_old_config); if (!cfg_init(main_loop_old_config)) { @@ -548,6 +557,8 @@ main_loop_reload_config_apply(void) void main_loop_reload_config_initiate(void) { + sd_notify(0, "STATUS=Reloading configuration"); + if (main_loop_new_config) { /* This block is entered only if this function is reentered before @@ -559,6 +570,7 @@ main_loop_reload_config_initiate(void) cfg_free(main_loop_new_config); main_loop_new_config = NULL; } + main_loop_old_config = current_configuration; app_pre_config_loaded(); main_loop_new_config = cfg_new(0); @@ -570,6 +582,7 @@ main_loop_reload_config_initiate(void) msg_error("Error parsing configuration", evt_tag_str(EVT_TAG_FILENAME, cfgfilename), NULL); + sd_notify(0, "STATUS=Error parsing new configuration, using the old config"); return; } main_loop_io_worker_sync_call(main_loop_reload_config_apply); @@ -700,6 +713,7 @@ main_loop_run(void) msg_notice("syslog-ng starting up", evt_tag_str("version", VERSION), NULL); + sd_notify(0, "STATUS=starting up"); IV_TIMER_INIT(&stats_timer); stats_timer.handler = stats_timer_elapsed; @@ -734,7 +748,10 @@ main_loop_run(void) stats_timer_kickoff(current_configuration); /* main loop */ + sd_notify(0, "STATUS="); + sd_notify(0, "READY=1"); iv_main(); + sd_notify(0, "STATUS=Shutting down"); control_destroy(); -- 1.7.10.4