From: Andrew Beekhof <andrew@beekhof.net>
Date: Wed, 2 Sep 2015 14:34:04 +1000
Subject: [PATCH] Fix: crmd: Report the completion status and output of
notifications
(cherry picked from commit 0c303d8a6f9f9a9dbec9f6d2e9e799fe335f8eaa)
---
crmd/notify.c | 37 ++++++++++++++++++++++++-------------
lib/services/services.c | 4 ++--
2 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/crmd/notify.c b/crmd/notify.c
index ccf5ea8..ca2be0f 100644
--- a/crmd/notify.c
+++ b/crmd/notify.c
@@ -29,6 +29,7 @@ static const char *notify_keys[] =
{
"CRM_notify_recipient",
"CRM_notify_node",
+ "CRM_notify_nodeid",
"CRM_notify_rsc",
"CRM_notify_task",
"CRM_notify_interval",
@@ -83,12 +84,21 @@ set_notify_key(const char *name, const char *cvalue, char *value)
free(value);
}
+static void crmd_notify_complete(svc_action_t *op)
+{
+ if(op->rc == 0) {
+ crm_info("Notification %d (%s) complete", op->sequence, op->agent);
+ } else {
+ crm_warn("Notification %d (%s) failed: %d", op->sequence, op->agent, op->rc);
+ }
+}
static void
send_notification(const char *kind)
{
int lpc;
- pid_t pid;
+ svc_action_t *notify = NULL;
+ static int operations = 0;
crm_debug("Sending '%s' notification to '%s' via '%s'", kind, notify_target, notify_script);
@@ -96,20 +106,20 @@ send_notification(const char *kind)
set_notify_key("CRM_notify_kind", kind, NULL);
set_notify_key("CRM_notify_version", VERSION, NULL);
- pid = fork();
- if (pid == -1) {
- crm_perror(LOG_ERR, "notification failed");
- }
+ notify = services_action_create_generic(notify_script, NULL);
- if (pid == 0) {
- /* crm_debug("notification: I am the child. Executing the nofitication program."); */
- execl(notify_script, notify_script, NULL);
- exit(EXIT_FAILURE);
+ notify->timeout = 300;
+ notify->standard = strdup("event");
+ notify->id = strdup(notify_script);
+ notify->agent = strdup(notify_script);
+ notify->sequence = ++operations;
- } else {
- for(lpc = 0; lpc < DIMOF(notify_keys); lpc++) {
- unsetenv(notify_keys[lpc]);
- }
+ if(services_action_async(notify, &crmd_notify_complete) == FALSE) {
+ services_action_free(notify);
+ }
+
+ for(lpc = 0; lpc < DIMOF(notify_keys); lpc++) {
+ unsetenv(notify_keys[lpc]);
}
}
@@ -120,6 +130,7 @@ void crmd_notify_node_event(crm_node_t *node)
}
set_notify_key("CRM_notify_node", node->uname, NULL);
+ set_notify_key("CRM_notify_nodeid", NULL, crm_itoa(node->id));
set_notify_key("CRM_notify_desc", node->state, NULL);
send_notification("node");
diff --git a/lib/services/services.c b/lib/services/services.c
index abf1458..4609a7d 100644
--- a/lib/services/services.c
+++ b/lib/services/services.c
@@ -598,7 +598,7 @@ action_async_helper(svc_action_t * op) {
}
/* keep track of ops that are in-flight to avoid collisions in the same namespace */
- if (res) {
+ if (op->rsc && res) {
inflight_ops = g_list_append(inflight_ops, op);
}
@@ -622,7 +622,7 @@ services_action_async(svc_action_t * op, void (*action_callback) (svc_action_t *
g_hash_table_replace(recurring_actions, op->id, op);
}
- if (is_op_blocked(op->rsc)) {
+ if (op->rsc && is_op_blocked(op->rsc)) {
blocked_ops = g_list_append(blocked_ops, op);
return TRUE;
}