Add creation and destruction of monitors
Monitors can now be created and destroyed at runtime. The configurations for new monitors are persisted to disk.
This commit is contained in:
@ -280,6 +280,11 @@ bool runtime_alter_server(SERVER *server, char *key, char *value)
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (valid)
|
||||
{
|
||||
server_serialize(server);
|
||||
}
|
||||
|
||||
spinlock_release(&crt_lock);
|
||||
return valid;
|
||||
}
|
||||
@ -357,6 +362,11 @@ bool runtime_alter_monitor(MONITOR *monitor, char *key, char *value)
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
{
|
||||
monitor_serialize(monitor);
|
||||
}
|
||||
|
||||
spinlock_release(&crt_lock);
|
||||
return valid;
|
||||
}
|
||||
@ -480,3 +490,58 @@ bool runtime_destroy_listener(SERVICE *service, const char *name)
|
||||
spinlock_release(&crt_lock);
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool runtime_create_monitor(const char *name, const char *module)
|
||||
{
|
||||
spinlock_acquire(&crt_lock);
|
||||
bool rval = false;
|
||||
MONITOR *monitor = monitor_alloc((char*)name, (char*)module);
|
||||
|
||||
if (monitor && monitor_serialize(monitor))
|
||||
{
|
||||
rval = true;
|
||||
}
|
||||
|
||||
spinlock_release(&crt_lock);
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool runtime_destroy_monitor(MONITOR *monitor)
|
||||
{
|
||||
bool rval = false;
|
||||
char filename[PATH_MAX];
|
||||
snprintf(filename, sizeof(filename), "%s/%s.cnf", get_config_persistdir(), monitor->name);
|
||||
|
||||
spinlock_acquire(&crt_lock);
|
||||
|
||||
if (unlink(filename) == -1)
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
{
|
||||
char err[MXS_STRERROR_BUFLEN];
|
||||
MXS_ERROR("Failed to remove persisted monitor configuration '%s': %d, %s",
|
||||
filename, errno, strerror_r(errno, err, sizeof(err)));
|
||||
}
|
||||
else
|
||||
{
|
||||
rval = false;
|
||||
MXS_WARNING("Monitor '%s' was not created at runtime. Remove the "
|
||||
"monitor manually from the correct configuration file.",
|
||||
monitor->name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rval = true;
|
||||
}
|
||||
|
||||
if (rval)
|
||||
{
|
||||
monitorStop(monitor);
|
||||
MXS_NOTICE("Destroyed monitor '%s'. The monitor will be removed "
|
||||
"after the next restart of MaxScale.", monitor->name);
|
||||
}
|
||||
|
||||
spinlock_release(&crt_lock);
|
||||
return rval;
|
||||
}
|
||||
|
Reference in New Issue
Block a user