MXS-1441 Expose monitor_launch_command
So that a specific monitor may create the command and replace monitor specific script variables before giving the command for execution.
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <maxscale/monitor.h>
|
#include <maxscale/monitor.h>
|
||||||
|
#include "externcmd.h"
|
||||||
|
|
||||||
MXS_BEGIN_DECLS
|
MXS_BEGIN_DECLS
|
||||||
|
|
||||||
@ -104,4 +105,17 @@ MXS_MONITOR* monitor_server_in_use(const SERVER *server);
|
|||||||
*/
|
*/
|
||||||
int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, const char* script, uint32_t timeout);
|
int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, const char* script, uint32_t timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch a command
|
||||||
|
*
|
||||||
|
* @param mon Owning monitor
|
||||||
|
* @param ptr The server which has changed state
|
||||||
|
* @param cmd The command to execute.
|
||||||
|
*
|
||||||
|
* @note All default script variables will be replaced.
|
||||||
|
*
|
||||||
|
* @return Return value of the executed script or -1 on error.
|
||||||
|
*/
|
||||||
|
int monitor_launch_command(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, EXTERNCMD* cmd);
|
||||||
|
|
||||||
MXS_END_DECLS
|
MXS_END_DECLS
|
||||||
|
|||||||
@ -1235,20 +1235,8 @@ static std::string child_nodes(MXS_MONITORED_SERVER* servers,
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, const char* script, uint32_t timeout)
|
int monitor_launch_command(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, EXTERNCMD* cmd)
|
||||||
{
|
{
|
||||||
char arg[strlen(script) + 1];
|
|
||||||
strcpy(arg, script);
|
|
||||||
|
|
||||||
EXTERNCMD* cmd = externcmd_allocate(arg, timeout);
|
|
||||||
|
|
||||||
if (cmd == NULL)
|
|
||||||
{
|
|
||||||
MXS_ERROR("Failed to initialize script '%s'. See previous errors for the "
|
|
||||||
"cause of this failure.", script);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (externcmd_matches(cmd, "$INITIATOR"))
|
if (externcmd_matches(cmd, "$INITIATOR"))
|
||||||
{
|
{
|
||||||
char initiator[strlen(ptr->server->name) + 24]; // Extra space for port
|
char initiator[strlen(ptr->server->name) + 24]; // Extra space for port
|
||||||
@ -1325,13 +1313,13 @@ int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, const cha
|
|||||||
{
|
{
|
||||||
// Internal error
|
// Internal error
|
||||||
MXS_ERROR("Failed to execute script '%s' on server state change event '%s'",
|
MXS_ERROR("Failed to execute script '%s' on server state change event '%s'",
|
||||||
script, mon_get_event_name(ptr));
|
cmd->argv[0], mon_get_event_name(ptr));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Script returned a non-zero value
|
// Script returned a non-zero value
|
||||||
MXS_ERROR("Script '%s' returned %d on event '%s'",
|
MXS_ERROR("Script '%s' returned %d on event '%s'",
|
||||||
script, rv, mon_get_event_name(ptr));
|
cmd->argv[0], rv, mon_get_event_name(ptr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1382,6 +1370,25 @@ int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, const cha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, const char* script, uint32_t timeout)
|
||||||
|
{
|
||||||
|
char arg[strlen(script) + 1];
|
||||||
|
strcpy(arg, script);
|
||||||
|
|
||||||
|
EXTERNCMD* cmd = externcmd_allocate(arg, timeout);
|
||||||
|
|
||||||
|
if (cmd == NULL)
|
||||||
|
{
|
||||||
|
MXS_ERROR("Failed to initialize script '%s'. See previous errors for the "
|
||||||
|
"cause of this failure.", script);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rv = monitor_launch_command(mon, ptr, cmd);
|
||||||
|
|
||||||
externcmd_free(cmd);
|
externcmd_free(cmd);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
|||||||
Reference in New Issue
Block a user