pacemaker  2.0.4-2deceaa
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, // Deprecated (see PCMK_LRM_OP_NOT_CONNECTED)
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 {
131 };
132 
139 
142 };
143 
145  /* On timeout, only kill pid, do not kill entire pid group */
148 };
149 
151 typedef struct svc_action_s {
152  char *id;
153  char *rsc;
154  char *action;
155  guint interval_ms;
156 
157  char *standard;
158  char *provider;
159  char *agent;
160 
161  int timeout;
162  GHashTable *params; /* used for setting up environment for ocf-ra &
163  alert agents
164  and to be sent via stdin for fence-agents
165  */
166 
167  int rc;
168  int pid;
169  int cancel;
170  int status;
171  int sequence;
175 
176  char *stderr_data;
177  char *stdout_data;
178 
185  void *cb_data;
186 
188 } svc_action_t;
189 
200  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
201 
208  GList *services_list(void);
209 
218  GList *resources_list_providers(const char *standard);
219 
229  GList *resources_list_agents(const char *standard, const char *provider);
230 
237  GList *resources_list_standards(void);
238 
248  gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent);
249 
250 svc_action_t *services_action_create(const char *name, const char *action,
251  guint interval_ms, int timeout /* ms */);
252 
271 svc_action_t *resources_action_create(const char *name, const char *standard,
272  const char *provider, const char *agent,
273  const char *action, guint interval_ms,
274  int timeout /* ms */, GHashTable *params,
275  enum svc_action_flags flags);
276 
280 gboolean services_action_kick(const char *name, const char *action,
281  guint interval_ms);
282 
283  const char *resources_find_service_class(const char *agent);
284 
298  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
299 
302  int services_action_user(svc_action_t *op, const char *user);
303 
304  gboolean services_action_sync(svc_action_t * op);
305 
317  void (*action_callback) (svc_action_t *),
318  void (*action_fork_callback) (svc_action_t *));
319 
320  gboolean services_action_async(svc_action_t * op,
321  void (*action_callback) (svc_action_t *));
322 
323 gboolean services_action_cancel(const char *name, const char *action,
324  guint interval_ms);
325 
326 /* functions for alert agents */
327 svc_action_t *services_alert_create(const char *id, const char *exec,
328  int timeout, GHashTable *params,
329  int sequence, void *cb_data);
331  void (*cb)(svc_action_t *op));
332 
333  static inline const char *services_lrm_status_str(enum op_status status) {
334  switch (status) {
335  case PCMK_LRM_OP_PENDING:
336  return "pending";
337  case PCMK_LRM_OP_DONE:return "complete";
338  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
339  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
340  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
341  case PCMK_LRM_OP_ERROR:return "Error";
342  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
343  case PCMK_LRM_OP_NOT_CONNECTED:return "No executor connection";
344  case PCMK_LRM_OP_INVALID:return "Cannot execute now";
345  default:return "UNKNOWN!";
346  }
347  }
348 
349  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
350  switch (code) {
351  case PCMK_OCF_OK:
352  return "ok";
354  return "error";
356  return "invalid parameter";
358  return "unimplemented feature";
360  return "insufficient privileges";
362  return "not installed";
364  return "not configured";
366  return "not running";
368  return "master";
370  return "master (failed)";
371  case PCMK_OCF_SIGNAL:
372  return "OCF_SIGNAL";
374  return "OCF_NOT_SUPPORTED";
375  case PCMK_OCF_PENDING:
376  return "OCF_PENDING";
377  case PCMK_OCF_CANCELLED:
378  return "OCF_CANCELLED";
379  case PCMK_OCF_TIMEOUT:
380  return "OCF_TIMEOUT";
382  return "OCF_OTHER_ERROR";
383  case PCMK_OCF_DEGRADED:
384  return "OCF_DEGRADED";
386  return "OCF_DEGRADED_MASTER";
387  default:
388  return "unknown";
389  }
390  }
391 
400  static inline enum ocf_exitcode
401  services_get_ocf_exitcode(const char *action, int lsb_exitcode)
402  {
403  /* For non-status actions, LSB and OCF share error code meaning <= 7 */
404  if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
405  if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) {
406  return PCMK_OCF_UNKNOWN_ERROR;
407  }
408  return (enum ocf_exitcode)lsb_exitcode;
409  }
410 
411  /* status has different return codes */
412  switch (lsb_exitcode) {
413  case PCMK_LSB_STATUS_OK:
414  return PCMK_OCF_OK;
416  return PCMK_OCF_NOT_INSTALLED;
422  return PCMK_OCF_NOT_RUNNING;
423  }
424  return PCMK_OCF_UNKNOWN_ERROR;
425  }
426 
427 # ifdef __cplusplus
428 }
429 # endif
430 
431 #endif /* __PCMK_SERVICES__ */
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
Definition: services.c:547
struct svc_action_s svc_action_t
void services_action_free(svc_action_t *op)
Definition: services.c:469
guint interval_ms
Definition: services.h:155
char * standard
Definition: services.h:157
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Definition: services.c:614
char * id
Definition: services.h:152
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
Definition: services.c:69
svc_action_t * services_action_create(const char *name, const char *action, guint interval_ms, int timeout)
Definition: services_lsb.c:276
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Definition: services.c:308
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:737
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:165
char * rsc
Definition: services.h:153
svc_action_flags
Definition: services.h:144
const char * action
Definition: pcmk_fence.c:29
void services_action_cleanup(svc_action_t *op)
Definition: services.c:430
enum svc_action_flags flags
Definition: services.h:174
op_status
Definition: services.h:118
svc_action_private_t * opaque
Definition: services.h:187
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:346
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:874
char * stdout_data
Definition: services.h:177
GHashTable * params
Definition: services.h:162
char * agent
Definition: services.h:159
int synchronous
Definition: services.h:173
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:955
int sequence
Definition: services.h:171
lsb_exitcode
Definition: services.h:60
nagios_exitcode
Definition: services.h:133
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:376
char * action
Definition: services.h:154
ocf_exitcode
Definition: services.h:89
GList * resources_list_standards(void)
Definition: services.c:915
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:909
lsb_status_exitcode
Definition: services.h:74
gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent)
Definition: services.c:1021
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:965
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:394
void * cb_data
Definition: services.h:185
GList * services_list(void)
Definition: services_lsb.c:284
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Definition: services.c:769
char * name
Definition: pcmk_fence.c:30
unsigned int timeout
Definition: pcmk_fence.c:31
char * provider
Definition: services.h:158
uint64_t flags
Definition: remote.c:149
int expected_rc
Definition: services.h:172
char * stderr_data
Definition: services.h:176