pacemaker  2.0.2-debe490
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
services.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2019 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef __PCMK_SERVICES__
11 # define __PCMK_SERVICES__
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
23 # include <glib.h>
24 # include <stdio.h>
25 # include <string.h>
26 # include <stdbool.h>
27 # include <sys/types.h>
28 
29 # ifndef OCF_ROOT_DIR
30 # define OCF_ROOT_DIR "/usr/lib/ocf"
31 # endif
32 
33 # ifndef LSB_ROOT_DIR
34 # define LSB_ROOT_DIR "/etc/init.d"
35 # endif
36 
37 /* TODO: Autodetect these two ?*/
38 # ifndef SYSTEMCTL
39 # define SYSTEMCTL "/bin/systemctl"
40 # endif
41 
42 /* Known resource classes */
43 #define PCMK_RESOURCE_CLASS_OCF "ocf"
44 #define PCMK_RESOURCE_CLASS_SERVICE "service"
45 #define PCMK_RESOURCE_CLASS_LSB "lsb"
46 #define PCMK_RESOURCE_CLASS_SYSTEMD "systemd"
47 #define PCMK_RESOURCE_CLASS_UPSTART "upstart"
48 #define PCMK_RESOURCE_CLASS_NAGIOS "nagios"
49 #define PCMK_RESOURCE_CLASS_STONITH "stonith"
50 
51 /* This is the string passed in the OCF_EXIT_REASON_PREFIX environment variable.
52  * The stderr output that occurs after this prefix is encountered is considered
53  * the exit reason for a completed operation.
54  */
55 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
56 
57 // Agent version to use if agent doesn't specify one
58 #define PCMK_DEFAULT_AGENT_VERSION "0.1"
59 
69 };
70 
71 /* The return codes for the status operation are not the same for other
72  * operatios - go figure
73  */
80 
81  /* custom codes should be in the 150-199 range reserved for application use */
84 };
85 
86 /* Uniform exit codes
87  * Everything is mapped to its OCF equivalent so that Pacemaker only deals with one set of codes
88  */
97  PCMK_OCF_NOT_RUNNING = 7, /* End of overlap with LSB */
100 
101 
102  /* 150-199 reserved for application use */
103  PCMK_OCF_CONNECTION_DIED = 189, /* Operation failure implied by disconnection of the LRM API to a local or remote node */
104 
105  PCMK_OCF_DEGRADED = 190, /* Active resource that is no longer 100% functional */
106  PCMK_OCF_DEGRADED_MASTER = 191, /* Promoted resource that is no longer 100% functional */
107 
108  PCMK_OCF_EXEC_ERROR = 192, /* Generic problem invoking the agent */
109  PCMK_OCF_UNKNOWN = 193, /* State of the service is unknown - used for recording in-flight operations */
115  PCMK_OCF_OTHER_ERROR = 199, /* Keep the same codes as PCMK_LSB */
116 };
117 
118 enum op_status {
129 };
130 
137 
140 };
141 
143  /* On timeout, only kill pid, do not kill entire pid group */
145 };
146 
148 typedef struct svc_action_s {
149  char *id;
150  char *rsc;
151  char *action;
152  guint interval_ms;
153 
154  char *standard;
155  char *provider;
156  char *agent;
157 
158  int timeout;
159  GHashTable *params; /* used for setting up environment for ocf-ra &
160  alert agents
161  and to be sent via stdin for fence-agents
162  */
163 
164  int rc;
165  int pid;
166  int cancel;
167  int status;
168  int sequence;
172 
173  char *stderr_data;
174  char *stdout_data;
175 
182  void *cb_data;
183 
185 } svc_action_t;
186 
197  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
198 
205  GList *services_list(void);
206 
215  GList *resources_list_providers(const char *standard);
216 
226  GList *resources_list_agents(const char *standard, const char *provider);
227 
234  GList *resources_list_standards(void);
235 
245  gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent);
246 
247 svc_action_t *services_action_create(const char *name, const char *action,
248  guint interval_ms, int timeout /* ms */);
249 
268 svc_action_t *resources_action_create(const char *name, const char *standard,
269  const char *provider, const char *agent,
270  const char *action, guint interval_ms,
271  int timeout /* ms */, GHashTable *params,
272  enum svc_action_flags flags);
273 
277 gboolean services_action_kick(const char *name, const char *action,
278  guint interval_ms);
279 
280  const char *resources_find_service_class(const char *agent);
281 
295  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
296 
299  int services_action_user(svc_action_t *op, const char *user);
300 
301  gboolean services_action_sync(svc_action_t * op);
302 
314  void (*action_callback) (svc_action_t *),
315  void (*action_fork_callback) (svc_action_t *));
316 
317  gboolean services_action_async(svc_action_t * op,
318  void (*action_callback) (svc_action_t *));
319 
320 gboolean services_action_cancel(const char *name, const char *action,
321  guint interval_ms);
322 
323 /* functions for alert agents */
324 svc_action_t *services_alert_create(const char *id, const char *exec,
325  int timeout, GHashTable *params,
326  int sequence, void *cb_data);
327 gboolean services_alert_async(svc_action_t *action,
328  void (*cb)(svc_action_t *op));
329 
330  static inline const char *services_lrm_status_str(enum op_status status) {
331  switch (status) {
332  case PCMK_LRM_OP_PENDING:
333  return "pending";
334  case PCMK_LRM_OP_DONE:return "complete";
335  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
336  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
337  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
338  case PCMK_LRM_OP_ERROR:return "Error";
339  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
340  default:return "UNKNOWN!";
341  }
342  }
343 
344  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
345  switch (code) {
346  case PCMK_OCF_OK:
347  return "ok";
349  return "unknown error";
351  return "invalid parameter";
353  return "unimplemented feature";
355  return "insufficient privileges";
357  return "not installed";
359  return "not configured";
361  return "not running";
363  return "master";
365  return "master (failed)";
366  case PCMK_OCF_SIGNAL:
367  return "OCF_SIGNAL";
369  return "OCF_NOT_SUPPORTED";
370  case PCMK_OCF_PENDING:
371  return "OCF_PENDING";
372  case PCMK_OCF_CANCELLED:
373  return "OCF_CANCELLED";
374  case PCMK_OCF_TIMEOUT:
375  return "OCF_TIMEOUT";
377  return "OCF_OTHER_ERROR";
378  case PCMK_OCF_DEGRADED:
379  return "OCF_DEGRADED";
381  return "OCF_DEGRADED_MASTER";
382  default:
383  return "unknown";
384  }
385  }
386 
395  static inline enum ocf_exitcode
396  services_get_ocf_exitcode(const char *action, int lsb_exitcode)
397  {
398  /* For non-status actions, LSB and OCF share error code meaning <= 7 */
399  if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
400  if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) {
401  return PCMK_OCF_UNKNOWN_ERROR;
402  }
403  return (enum ocf_exitcode)lsb_exitcode;
404  }
405 
406  /* status has different return codes */
407  switch (lsb_exitcode) {
408  case PCMK_LSB_STATUS_OK:
409  return PCMK_OCF_OK;
411  return PCMK_OCF_NOT_INSTALLED;
417  return PCMK_OCF_NOT_RUNNING;
418  }
419  return PCMK_OCF_UNKNOWN_ERROR;
420  }
421 
422 # ifdef __cplusplus
423 }
424 # endif
425 
426 #endif /* __PCMK_SERVICES__ */
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
Definition: services.c:541
struct svc_action_s svc_action_t
void services_action_free(svc_action_t *op)
Definition: services.c:463
guint interval_ms
Definition: services.h:152
char * standard
Definition: services.h:154
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Definition: services.c:608
char * id
Definition: services.h:149
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
Definition: services.c:63
svc_action_t * services_action_create(const char *name, const char *action, guint interval_ms, int timeout)
Definition: services_lsb.c:274
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Definition: services.c:302
gboolean services_action_async_fork_notify(svc_action_t *op, void(*action_callback)(svc_action_t *), void(*action_fork_callback)(svc_action_t *))
Definition: services.c:731
svc_action_t * resources_action_create(const char *name, const char *standard, const char *provider, const char *agent, const char *action, guint interval_ms, int timeout, GHashTable *params, enum svc_action_flags flags)
Create a new resource action.
Definition: services.c:159
char * rsc
Definition: services.h:150
svc_action_flags
Definition: services.h:142
void services_action_cleanup(svc_action_t *op)
Definition: services.c:424
enum svc_action_flags flags
Definition: services.h:171
op_status
Definition: services.h:118
svc_action_private_t * opaque
Definition: services.h:184
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:340
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:918
char * stdout_data
Definition: services.h:174
GHashTable * params
Definition: services.h:159
char * agent
Definition: services.h:156
int synchronous
Definition: services.h:170
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:999
int sequence
Definition: services.h:168
lsb_exitcode
Definition: services.h:60
nagios_exitcode
Definition: services.h:131
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:370
char * action
Definition: services.h:151
ocf_exitcode
Definition: services.h:89
GList * resources_list_standards(void)
Definition: services.c:959
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:953
lsb_status_exitcode
Definition: services.h:74
gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent)
Definition: services.c:1065
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:1009
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:388
void * cb_data
Definition: services.h:182
GList * services_list(void)
Definition: services_lsb.c:282
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Definition: services.c:762
char * provider
Definition: services.h:155
uint64_t flags
Definition: remote.c:148
int expected_rc
Definition: services.h:169
char * stderr_data
Definition: services.h:173