First tests.

This commit is contained in:
Markus Makela
2015-03-31 17:27:25 +03:00
parent c3cb8df8a0
commit 341c04aa48
6 changed files with 72 additions and 8 deletions

View File

@ -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)

View File

@ -0,0 +1,38 @@
#include <mon_exec.h>
/** 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;
}

View File

@ -0,0 +1,13 @@
#ifndef MON_EXEC_HG
#define MON_EXEC_HG
#include <mon_exec.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <skygw_utils.h>
#include <log_manager.h>
int monitor_exec_cmd(char* cmd);
#endif

View File

@ -64,6 +64,7 @@
#include <dcb.h>
#include <modinfo.h>
#include <maxconfig.h>
#include <mon_exec.h>
/** 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;
}
@ -697,6 +701,14 @@ int log_no_master = 1;
{
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))

View File

@ -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

View File

@ -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)