pacemaker  1.1.18-2b07d5c5a9
Scalable High-Availability cluster resource manager
services.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2016 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This source code is licensed under the GNU Lesser General Public License
5  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
6  */
7 
8 #include <crm_internal.h>
9 
10 #ifndef _GNU_SOURCE
11 # define _GNU_SOURCE
12 #endif
13 
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <stdio.h>
17 
18 #include <errno.h>
19 #include <unistd.h>
20 #include <dirent.h>
21 #include <fcntl.h>
22 
23 #include <crm/crm.h>
24 #include <crm/common/mainloop.h>
25 #include <crm/services.h>
26 #include <crm/msg_xml.h>
27 #include "services_private.h"
28 
29 #if SUPPORT_UPSTART
30 # include <upstart.h>
31 #endif
32 
33 #if SUPPORT_SYSTEMD
34 # include <systemd.h>
35 #endif
36 
37 /* TODO: Develop a rollover strategy */
38 
39 static int operations = 0;
40 static GHashTable *recurring_actions = NULL;
41 
42 /* ops waiting to run async because of conflicting active
43  * pending ops */
44 static GList *blocked_ops = NULL;
45 
46 /* ops currently active (in-flight) */
47 static GList *inflight_ops = NULL;
48 
49 static void handle_blocked_ops(void);
50 
52 services_action_create(const char *name, const char *action, int interval, int timeout)
53 {
54  return resources_action_create(name, PCMK_RESOURCE_CLASS_LSB, NULL, name,
55  action, interval, timeout, NULL, 0);
56 }
57 
69 const char *
70 resources_find_service_class(const char *agent)
71 {
72  /* Priority is:
73  * - lsb
74  * - systemd
75  * - upstart
76  */
77  int rc = 0;
78  struct stat st;
79  char *path = NULL;
80 
81 #ifdef LSB_ROOT_DIR
82  rc = asprintf(&path, "%s/%s", LSB_ROOT_DIR, agent);
83  if (rc > 0 && stat(path, &st) == 0) {
84  free(path);
86  }
87  free(path);
88 #endif
89 
90 #if SUPPORT_SYSTEMD
91  if (systemd_unit_exists(agent)) {
93  }
94 #endif
95 
96 #if SUPPORT_UPSTART
97  if (upstart_job_exists(agent)) {
99  }
100 #endif
101  return NULL;
102 }
103 
104 static inline void
105 init_recurring_actions(void)
106 {
107  if (recurring_actions == NULL) {
108  recurring_actions = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
109  NULL);
110  }
111 }
112 
121 static inline gboolean
122 inflight_systemd_or_upstart(svc_action_t *op)
123 {
126  && (g_list_find(inflight_ops, op) != NULL);
127 }
128 
141 static char *
142 expand_resource_class(const char *rsc, const char *standard, const char *agent)
143 {
144  char *expanded_class = NULL;
145 
146  if (strcasecmp(standard, PCMK_RESOURCE_CLASS_SERVICE) == 0) {
147  const char *found_class = resources_find_service_class(agent);
148 
149  if (found_class) {
150  crm_debug("Found %s agent %s for %s", found_class, agent, rsc);
151  expanded_class = strdup(found_class);
152  } else {
153  crm_info("Assuming resource class lsb for agent %s for %s",
154  agent, rsc);
155  expanded_class = strdup(PCMK_RESOURCE_CLASS_LSB);
156  }
157  } else {
158  expanded_class = strdup(standard);
159  }
160  CRM_ASSERT(expanded_class);
161  return expanded_class;
162 }
163 
164 svc_action_t *
165 resources_action_create(const char *name, const char *standard, const char *provider,
166  const char *agent, const char *action, int interval, int timeout,
167  GHashTable * params, enum svc_action_flags flags)
168 {
169  svc_action_t *op = NULL;
170 
171  /*
172  * Do some up front sanity checks before we go off and
173  * build the svc_action_t instance.
174  */
175 
176  if (crm_strlen_zero(name)) {
177  crm_err("Cannot create operation without resource name");
178  goto return_error;
179  }
180 
181  if (crm_strlen_zero(standard)) {
182  crm_err("Cannot create operation for %s without resource class", name);
183  goto return_error;
184  }
185 
186  if (crm_provider_required(standard) && crm_strlen_zero(provider)) {
187  crm_err("Cannot create OCF operation for %s without provider", name);
188  goto return_error;
189  }
190 
191  if (crm_strlen_zero(agent)) {
192  crm_err("Cannot create operation for %s without agent name", name);
193  goto return_error;
194  }
195 
196  if (crm_strlen_zero(action)) {
197  crm_err("Cannot create operation for %s without operation name", name);
198  goto return_error;
199  }
200 
201  /*
202  * Sanity checks passed, proceed!
203  */
204 
205  op = calloc(1, sizeof(svc_action_t));
206  op->opaque = calloc(1, sizeof(svc_action_private_t));
207  op->rsc = strdup(name);
208  op->interval = interval;
209  op->timeout = timeout;
210  op->standard = expand_resource_class(name, standard, agent);
211  op->agent = strdup(agent);
212  op->sequence = ++operations;
213  op->flags = flags;
214  op->id = generate_op_key(name, action, interval);
215 
216  if (safe_str_eq(action, "monitor") && (
219 #endif
221  action = "status";
222  }
223  op->action = strdup(action);
224 
225  if (crm_provider_required(op->standard)) {
226  op->provider = strdup(provider);
227  op->params = params;
228  params = NULL;
229 
230  if (asprintf(&op->opaque->exec, "%s/resource.d/%s/%s", OCF_ROOT_DIR, provider, agent) == -1) {
231  crm_err("Internal error: cannot create agent path");
232  goto return_error;
233  }
234  op->opaque->args[0] = strdup(op->opaque->exec);
235  op->opaque->args[1] = strdup(action);
236 
237  } else if (strcasecmp(op->standard, PCMK_RESOURCE_CLASS_LSB) == 0) {
238  if (op->agent[0] == '/') {
239  /* if given an absolute path, use that instead
240  * of tacking on the LSB_ROOT_DIR path to the front */
241  op->opaque->exec = strdup(op->agent);
242  } else if (asprintf(&op->opaque->exec, "%s/%s", LSB_ROOT_DIR, op->agent) == -1) {
243  crm_err("Internal error: cannot create agent path");
244  goto return_error;
245  }
246  op->opaque->args[0] = strdup(op->opaque->exec);
247  op->opaque->args[1] = strdup(op->action);
248  op->opaque->args[2] = NULL;
249 #if SUPPORT_HEARTBEAT
250  } else if (strcasecmp(op->standard, PCMK_RESOURCE_CLASS_HB) == 0) {
251  int index;
252  int param_num;
253  char buf_tmp[20];
254  void *value_tmp;
255 
256  if (op->agent[0] == '/') {
257  /* if given an absolute path, use that instead
258  * of tacking on the HB_RA_DIR path to the front */
259  op->opaque->exec = strdup(op->agent);
260  } else if (asprintf(&op->opaque->exec, "%s/%s", HB_RA_DIR, op->agent) == -1) {
261  crm_err("Internal error: cannot create agent path");
262  goto return_error;
263  }
264  op->opaque->args[0] = strdup(op->opaque->exec);
265 
266  /* The "heartbeat" agent class only has positional arguments,
267  * which we keyed by their decimal position number. */
268  param_num = 1;
269  if (params) {
270  for (index = 1; index <= MAX_ARGC - 3; index++ ) {
271  snprintf(buf_tmp, sizeof(buf_tmp), "%d", index);
272  value_tmp = g_hash_table_lookup(params, buf_tmp);
273  if (value_tmp == NULL) {
274  /* maybe: strdup("") ??
275  * But the old lrmd did simply continue as well. */
276  continue;
277  }
278  op->opaque->args[param_num++] = strdup(value_tmp);
279  }
280  }
281 
282  /* Add operation code as the last argument, */
283  /* and the terminating NULL pointer */
284  op->opaque->args[param_num++] = strdup(op->action);
285  op->opaque->args[param_num] = NULL;
286 #endif
287 #if SUPPORT_SYSTEMD
288  } else if (strcasecmp(op->standard, PCMK_RESOURCE_CLASS_SYSTEMD) == 0) {
289  op->opaque->exec = strdup("systemd-dbus");
290 #endif
291 #if SUPPORT_UPSTART
292  } else if (strcasecmp(op->standard, PCMK_RESOURCE_CLASS_UPSTART) == 0) {
293  op->opaque->exec = strdup("upstart-dbus");
294 #endif
295 #if SUPPORT_NAGIOS
296  } else if (strcasecmp(op->standard, PCMK_RESOURCE_CLASS_NAGIOS) == 0) {
297  int index = 0;
298 
299  if (op->agent[0] == '/') {
300  /* if given an absolute path, use that instead
301  * of tacking on the NAGIOS_PLUGIN_DIR path to the front */
302  op->opaque->exec = strdup(op->agent);
303 
304  } else if (asprintf(&op->opaque->exec, "%s/%s", NAGIOS_PLUGIN_DIR, op->agent) == -1) {
305  crm_err("Internal error: cannot create agent path");
306  goto return_error;
307  }
308 
309  op->opaque->args[0] = strdup(op->opaque->exec);
310  index = 1;
311 
312  if (safe_str_eq(op->action, "monitor") && op->interval == 0) {
313  /* Invoke --version for a nagios probe */
314  op->opaque->args[index] = strdup("--version");
315  index++;
316 
317  } else if (params) {
318  GHashTableIter iter;
319  char *key = NULL;
320  char *value = NULL;
321  static int args_size = sizeof(op->opaque->args) / sizeof(char *);
322 
323  g_hash_table_iter_init(&iter, params);
324 
325  while (g_hash_table_iter_next(&iter, (gpointer *) & key, (gpointer *) & value) &&
326  index <= args_size - 3) {
327  int len = 3;
328  char *long_opt = NULL;
329 
330  if (safe_str_eq(key, XML_ATTR_CRM_VERSION) || strstr(key, CRM_META "_")) {
331  continue;
332  }
333 
334  len += strlen(key);
335  long_opt = calloc(1, len);
336  sprintf(long_opt, "--%s", key);
337  long_opt[len - 1] = 0;
338 
339  op->opaque->args[index] = long_opt;
340  op->opaque->args[index + 1] = strdup(value);
341  index += 2;
342  }
343  }
344  op->opaque->args[index] = NULL;
345 #endif
346  } else {
347  crm_err("Unknown resource standard: %s", op->standard);
349  op = NULL;
350  }
351 
352  if(params) {
353  g_hash_table_destroy(params);
354  }
355  return op;
356 
357  return_error:
358  if(params) {
359  g_hash_table_destroy(params);
360  }
362 
363  return NULL;
364 }
365 
366 svc_action_t *
367 services_action_create_generic(const char *exec, const char *args[])
368 {
369  svc_action_t *op;
370  unsigned int cur_arg;
371 
372  op = calloc(1, sizeof(*op));
373  op->opaque = calloc(1, sizeof(svc_action_private_t));
374 
375  op->opaque->exec = strdup(exec);
376  op->opaque->args[0] = strdup(exec);
377 
378  for (cur_arg = 1; args && args[cur_arg - 1]; cur_arg++) {
379  op->opaque->args[cur_arg] = strdup(args[cur_arg - 1]);
380 
381  if (cur_arg == DIMOF(op->opaque->args) - 1) {
382  crm_err("svc_action_t args list not long enough for '%s' execution request.", exec);
383  break;
384  }
385  }
386 
387  return op;
388 }
389 
404 svc_action_t *
405 services_alert_create(const char *id, const char *exec, int timeout,
406  GHashTable *params, int sequence, void *cb_data)
407 {
408  svc_action_t *action = services_action_create_generic(exec, NULL);
409 
410  CRM_ASSERT(action);
411  action->timeout = timeout;
412  action->id = strdup(id);
413  action->params = params;
414  action->sequence = sequence;
415  action->cb_data = cb_data;
416  return action;
417 }
418 
434 int
435 services_action_user(svc_action_t *op, const char *user)
436 {
437  CRM_CHECK((op != NULL) && (user != NULL), return -EINVAL);
438  return crm_user_lookup(user, &(op->opaque->uid), &(op->opaque->gid));
439 }
440 
452 gboolean
454 {
455  action->synchronous = false;
456  action->opaque->callback = cb;
457  return services_os_action_execute(action);
458 }
459 
460 #if SUPPORT_DBUS
461 
468 void
469 services_set_op_pending(svc_action_t *op, DBusPendingCall *pending)
470 {
471  if (op->opaque->pending && (op->opaque->pending != pending)) {
472  if (pending) {
473  crm_info("Lost pending %s DBus call (%p)", op->id, op->opaque->pending);
474  } else {
475  crm_trace("Done with pending %s DBus call (%p)", op->id, op->opaque->pending);
476  }
477  dbus_pending_call_unref(op->opaque->pending);
478  }
479  op->opaque->pending = pending;
480  if (pending) {
481  crm_trace("Updated pending %s DBus call (%p)", op->id, pending);
482  } else {
483  crm_trace("Cleared pending %s DBus call", op->id);
484  }
485 }
486 #endif
487 
488 void
490 {
491  if(op->opaque == NULL) {
492  return;
493  }
494 
495 #if SUPPORT_DBUS
496  if(op->opaque->timerid != 0) {
497  crm_trace("Removing timer for call %s to %s", op->action, op->rsc);
498  g_source_remove(op->opaque->timerid);
499  op->opaque->timerid = 0;
500  }
501 
502  if(op->opaque->pending) {
503  crm_trace("Cleaning up pending dbus call %p %s for %s", op->opaque->pending, op->action, op->rsc);
504  if(dbus_pending_call_get_completed(op->opaque->pending)) {
505  crm_warn("Pending dbus call %s for %s did not complete", op->action, op->rsc);
506  }
507  dbus_pending_call_cancel(op->opaque->pending);
508  dbus_pending_call_unref(op->opaque->pending);
509  op->opaque->pending = NULL;
510  }
511 #endif
512 
513  if (op->opaque->stderr_gsource) {
515  op->opaque->stderr_gsource = NULL;
516  }
517 
518  if (op->opaque->stdout_gsource) {
520  op->opaque->stdout_gsource = NULL;
521  }
522 }
523 
524 void
526 {
527  unsigned int i;
528 
529  if (op == NULL) {
530  return;
531  }
532 
533  /* The operation should be removed from all tracking lists by this point.
534  * If it's not, we have a bug somewhere, so bail. That may lead to a
535  * memory leak, but it's better than a use-after-free segmentation fault.
536  */
537  CRM_CHECK(g_list_find(inflight_ops, op) == NULL, return);
538  CRM_CHECK(g_list_find(blocked_ops, op) == NULL, return);
539  CRM_CHECK((recurring_actions == NULL)
540  || (g_hash_table_lookup(recurring_actions, op->id) == NULL),
541  return);
542 
544 
545  if (op->opaque->repeat_timer) {
546  g_source_remove(op->opaque->repeat_timer);
547  op->opaque->repeat_timer = 0;
548  }
549 
550  free(op->id);
551  free(op->opaque->exec);
552 
553  for (i = 0; i < DIMOF(op->opaque->args); i++) {
554  free(op->opaque->args[i]);
555  }
556 
557  free(op->opaque);
558  free(op->rsc);
559  free(op->action);
560 
561  free(op->standard);
562  free(op->agent);
563  free(op->provider);
564 
565  free(op->stdout_data);
566  free(op->stderr_data);
567 
568  if (op->params) {
569  g_hash_table_destroy(op->params);
570  op->params = NULL;
571  }
572 
573  free(op);
574 }
575 
576 gboolean
578 {
579  crm_info("Cancelling %s operation %s", op->standard, op->id);
580 
581  if (recurring_actions) {
582  g_hash_table_remove(recurring_actions, op->id);
583  }
584 
585  if (op->opaque->repeat_timer) {
586  g_source_remove(op->opaque->repeat_timer);
587  op->opaque->repeat_timer = 0;
588  }
589 
590  return TRUE;
591 }
592 
602 gboolean
603 services_action_cancel(const char *name, const char *action, int interval)
604 {
605  gboolean cancelled = FALSE;
606  char *id = generate_op_key(name, action, interval);
607  svc_action_t *op = NULL;
608 
609  /* We can only cancel a recurring action */
610  init_recurring_actions();
611  op = g_hash_table_lookup(recurring_actions, id);
612  if (op == NULL) {
613  goto done;
614  }
615 
616  /* Tell operation_finalize() not to reschedule the operation */
617  op->cancel = TRUE;
618 
619  /* Stop tracking it as a recurring operation, and stop its timer */
621 
622  /* If the op has a PID, it's an in-flight child process, so kill it.
623  *
624  * Whether the kill succeeds or fails, the main loop will send the op to
625  * operation_finished() (and thus operation_finalize()) when the process
626  * goes away.
627  */
628  if (op->pid != 0) {
629  crm_info("Terminating in-flight op %s (pid %d) early because it was cancelled",
630  id, op->pid);
631  cancelled = mainloop_child_kill(op->pid);
632  if (cancelled == FALSE) {
633  crm_err("Termination of %s (pid %d) failed", id, op->pid);
634  }
635  goto done;
636  }
637 
638  /* In-flight systemd and upstart ops don't have a pid. The relevant handlers
639  * will call operation_finalize() when the operation completes.
640  * @TODO: Can we request early termination, maybe using
641  * dbus_pending_call_cancel()?
642  */
643  if (inflight_systemd_or_upstart(op)) {
644  crm_info("Will cancel %s op %s when in-flight instance completes",
645  op->standard, op->id);
646  cancelled = FALSE;
647  goto done;
648  }
649 
650  /* Otherwise, operation is not in-flight, just report as cancelled */
652  if (op->opaque->callback) {
653  op->opaque->callback(op);
654  }
655 
656  blocked_ops = g_list_remove(blocked_ops, op);
658  cancelled = TRUE;
659 
660 done:
661  free(id);
662  return cancelled;
663 }
664 
665 gboolean
666 services_action_kick(const char *name, const char *action, int interval /* ms */)
667 {
668  svc_action_t * op = NULL;
669  char *id = generate_op_key(name, action, interval);
670 
671  init_recurring_actions();
672  op = g_hash_table_lookup(recurring_actions, id);
673  free(id);
674 
675  if (op == NULL) {
676  return FALSE;
677  }
678 
679 
680  if (op->pid || inflight_systemd_or_upstart(op)) {
681  return TRUE;
682  } else {
683  if (op->opaque->repeat_timer) {
684  g_source_remove(op->opaque->repeat_timer);
685  op->opaque->repeat_timer = 0;
686  }
688  return TRUE;
689  }
690 
691 }
692 
701 static gboolean
702 handle_duplicate_recurring(svc_action_t * op)
703 {
704  svc_action_t * dup = NULL;
705 
706  /* check for duplicates */
707  dup = g_hash_table_lookup(recurring_actions, op->id);
708 
709  if (dup && (dup != op)) {
710  /* update user data */
711  if (op->opaque->callback) {
712  dup->opaque->callback = op->opaque->callback;
713  dup->cb_data = op->cb_data;
714  op->cb_data = NULL;
715  }
716  /* immediately execute the next interval */
717  if (dup->pid != 0) {
718  if (op->opaque->repeat_timer) {
719  g_source_remove(op->opaque->repeat_timer);
720  op->opaque->repeat_timer = 0;
721  }
723  }
724  /* free the duplicate */
726  return TRUE;
727  }
728 
729  return FALSE;
730 }
731 
732 inline static gboolean
733 action_exec_helper(svc_action_t * op)
734 {
735  /* Whether a/synchronous must be decided (op->synchronous) beforehand. */
736  if (op->standard
737  && (strcasecmp(op->standard, PCMK_RESOURCE_CLASS_UPSTART) == 0)) {
738 #if SUPPORT_UPSTART
739  return upstart_job_exec(op);
740 #endif
741  } else if (op->standard && strcasecmp(op->standard,
743 #if SUPPORT_SYSTEMD
744  return systemd_unit_exec(op);
745 #endif
746  } else {
747  return services_os_action_execute(op);
748  }
749  /* The 'op' has probably been freed if the execution functions return TRUE
750  for the asynchronous 'op'. */
751  /* Avoid using the 'op' in here. */
752 
753  return FALSE;
754 }
755 
756 void
758 {
759  if (op == NULL) {
760  return;
761  }
762 
763  CRM_ASSERT(op->synchronous == FALSE);
764 
765  /* keep track of ops that are in-flight to avoid collisions in the same namespace */
766  if (op->rsc) {
767  inflight_ops = g_list_append(inflight_ops, op);
768  }
769 }
770 
777 void
779 {
780  /* Op is no longer in-flight or blocked */
781  inflight_ops = g_list_remove(inflight_ops, op);
782  blocked_ops = g_list_remove(blocked_ops, op);
783 
784  /* Op is no longer blocking other ops, so check if any need to run */
785  handle_blocked_ops();
786 }
787 
788 gboolean
789 services_action_async(svc_action_t * op, void (*action_callback) (svc_action_t *))
790 {
791  op->synchronous = false;
792  if (action_callback) {
793  op->opaque->callback = action_callback;
794  }
795 
796  if (op->interval > 0) {
797  init_recurring_actions();
798  if (handle_duplicate_recurring(op) == TRUE) {
799  /* entry rescheduled, dup freed */
800  /* exit early */
801  return TRUE;
802  }
803  g_hash_table_replace(recurring_actions, op->id, op);
804  }
805 
806  if (op->rsc && is_op_blocked(op->rsc)) {
807  blocked_ops = g_list_append(blocked_ops, op);
808  return TRUE;
809  }
810 
811  return action_exec_helper(op);
812 }
813 
814 
815 static gboolean processing_blocked_ops = FALSE;
816 
817 gboolean
818 is_op_blocked(const char *rsc)
819 {
820  GList *gIter = NULL;
821  svc_action_t *op = NULL;
822 
823  for (gIter = inflight_ops; gIter != NULL; gIter = gIter->next) {
824  op = gIter->data;
825  if (safe_str_eq(op->rsc, rsc)) {
826  return TRUE;
827  }
828  }
829 
830  return FALSE;
831 }
832 
833 static void
834 handle_blocked_ops(void)
835 {
836  GList *executed_ops = NULL;
837  GList *gIter = NULL;
838  svc_action_t *op = NULL;
839  gboolean res = FALSE;
840 
841  if (processing_blocked_ops) {
842  /* avoid nested calling of this function */
843  return;
844  }
845 
846  processing_blocked_ops = TRUE;
847 
848  /* n^2 operation here, but blocked ops are incredibly rare. this list
849  * will be empty 99% of the time. */
850  for (gIter = blocked_ops; gIter != NULL; gIter = gIter->next) {
851  op = gIter->data;
852  if (is_op_blocked(op->rsc)) {
853  continue;
854  }
855  executed_ops = g_list_append(executed_ops, op);
856  res = action_exec_helper(op);
857  if (res == FALSE) {
859  /* this can cause this function to be called recursively
860  * which is why we have processing_blocked_ops static variable */
861  operation_finalize(op);
862  }
863  }
864 
865  for (gIter = executed_ops; gIter != NULL; gIter = gIter->next) {
866  op = gIter->data;
867  blocked_ops = g_list_remove(blocked_ops, op);
868  }
869  g_list_free(executed_ops);
870 
871  processing_blocked_ops = FALSE;
872 }
873 
874 #define lsb_metadata_template \
875  "<?xml version='1.0'?>\n" \
876  "<!DOCTYPE resource-agent SYSTEM 'ra-api-1.dtd'>\n" \
877  "<resource-agent name='%s' version='" PCMK_DEFAULT_AGENT_VERSION "'>\n" \
878  " <version>1.0</version>\n" \
879  " <longdesc lang='en'>\n" \
880  "%s" \
881  " </longdesc>\n" \
882  " <shortdesc lang='en'>%s</shortdesc>\n" \
883  " <parameters>\n" \
884  " </parameters>\n" \
885  " <actions>\n" \
886  " <action name='meta-data' timeout='5' />\n" \
887  " <action name='start' timeout='15' />\n" \
888  " <action name='stop' timeout='15' />\n" \
889  " <action name='status' timeout='15' />\n" \
890  " <action name='restart' timeout='15' />\n" \
891  " <action name='force-reload' timeout='15' />\n" \
892  " <action name='monitor' timeout='15' interval='15' />\n" \
893  " </actions>\n" \
894  " <special tag='LSB'>\n" \
895  " <Provides>%s</Provides>\n" \
896  " <Required-Start>%s</Required-Start>\n" \
897  " <Required-Stop>%s</Required-Stop>\n" \
898  " <Should-Start>%s</Should-Start>\n" \
899  " <Should-Stop>%s</Should-Stop>\n" \
900  " <Default-Start>%s</Default-Start>\n" \
901  " <Default-Stop>%s</Default-Stop>\n" \
902  " </special>\n" \
903  "</resource-agent>\n"
904 
905 /* See "Comment Conventions for Init Scripts" in the LSB core specification at:
906  * http://refspecs.linuxfoundation.org/lsb.shtml
907  */
908 #define LSB_INITSCRIPT_INFOBEGIN_TAG "### BEGIN INIT INFO"
909 #define LSB_INITSCRIPT_INFOEND_TAG "### END INIT INFO"
910 #define PROVIDES "# Provides:"
911 #define REQ_START "# Required-Start:"
912 #define REQ_STOP "# Required-Stop:"
913 #define SHLD_START "# Should-Start:"
914 #define SHLD_STOP "# Should-Stop:"
915 #define DFLT_START "# Default-Start:"
916 #define DFLT_STOP "# Default-Stop:"
917 #define SHORT_DSCR "# Short-Description:"
918 #define DESCRIPTION "# Description:"
919 
920 #define lsb_meta_helper_free_value(m) \
921  do { \
922  if ((m) != NULL) { \
923  xmlFree(m); \
924  (m) = NULL; \
925  } \
926  } while(0)
927 
938 static inline gboolean
939 lsb_meta_helper_get_value(const char *line, char **value, const char *prefix)
940 {
941  if (!*value && crm_starts_with(line, prefix)) {
942  *value = (char *)xmlEncodeEntitiesReentrant(NULL, BAD_CAST line+strlen(prefix));
943  return TRUE;
944  }
945  return FALSE;
946 }
947 
948 #define DESC_MAX 2048
949 
950 static int
951 lsb_get_metadata(const char *type, char **output)
952 {
953  char ra_pathname[PATH_MAX] = { 0, };
954  FILE *fp = NULL;
955  char buffer[1024] = { 0, };
956  char *provides = NULL;
957  char *req_start = NULL;
958  char *req_stop = NULL;
959  char *shld_start = NULL;
960  char *shld_stop = NULL;
961  char *dflt_start = NULL;
962  char *dflt_stop = NULL;
963  char *s_dscrpt = NULL;
964  char *xml_l_dscrpt = NULL;
965  int offset = 0;
966  bool in_header = FALSE;
967  char description[DESC_MAX] = { 0, };
968 
969  if (type[0] == '/') {
970  snprintf(ra_pathname, sizeof(ra_pathname), "%s", type);
971  } else {
972  snprintf(ra_pathname, sizeof(ra_pathname), "%s/%s",
973  LSB_ROOT_DIR, type);
974  }
975 
976  crm_trace("Looking into %s", ra_pathname);
977  fp = fopen(ra_pathname, "r");
978  if (fp == NULL) {
979  return -errno;
980  }
981 
982  /* Enter into the LSB-compliant comment block */
983  while (fgets(buffer, sizeof(buffer), fp)) {
984 
985  // Ignore lines up to and including the block delimiter
987  in_header = TRUE;
988  continue;
989  }
990  if (!in_header) {
991  continue;
992  }
993 
994  /* Assume each of the following eight arguments contain one line */
995  if (lsb_meta_helper_get_value(buffer, &provides, PROVIDES)) {
996  continue;
997  }
998  if (lsb_meta_helper_get_value(buffer, &req_start, REQ_START)) {
999  continue;
1000  }
1001  if (lsb_meta_helper_get_value(buffer, &req_stop, REQ_STOP)) {
1002  continue;
1003  }
1004  if (lsb_meta_helper_get_value(buffer, &shld_start, SHLD_START)) {
1005  continue;
1006  }
1007  if (lsb_meta_helper_get_value(buffer, &shld_stop, SHLD_STOP)) {
1008  continue;
1009  }
1010  if (lsb_meta_helper_get_value(buffer, &dflt_start, DFLT_START)) {
1011  continue;
1012  }
1013  if (lsb_meta_helper_get_value(buffer, &dflt_stop, DFLT_STOP)) {
1014  continue;
1015  }
1016  if (lsb_meta_helper_get_value(buffer, &s_dscrpt, SHORT_DSCR)) {
1017  continue;
1018  }
1019 
1020  /* Long description may cross multiple lines */
1021  if ((offset == 0) // haven't already found long description
1022  && crm_starts_with(buffer, DESCRIPTION)) {
1023  bool processed_line = TRUE;
1024 
1025  // Get remainder of description line itself
1026  offset += snprintf(description, DESC_MAX, "%s",
1027  buffer + strlen(DESCRIPTION));
1028 
1029  // Read any continuation lines of the description
1030  buffer[0] = '\0';
1031  while (fgets(buffer, sizeof(buffer), fp)) {
1032  if (crm_starts_with(buffer, "# ")
1033  || crm_starts_with(buffer, "#\t")) {
1034  /* '#' followed by a tab or more than one space indicates a
1035  * continuation of the long description.
1036  */
1037  offset += snprintf(description + offset, DESC_MAX - offset,
1038  "%s", buffer + 1);
1039  } else {
1040  /* This line is not part of the long description,
1041  * so continue with normal processing.
1042  */
1043  processed_line = FALSE;
1044  break;
1045  }
1046  }
1047 
1048  // Make long description safe to use in XML
1049  xml_l_dscrpt = (char *)xmlEncodeEntitiesReentrant(NULL, BAD_CAST(description));
1050 
1051  if (processed_line) {
1052  // We grabbed the line into the long description
1053  continue;
1054  }
1055  }
1056 
1057  // Stop if we leave the header block
1059  break;
1060  }
1061  if (buffer[0] != '#') {
1062  break;
1063  }
1064  }
1065  fclose(fp);
1066 
1067  *output = crm_strdup_printf(lsb_metadata_template, type,
1068  (xml_l_dscrpt? xml_l_dscrpt : type),
1069  (s_dscrpt? s_dscrpt : type),
1070  (provides? provides : ""),
1071  (req_start? req_start : ""),
1072  (req_stop? req_stop : ""),
1073  (shld_start? shld_start : ""),
1074  (shld_stop? shld_stop : ""),
1075  (dflt_start? dflt_start : ""),
1076  (dflt_stop? dflt_stop : ""));
1077 
1078  lsb_meta_helper_free_value(xml_l_dscrpt);
1079  lsb_meta_helper_free_value(s_dscrpt);
1080  lsb_meta_helper_free_value(provides);
1081  lsb_meta_helper_free_value(req_start);
1082  lsb_meta_helper_free_value(req_stop);
1083  lsb_meta_helper_free_value(shld_start);
1084  lsb_meta_helper_free_value(shld_stop);
1085  lsb_meta_helper_free_value(dflt_start);
1086  lsb_meta_helper_free_value(dflt_stop);
1087 
1088  crm_trace("Created fake metadata: %llu",
1089  (unsigned long long) strlen(*output));
1090  return pcmk_ok;
1091 }
1092 
1093 #if SUPPORT_NAGIOS
1094 static int
1095 nagios_get_metadata(const char *type, char **output)
1096 {
1097  int rc = pcmk_ok;
1098  FILE *file_strm = NULL;
1099  int start = 0, length = 0, read_len = 0;
1100  char *metadata_file = crm_strdup_printf("%s/%s.xml",
1101  NAGIOS_METADATA_DIR, type);
1102 
1103  file_strm = fopen(metadata_file, "r");
1104  if (file_strm == NULL) {
1105  crm_err("Metadata file %s does not exist", metadata_file);
1106  free(metadata_file);
1107  return -EIO;
1108  }
1109 
1110  /* see how big the file is */
1111  start = ftell(file_strm);
1112  fseek(file_strm, 0L, SEEK_END);
1113  length = ftell(file_strm);
1114  fseek(file_strm, 0L, start);
1115 
1116  CRM_ASSERT(length >= 0);
1117  CRM_ASSERT(start == ftell(file_strm));
1118 
1119  if (length <= 0) {
1120  crm_info("%s was not valid", metadata_file);
1121  free(*output);
1122  *output = NULL;
1123  rc = -EIO;
1124 
1125  } else {
1126  crm_trace("Reading %d bytes from file", length);
1127  *output = calloc(1, (length + 1));
1128  read_len = fread(*output, 1, length, file_strm);
1129  if (read_len != length) {
1130  crm_err("Calculated and read bytes differ: %d vs. %d",
1131  length, read_len);
1132  free(*output);
1133  *output = NULL;
1134  rc = -EIO;
1135  }
1136  }
1137 
1138  fclose(file_strm);
1139  free(metadata_file);
1140  return rc;
1141 }
1142 #endif
1143 
1144 #if SUPPORT_HEARTBEAT
1145 /* strictly speaking, support for class=heartbeat style scripts
1146  * does not require "heartbeat support" to be enabled.
1147  * But since those scripts are part of the "heartbeat" package usually,
1148  * and are very unlikely to be present in any other deployment,
1149  * I leave it inside this ifdef.
1150  *
1151  * Yes, I know, these are legacy and should die,
1152  * or at least be rewritten to be a proper OCF style agent.
1153  * But they exist, and custom scripts following these rules do, too.
1154  *
1155  * Taken from the old "glue" lrmd, see
1156  * http://hg.linux-ha.org/glue/file/0a7add1d9996/lib/plugins/lrm/raexechb.c#l49
1157  * http://hg.linux-ha.org/glue/file/0a7add1d9996/lib/plugins/lrm/raexechb.c#l393
1158  */
1159 
1160 static const char hb_metadata_template[] =
1161  "<?xml version='1.0'?>\n"
1162  "<!DOCTYPE resource-agent SYSTEM 'ra-api-1.dtd'>\n"
1163  "<resource-agent name='%s' version='" PCMK_DEFAULT_AGENT_VERSION "'>\n"
1164  "<version>1.0</version>\n"
1165  "<longdesc lang='en'>\n"
1166  "%s"
1167  "</longdesc>\n"
1168  "<shortdesc lang='en'>%s</shortdesc>\n"
1169  "<parameters>\n"
1170  "<parameter name='1' unique='1' required='0'>\n"
1171  "<longdesc lang='en'>\n"
1172  "This argument will be passed as the first argument to the "
1173  "heartbeat resource agent (assuming it supports one)\n"
1174  "</longdesc>\n"
1175  "<shortdesc lang='en'>argv[1]</shortdesc>\n"
1176  "<content type='string' default=' ' />\n"
1177  "</parameter>\n"
1178  "<parameter name='2' unique='1' required='0'>\n"
1179  "<longdesc lang='en'>\n"
1180  "This argument will be passed as the second argument to the "
1181  "heartbeat resource agent (assuming it supports one)\n"
1182  "</longdesc>\n"
1183  "<shortdesc lang='en'>argv[2]</shortdesc>\n"
1184  "<content type='string' default=' ' />\n"
1185  "</parameter>\n"
1186  "<parameter name='3' unique='1' required='0'>\n"
1187  "<longdesc lang='en'>\n"
1188  "This argument will be passed as the third argument to the "
1189  "heartbeat resource agent (assuming it supports one)\n"
1190  "</longdesc>\n"
1191  "<shortdesc lang='en'>argv[3]</shortdesc>\n"
1192  "<content type='string' default=' ' />\n"
1193  "</parameter>\n"
1194  "<parameter name='4' unique='1' required='0'>\n"
1195  "<longdesc lang='en'>\n"
1196  "This argument will be passed as the fourth argument to the "
1197  "heartbeat resource agent (assuming it supports one)\n"
1198  "</longdesc>\n"
1199  "<shortdesc lang='en'>argv[4]</shortdesc>\n"
1200  "<content type='string' default=' ' />\n"
1201  "</parameter>\n"
1202  "<parameter name='5' unique='1' required='0'>\n"
1203  "<longdesc lang='en'>\n"
1204  "This argument will be passed as the fifth argument to the "
1205  "heartbeat resource agent (assuming it supports one)\n"
1206  "</longdesc>\n"
1207  "<shortdesc lang='en'>argv[5]</shortdesc>\n"
1208  "<content type='string' default=' ' />\n"
1209  "</parameter>\n"
1210  "</parameters>\n"
1211  "<actions>\n"
1212  "<action name='start' timeout='15' />\n"
1213  "<action name='stop' timeout='15' />\n"
1214  "<action name='status' timeout='15' />\n"
1215  "<action name='monitor' timeout='15' interval='15' start-delay='15' />\n"
1216  "<action name='meta-data' timeout='5' />\n"
1217  "</actions>\n"
1218  "<special tag='heartbeat'>\n"
1219  "</special>\n"
1220  "</resource-agent>\n";
1221 
1222 static int
1223 heartbeat_get_metadata(const char *type, char **output)
1224 {
1225  *output = crm_strdup_printf(hb_metadata_template, type, type, type);
1226  crm_trace("Created fake metadata: %llu",
1227  (unsigned long long) strlen(*output));
1228  return pcmk_ok;
1229 }
1230 #endif
1231 
1232 static gboolean
1233 action_get_metadata(svc_action_t *op)
1234 {
1235  const char *class = op->standard;
1236 
1237  if (op->agent == NULL) {
1238  crm_err("meta-data requested without specifying agent");
1239  return FALSE;
1240  }
1241 
1242  if (class == NULL) {
1243  crm_err("meta-data requested for agent %s without specifying class",
1244  op->agent);
1245  return FALSE;
1246  }
1247 
1248  if (!strcmp(class, PCMK_RESOURCE_CLASS_SERVICE)) {
1249  class = resources_find_service_class(op->agent);
1250  }
1251 
1252  if (class == NULL) {
1253  crm_err("meta-data requested for %s, but could not determine class",
1254  op->agent);
1255  return FALSE;
1256  }
1257 
1258  if (safe_str_eq(class, PCMK_RESOURCE_CLASS_LSB)) {
1259  return (lsb_get_metadata(op->agent, &op->stdout_data) >= 0);
1260  }
1261 
1262 #if SUPPORT_NAGIOS
1264  return (nagios_get_metadata(op->agent, &op->stdout_data) >= 0);
1265  }
1266 #endif
1267 
1268 #if SUPPORT_HEARTBEAT
1269  if (safe_str_eq(class, PCMK_RESOURCE_CLASS_HB)) {
1270  return (heartbeat_get_metadata(op->agent, &op->stdout_data) >= 0);
1271  }
1272 #endif
1273 
1274  return action_exec_helper(op);
1275 }
1276 
1277 gboolean
1279 {
1280  gboolean rc = TRUE;
1281 
1282  if (op == NULL) {
1283  crm_trace("No operation to execute");
1284  return FALSE;
1285  }
1286 
1287  op->synchronous = true;
1288 
1289  if (safe_str_eq(op->action, "meta-data")) {
1290  /* Synchronous meta-data operations are handled specially. Since most
1291  * resource classes don't provide any meta-data, it has to be
1292  * synthesized from available information about the agent.
1293  *
1294  * services_action_async() doesn't treat meta-data actions specially, so
1295  * it will result in an error for classes that don't support the action.
1296  */
1297  rc = action_get_metadata(op);
1298  } else {
1299  rc = action_exec_helper(op);
1300  }
1301  crm_trace(" > %s_%s_%d: %s = %d",
1302  op->rsc, op->action, op->interval, op->opaque->exec, op->rc);
1303  if (op->stdout_data) {
1304  crm_trace(" > stdout: %s", op->stdout_data);
1305  }
1306  if (op->stderr_data) {
1307  crm_trace(" > stderr: %s", op->stderr_data);
1308  }
1309  return rc;
1310 }
1311 
1312 GList *
1313 get_directory_list(const char *root, gboolean files, gboolean executable)
1314 {
1315  return services_os_get_directory_list(root, files, executable);
1316 }
1317 
1318 GList *
1320 {
1322 }
1323 
1324 #if SUPPORT_HEARTBEAT
1325 static GList *
1326 resources_os_list_hb_agents(void)
1327 {
1328  return services_os_get_directory_list(HB_RA_DIR, TRUE, TRUE);
1329 }
1330 #endif
1331 
1332 GList *
1334 {
1335  GList *standards = NULL;
1336  GList *agents = NULL;
1337 
1338  standards = g_list_append(standards, strdup(PCMK_RESOURCE_CLASS_OCF));
1339  standards = g_list_append(standards, strdup(PCMK_RESOURCE_CLASS_LSB));
1340  standards = g_list_append(standards, strdup(PCMK_RESOURCE_CLASS_SERVICE));
1341 
1342 #if SUPPORT_SYSTEMD
1343  agents = systemd_unit_listall();
1344  if (agents) {
1345  standards = g_list_append(standards,
1346  strdup(PCMK_RESOURCE_CLASS_SYSTEMD));
1347  g_list_free_full(agents, free);
1348  }
1349 #endif
1350 
1351 #if SUPPORT_UPSTART
1352  agents = upstart_job_listall();
1353  if (agents) {
1354  standards = g_list_append(standards,
1355  strdup(PCMK_RESOURCE_CLASS_UPSTART));
1356  g_list_free_full(agents, free);
1357  }
1358 #endif
1359 
1360 #if SUPPORT_NAGIOS
1362  if (agents) {
1363  standards = g_list_append(standards,
1364  strdup(PCMK_RESOURCE_CLASS_NAGIOS));
1365  g_list_free_full(agents, free);
1366  }
1367 #endif
1368 
1369 #if SUPPORT_HEARTBEAT
1370  standards = g_list_append(standards, strdup(PCMK_RESOURCE_CLASS_HB));
1371 #endif
1372 
1373  return standards;
1374 }
1375 
1376 GList *
1377 resources_list_providers(const char *standard)
1378 {
1379  if (crm_provider_required(standard)) {
1381  }
1382 
1383  return NULL;
1384 }
1385 
1386 GList *
1387 resources_list_agents(const char *standard, const char *provider)
1388 {
1389  if ((standard == NULL)
1390  || (strcasecmp(standard, PCMK_RESOURCE_CLASS_SERVICE) == 0)) {
1391 
1392  GList *tmp1;
1393  GList *tmp2;
1394  GList *result = resources_os_list_lsb_agents();
1395 
1396  if (standard == NULL) {
1397  tmp1 = result;
1398  tmp2 = resources_os_list_ocf_agents(NULL);
1399  if (tmp2) {
1400  result = g_list_concat(tmp1, tmp2);
1401  }
1402  }
1403 #if SUPPORT_SYSTEMD
1404  tmp1 = result;
1405  tmp2 = systemd_unit_listall();
1406  if (tmp2) {
1407  result = g_list_concat(tmp1, tmp2);
1408  }
1409 #endif
1410 
1411 #if SUPPORT_UPSTART
1412  tmp1 = result;
1413  tmp2 = upstart_job_listall();
1414  if (tmp2) {
1415  result = g_list_concat(tmp1, tmp2);
1416  }
1417 #endif
1418 
1419  return result;
1420 
1421  } else if (strcasecmp(standard, PCMK_RESOURCE_CLASS_OCF) == 0) {
1422  return resources_os_list_ocf_agents(provider);
1423  } else if (strcasecmp(standard, PCMK_RESOURCE_CLASS_LSB) == 0) {
1425 #if SUPPORT_HEARTBEAT
1426  } else if (strcasecmp(standard, PCMK_RESOURCE_CLASS_HB) == 0) {
1427  return resources_os_list_hb_agents();
1428 #endif
1429 #if SUPPORT_SYSTEMD
1430  } else if (strcasecmp(standard, PCMK_RESOURCE_CLASS_SYSTEMD) == 0) {
1431  return systemd_unit_listall();
1432 #endif
1433 #if SUPPORT_UPSTART
1434  } else if (strcasecmp(standard, PCMK_RESOURCE_CLASS_UPSTART) == 0) {
1435  return upstart_job_listall();
1436 #endif
1437 #if SUPPORT_NAGIOS
1438  } else if (strcasecmp(standard, PCMK_RESOURCE_CLASS_NAGIOS) == 0) {
1440 #endif
1441  }
1442 
1443  return NULL;
1444 }
gboolean services_action_cancel(const char *name, const char *action, int interval)
Cancel a recurring action.
Definition: services.c:603
Services API.
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:164
#define lsb_metadata_template
Definition: services.c:874
void(* callback)(svc_action_t *op)
A dumping ground.
#define SHORT_DSCR
Definition: services.c:917
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:1377
char * standard
Definition: services.h:168
gboolean upstart_job_exists(const char *name)
Definition: upstart.c:230
gboolean mainloop_child_kill(pid_t pid)
Definition: mainloop.c:1042
char * id
Definition: services.h:163
svc_action_t * resources_action_create(const char *name, const char *standard, const char *provider, const char *agent, const char *action, int interval, int timeout, GHashTable *params, enum svc_action_flags flags)
Create a new resource action.
Definition: services.c:165
mainloop_io_t * stderr_gsource
GList * resources_os_list_ocf_agents(const char *provider)
GList * resources_os_list_ocf_providers(void)
#define PCMK_RESOURCE_CLASS_SYSTEMD
Definition: services.h:60
#define pcmk_ok
Definition: error.h:42
#define PROVIDES
Definition: services.c:910
gboolean recurring_action_timer(gpointer data)
GList * services_os_get_directory_list(const char *root, gboolean files, gboolean executable)
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Definition: services.c:789
char * rsc
Definition: services.h:164
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
Definition: utils.c:424
int interval
Definition: services.h:166
gboolean services_os_action_execute(svc_action_t *op)
G_GNUC_INTERNAL GList * resources_os_list_nagios_agents(void)
#define DESCRIPTION
Definition: services.c:918
svc_action_flags
Definition: services.h:156
#define DESC_MAX
Definition: services.c:948
gboolean upstart_job_exec(svc_action_t *op)
Definition: upstart.c:417
gboolean is_op_blocked(const char *rsc)
Definition: services.c:818
Wrappers for and extensions to glib mainloop.
bool crm_starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
Definition: strings.c:252
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Definition: services.c:367
GList * resources_os_list_lsb_agents(void)
#define SHLD_START
Definition: services.c:913
enum svc_action_flags flags
Definition: services.h:182
#define crm_warn(fmt, args...)
Definition: logging.h:249
GList * services_list(void)
Definition: services.c:1319
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:57
gboolean cancel_recurring_action(svc_action_t *op)
Definition: services.c:577
svc_action_private_t * opaque
Definition: services.h:195
GList * upstart_job_listall(void)
Definition: upstart.c:149
#define OCF_ROOT_DIR
Definition: services.h:39
#define crm_debug(fmt, args...)
Definition: logging.h:253
#define REQ_START
Definition: services.c:911
gboolean operation_finalize(svc_action_t *op)
char * stdout_data
Definition: services.h:185
svc_action_t * services_alert_create(const char *id, const char *exec, int timeout, GHashTable *params, int sequence, void *cb_data)
Create an alert agent action.
Definition: services.c:405
gboolean systemd_unit_exists(const char *name)
Definition: systemd.c:465
#define PCMK_RESOURCE_CLASS_SERVICE
Definition: services.h:58
GHashTable * params
Definition: services.h:173
#define LSB_INITSCRIPT_INFOEND_TAG
Definition: services.c:909
#define crm_trace(fmt, args...)
Definition: logging.h:254
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:453
char * agent
Definition: services.h:170
int synchronous
Definition: services.h:181
#define LSB_INITSCRIPT_INFOBEGIN_TAG
Definition: services.c:908
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:1278
#define SUPPORT_HEARTBEAT
Definition: config.h:732
#define LSB_ROOT_DIR
Definition: services.h:43
int sequence
Definition: services.h:179
#define SHLD_STOP
Definition: services.c:914
gboolean services_action_kick(const char *name, const char *action, int interval)
Definition: services.c:666
GList * systemd_unit_listall(void)
Definition: systemd.c:358
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
Definition: services.c:70
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:1387
#define MAX_ARGC
char * args[MAX_ARGC]
void services_add_inflight_op(svc_action_t *op)
Definition: services.c:757
GList * resources_list_standards(void)
Definition: services.c:1333
void services_untrack_op(svc_action_t *op)
Definition: services.c:778
char * action
Definition: services.h:165
GList * get_directory_list(const char *root, gboolean files, gboolean executable)
Get a list of files or directories in a given path.
Definition: services.c:1313
#define PCMK_RESOURCE_CLASS_NAGIOS
Definition: services.h:63
#define PCMK_RESOURCE_CLASS_LSB
Definition: services.h:59
#define NAGIOS_PLUGIN_DIR
Definition: config.h:621
#define CRM_META
Definition: crm.h:53
#define crm_err(fmt, args...)
Definition: logging.h:248
#define PCMK_RESOURCE_CLASS_UPSTART
Definition: services.h:61
#define PCMK_RESOURCE_CLASS_HB
Definition: services.h:62
int services_action_user(svc_action_t *op, const char *user)
Set the user and group that an action will execute as.
Definition: services.c:435
#define PCMK_DEFAULT_AGENT_VERSION
Definition: services.h:73
#define DIMOF(a)
Definition: crm.h:39
mainloop_io_t * stdout_gsource
#define CRM_ASSERT(expr)
Definition: error.h:35
#define XML_ATTR_CRM_VERSION
Definition: msg_xml.h:84
#define REQ_STOP
Definition: services.c:912
#define DFLT_STOP
Definition: services.c:916
void mainloop_del_fd(mainloop_io_t *client)
Definition: mainloop.c:854
void * cb_data
Definition: services.h:193
void services_action_cleanup(svc_action_t *op)
Definition: services.c:489
bool crm_provider_required(const char *standard)
Check whether a resource standard requires a provider to be specified.
Definition: utils.c:1489
char * generate_op_key(const char *rsc_id, const char *op_type, int interval)
Generate an operation key.
Definition: operations.c:37
#define safe_str_eq(a, b)
Definition: util.h:72
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
void services_action_free(svc_action_t *op)
Definition: services.c:525
#define DFLT_START
Definition: services.c:915
char * provider
Definition: services.h:169
gboolean systemd_unit_exec(svc_action_t *op)
Definition: systemd.c:756
#define crm_info(fmt, args...)
Definition: logging.h:251
#define NAGIOS_METADATA_DIR
Definition: config.h:618
uint64_t flags
Definition: remote.c:156
svc_action_t * services_action_create(const char *name, const char *action, int interval, int timeout)
Definition: services.c:52
enum crm_ais_msg_types type
Definition: internal.h:51
#define lsb_meta_helper_free_value(m)
Definition: services.c:920
char * stderr_data
Definition: services.h:184