diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index ae6477863..a71a8dc61 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -80,9 +80,13 @@ protected: * * When the monitor is started, this function will be called in order * to allow the concrete implementation to configure itself from - * configuration parameters. The default implementation does nothing. + * configuration parameters. The default implementation returns true. + * + * @return True, if the monitor could be configured, false otherwise. + * + * @note If false is returned, then the monitor will not be started. */ - virtual void configure(const MXS_CONFIG_PARAMETER* pParams); + virtual bool configure(const MXS_CONFIG_PARAMETER* pParams); /** * @brief Check whether the monitor has sufficient rights diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 25b4e0792..ec1b30dc2 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -2599,26 +2599,27 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams) m_events = config_get_enum(pParams, "events", mxs_monitor_event_enum_values); m_master = NULL; - configure(pParams); - - if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) == NULL) + if (configure(pParams)) { - MXS_ERROR("Failed to start monitor thread for monitor '%s'.", m_monitor->name); - } - else - { - // Ok, so the thread started. Let's wait until we can be certain the - // state has been updated. - m_semaphore.wait(); - - started = (atomic_load_int32(&m_status) == MXS_MONITOR_RUNNING); - - if (!started) + if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) == NULL) { - // Ok, so the initialization failed and the thread will exit. - // We need to wait on it so that the thread resources will not leak. - thread_wait(m_thread); - m_thread = 0; + MXS_ERROR("Failed to start monitor thread for monitor '%s'.", m_monitor->name); + } + else + { + // Ok, so the thread started. Let's wait until we can be certain the + // state has been updated. + m_semaphore.wait(); + + started = (atomic_load_int32(&m_status) == MXS_MONITOR_RUNNING); + + if (!started) + { + // Ok, so the initialization failed and the thread will exit. + // We need to wait on it so that the thread resources will not leak. + thread_wait(m_thread); + m_thread = 0; + } } } } @@ -2626,13 +2627,14 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams) return started; } -bool MonitorInstance::has_sufficient_permissions() const +bool MonitorInstance::configure(const MXS_CONFIG_PARAMETER* pParams) { return true; } -void MonitorInstance::configure(const MXS_CONFIG_PARAMETER* pParams) +bool MonitorInstance::has_sufficient_permissions() const { + return true; } void MonitorInstance::flush_server_status() diff --git a/server/modules/monitor/auroramon/auroramon.cc b/server/modules/monitor/auroramon/auroramon.cc index 57c12ae4f..5a58cc5ca 100644 --- a/server/modules/monitor/auroramon/auroramon.cc +++ b/server/modules/monitor/auroramon/auroramon.cc @@ -49,8 +49,9 @@ json_t* AuroraMonitor::diagnostics_json() const return NULL; } -void AuroraMonitor::configure(const MXS_CONFIG_PARAMETER* params) +bool AuroraMonitor::configure(const MXS_CONFIG_PARAMETER* params) { + return true; } bool AuroraMonitor::has_sufficient_permissions() const diff --git a/server/modules/monitor/auroramon/auroramon.hh b/server/modules/monitor/auroramon/auroramon.hh index a287615f5..6e5054343 100644 --- a/server/modules/monitor/auroramon/auroramon.hh +++ b/server/modules/monitor/auroramon/auroramon.hh @@ -32,7 +32,7 @@ public: json_t* diagnostics_json() const; protected: - void configure(const MXS_CONFIG_PARAMETER* params); + bool configure(const MXS_CONFIG_PARAMETER* params); bool has_sufficient_permissions() const; void update_server_status(MXS_MONITORED_SERVER* monitored_server); diff --git a/server/modules/monitor/galeramon/galeramon.cc b/server/modules/monitor/galeramon/galeramon.cc index de192615f..b2e9b44e2 100644 --- a/server/modules/monitor/galeramon/galeramon.cc +++ b/server/modules/monitor/galeramon/galeramon.cc @@ -130,7 +130,7 @@ json_t* GaleraMonitor::diagnostics_json() const return rval; } -void GaleraMonitor::configure(const MXS_CONFIG_PARAMETER* params) +bool GaleraMonitor::configure(const MXS_CONFIG_PARAMETER* params) { m_disableMasterFailback = config_get_bool(params, "disable_master_failback"); m_availableWhenDonor = config_get_bool(params, "available_when_donor"); @@ -142,6 +142,8 @@ void GaleraMonitor::configure(const MXS_CONFIG_PARAMETER* params) /* Reset all data in the hashtable */ reset_cluster_info(); + + return true; } bool GaleraMonitor::has_sufficient_permissions() const diff --git a/server/modules/monitor/galeramon/galeramon.hh b/server/modules/monitor/galeramon/galeramon.hh index 1210f03d7..de95e0db5 100644 --- a/server/modules/monitor/galeramon/galeramon.hh +++ b/server/modules/monitor/galeramon/galeramon.hh @@ -64,7 +64,7 @@ public: json_t* diagnostics_json() const; protected: - void configure(const MXS_CONFIG_PARAMETER* param); + bool configure(const MXS_CONFIG_PARAMETER* param); bool has_sufficient_permissions() const; void update_server_status(MXS_MONITORED_SERVER* monitored_server); void tick(); diff --git a/server/modules/monitor/grmon/grmon.cc b/server/modules/monitor/grmon/grmon.cc index 3687928ed..665d09f31 100644 --- a/server/modules/monitor/grmon/grmon.cc +++ b/server/modules/monitor/grmon/grmon.cc @@ -49,8 +49,9 @@ json_t* GRMon::diagnostics_json() const return NULL; } -void GRMon::configure(const MXS_CONFIG_PARAMETER* params) +bool GRMon::configure(const MXS_CONFIG_PARAMETER* params) { + return true; } bool GRMon::has_sufficient_permissions() const diff --git a/server/modules/monitor/grmon/grmon.hh b/server/modules/monitor/grmon/grmon.hh index 473f23aa5..c7dae9ab6 100644 --- a/server/modules/monitor/grmon/grmon.hh +++ b/server/modules/monitor/grmon/grmon.hh @@ -32,7 +32,7 @@ public: json_t* diagnostics_json() const; protected: - void configure(const MXS_CONFIG_PARAMETER* params); + bool configure(const MXS_CONFIG_PARAMETER* params); bool has_sufficient_permissions() const; void update_server_status(MXS_MONITORED_SERVER* monitored_server); diff --git a/server/modules/monitor/mmmon/mmmon.cc b/server/modules/monitor/mmmon/mmmon.cc index 44e1df8e0..006e4dbf0 100644 --- a/server/modules/monitor/mmmon/mmmon.cc +++ b/server/modules/monitor/mmmon/mmmon.cc @@ -64,9 +64,11 @@ json_t* MMMonitor::diagnostics_json() const return rval; } -void MMMonitor::configure(const MXS_CONFIG_PARAMETER* params) +bool MMMonitor::configure(const MXS_CONFIG_PARAMETER* params) { m_detectStaleMaster = config_get_bool(params, "detect_stale_master"); + + return true; } bool MMMonitor::has_sufficient_permissions() const diff --git a/server/modules/monitor/mmmon/mmmon.hh b/server/modules/monitor/mmmon/mmmon.hh index 8ed443cb8..06c97d134 100644 --- a/server/modules/monitor/mmmon/mmmon.hh +++ b/server/modules/monitor/mmmon/mmmon.hh @@ -32,7 +32,7 @@ public: json_t* diagnostics_json() const; protected: - void configure(const MXS_CONFIG_PARAMETER* params); + bool configure(const MXS_CONFIG_PARAMETER* params); bool has_sufficient_permissions() const; void update_server_status(MXS_MONITORED_SERVER* monitored_server); void tick(); diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.cc b/server/modules/monitor/ndbclustermon/ndbclustermon.cc index 43728b227..4596ebea1 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.cc +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.cc @@ -47,8 +47,9 @@ json_t* NDBCMonitor::diagnostics_json() const return NULL; } -void NDBCMonitor::configure(const MXS_CONFIG_PARAMETER* params) +bool NDBCMonitor::configure(const MXS_CONFIG_PARAMETER* params) { + return true; } bool NDBCMonitor::has_sufficient_permissions() const diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.hh b/server/modules/monitor/ndbclustermon/ndbclustermon.hh index 9d2af06bd..ef476b804 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.hh +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.hh @@ -32,7 +32,7 @@ public: json_t* diagnostics_json() const; protected: - void configure(const MXS_CONFIG_PARAMETER* params); + bool configure(const MXS_CONFIG_PARAMETER* params); bool has_sufficient_permissions() const; void update_server_status(MXS_MONITORED_SERVER* monitored_server);