]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master, master: Initialize stats-client via environment variables
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 29 Aug 2018 19:09:57 +0000 (22:09 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 13 Nov 2018 13:10:42 +0000 (15:10 +0200)
That way it's initialized before settings are read, and it can catch events
earlier. It also doesn't require all services to read settings if they
otherwise don't need them.

src/lib-master/master-interface.h
src/lib-master/master-service-settings.c
src/lib-master/master-service.c
src/master/service-process.c

index 821aa02b5a3f28207cb2aa7910aec0f7cc4c241b..1ddef5f6876907a47fde2fca6ce0022fca473760 100644 (file)
@@ -79,6 +79,10 @@ enum master_login_state {
    be used to initialize debug logging immediately at startup. */
 #define DOVECOT_LOG_DEBUG_ENV "LOG_DEBUG"
 
+/* getenv(DOVECOT_STATS_WRITER_SOCKET_PATH) returns path to the stats-writer
+   socket. */
+#define DOVECOT_STATS_WRITER_SOCKET_PATH "STATS_WRITER_SOCKET_PATH"
+
 /* Write pipe to anvil. */
 #define MASTER_ANVIL_FD 3
 /* Anvil reads new log fds from this fd */
index 5fee08a09693a87868c0594d34ea103d058b15f9..fb555c3ce90631d6fa948b90cd45621994aea3b5 100644 (file)
@@ -766,13 +766,13 @@ int master_service_settings_read(struct master_service *service,
                /* running standalone. we want to ignore plugin versions. */
                service->version_string = NULL;
        }
-       if ((service->flags & MASTER_SERVICE_FLAG_SEND_STATS) != 0) {
+       if ((service->flags & MASTER_SERVICE_FLAG_SEND_STATS) != 0 &&
+           (service->flags & MASTER_SERVICE_FLAG_STANDALONE) != 0) {
                /* When running standalone (e.g. doveadm) try to connect to the
                   stats socket, but don't log an error if it's not running.
-                  It may be intentional. */
-               bool silent_notfound_errors =
-                       (service->flags & MASTER_SERVICE_FLAG_STANDALONE) != 0;
-               master_service_init_stats_client(service, silent_notfound_errors);
+                  It may be intentional. Non-standalone stats-client
+                  initialization was already done earlier. */
+               master_service_init_stats_client(service, TRUE);
        }
 
        if (service->set->shutdown_clients)
index 2e1914e22b435722edc54e994191fd7dac62d874..860986ca48b2d900ba7bddc0d063996da0ae75f8 100644 (file)
@@ -338,6 +338,12 @@ master_service_init(const char *name, enum master_service_flags flags,
                   are dropped. */
                master_service_config_socket_try_open(service);
        }
+       if ((flags & MASTER_SERVICE_FLAG_SEND_STATS) != 0) {
+               /* Initialize stats-client early so it can see all events. */
+               value = getenv(DOVECOT_STATS_WRITER_SOCKET_PATH);
+               if (value != NULL)
+                       service->stats_client = stats_client_init(value, FALSE);
+       }
 
        master_service_verify_version_string(service);
        return service;
index 2733daf00b155f48c04118424ea02aef9f274cd7..e6fb486084fdb0f348ba54ab745404a1108d625a 100644 (file)
@@ -232,6 +232,8 @@ static void
 service_process_setup_environment(struct service *service, unsigned int uid,
                                  const char *hostdomain)
 {
+       const struct master_service_settings *service_set =
+               service->list->service_set;
        master_service_env_clean();
 
        env_put(MASTER_IS_PARENT_ENV"=1");
@@ -255,6 +257,11 @@ service_process_setup_environment(struct service *service, unsigned int uid,
        if (!service->set->master_set->version_ignore)
                env_put(MASTER_DOVECOT_VERSION_ENV"="PACKAGE_VERSION);
 
+       if (service_set->stats_writer_socket_path[0] != '\0') {
+               env_put(t_strdup_printf(DOVECOT_STATS_WRITER_SOCKET_PATH"=%s/%s",
+                                       service_set->base_dir,
+                                       service_set->stats_writer_socket_path));
+       }
        if (ssl_manual_key_password != NULL && service->have_inet_listeners) {
                /* manually given SSL password. give it only to services
                   that have inet listeners. */
@@ -265,7 +272,7 @@ service_process_setup_environment(struct service *service, unsigned int uid,
            service_anvil_global->restarted)
                env_put("ANVIL_RESTARTED=1");
        env_put(t_strconcat(DOVECOT_LOG_DEBUG_ENV"=",
-                           service->list->service_set->log_debug, NULL));
+                           service_set->log_debug, NULL));
 }
 
 static void service_process_status_timeout(struct service_process *process)