diff --git a/server/modules/monitor/CMakeLists.txt b/server/modules/monitor/CMakeLists.txt index a99a66142..3d3f83580 100644 --- a/server/modules/monitor/CMakeLists.txt +++ b/server/modules/monitor/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(mysqlmon SHARED mysql_mon.c) +add_library(mysqlmon SHARED mysql_mon.c mon_exec.c) target_link_libraries(mysqlmon log_manager utils) install(TARGETS mysqlmon DESTINATION modules) diff --git a/server/modules/monitor/mon_exec.c b/server/modules/monitor/mon_exec.c new file mode 100644 index 000000000..122390da9 --- /dev/null +++ b/server/modules/monitor/mon_exec.c @@ -0,0 +1,38 @@ +#include + +/** Defined in log_manager.cc */ +extern int lm_enabled_logfiles_bitmask; +extern size_t log_ses_count[]; +extern __thread log_info_t tls_log_info; + +/** + *Execute a command in a separate process. + *@param cmd Command to execute + *@return 0 on success, -1 on error. + */ +int monitor_exec_cmd(char* cmd) +{ + int rval = 0; + pid_t pid; + + pid = fork(); + + if(pid < 0) + { + skygw_log_write(LOGFILE_ERROR,"Error: Failed to execute command '%s', fork failed: [%d] %s", + cmd,errno,strerror(errno)); + rval = -1; + } + else if(pid == 0) + { + /** Child process, execute command */ + execl(cmd,cmd,NULL); + } + else + { + LOGIF(LD,skygw_log_write(LD,"[monitor_exec_cmd] Forked child process %d : %s.",pid,cmd)); + } + + return rval; + +} diff --git a/server/modules/monitor/mon_exec.h b/server/modules/monitor/mon_exec.h new file mode 100644 index 000000000..ed277ab3e --- /dev/null +++ b/server/modules/monitor/mon_exec.h @@ -0,0 +1,13 @@ +#ifndef MON_EXEC_HG +#define MON_EXEC_HG + +#include +#include +#include +#include +#include +#include + +int monitor_exec_cmd(char* cmd); + +#endif diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index 9945086fb..51720c225 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -64,6 +64,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -184,6 +185,7 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; handle->connect_timeout=DEFAULT_CONNECT_TIMEOUT; handle->read_timeout=DEFAULT_READ_TIMEOUT; handle->write_timeout=DEFAULT_WRITE_TIMEOUT; + handle->script = NULL; spinlock_init(&handle->lock); } @@ -193,6 +195,8 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; handle->detectStaleMaster = config_truth_value(params->value); else if(!strcmp(params->name,"detect_replication_lag")) handle->replicationHeartbeat = config_truth_value(params->value); + else if(!strcmp(params->name,"script")) + handle->script = strdup(params->value); params = params->next; } @@ -696,7 +700,15 @@ int log_no_master = 1; !(SERVER_IS_IN_CLUSTER(ptr->server))) { dcb_call_foreach(ptr->server,DCB_REASON_NOT_RESPONDING); - } + } + +/* + if(handle->script) + { + if(monitor_exec_cmd(handle->script)) + skygw_log_write(LOGFILE_ERROR,"Error: Failed to execute command '%s' on server state change.",handle->script); + } +*/ } if (mon_status_changed(ptr)) diff --git a/server/modules/monitor/mysqlmon.h b/server/modules/monitor/mysqlmon.h index a7d7fb419..3b5658a5a 100644 --- a/server/modules/monitor/mysqlmon.h +++ b/server/modules/monitor/mysqlmon.h @@ -77,6 +77,7 @@ typedef struct { int write_timeout; /**< Timeout in seconds for each attempt to write to the server. * There are retries and the total effective timeout value is two times the option value. */ + char *script;0 } MYSQL_MONITOR; #define MONITOR_RUNNING 1 diff --git a/server/modules/protocol/CMakeLists.txt b/server/modules/protocol/CMakeLists.txt index 0bea95832..7d118c3ec 100644 --- a/server/modules/protocol/CMakeLists.txt +++ b/server/modules/protocol/CMakeLists.txt @@ -6,13 +6,13 @@ add_library(MySQLBackend SHARED mysql_backend.c mysql_common.c) target_link_libraries(MySQLBackend log_manager utils) install(TARGETS MySQLBackend DESTINATION modules) -add_library(mongoclient SHARED mongo_client.c mysql_common.c) -target_link_libraries(mongoclient log_manager utils) -install(TARGETS mongoclient DESTINATION modules) +add_library(plainclient SHARED plainclient.c mysql_common.c) +target_link_libraries(plainclient log_manager utils) +install(TARGETS plainclient DESTINATION modules) -add_library(mongobackend SHARED mongo_backend.c mysql_common.c) -target_link_libraries(mongobackend log_manager utils) -install(TARGETS mongobackend DESTINATION modules) +add_library(plainbackend SHARED plainbackend.c mysql_common.c) +target_link_libraries(plainbackend log_manager utils) +install(TARGETS plainbackend DESTINATION modules) add_library(telnetd SHARED telnetd.c)