pacemaker  2.0.1-9e909a5bdd
Scalable High-Availability cluster resource manager
services.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2018 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 #ifndef __PCMK_SERVICES__
9 # define __PCMK_SERVICES__
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
21 # include <glib.h>
22 # include <stdio.h>
23 # include <string.h>
24 # include <stdbool.h>
25 # include <sys/types.h>
26 
27 # ifndef OCF_ROOT_DIR
28 # define OCF_ROOT_DIR "/usr/lib/ocf"
29 # endif
30 
31 # ifndef LSB_ROOT_DIR
32 # define LSB_ROOT_DIR "/etc/init.d"
33 # endif
34 
35 /* TODO: Autodetect these two ?*/
36 # ifndef SYSTEMCTL
37 # define SYSTEMCTL "/bin/systemctl"
38 # endif
39 
40 /* Known resource classes */
41 #define PCMK_RESOURCE_CLASS_OCF "ocf"
42 #define PCMK_RESOURCE_CLASS_SERVICE "service"
43 #define PCMK_RESOURCE_CLASS_LSB "lsb"
44 #define PCMK_RESOURCE_CLASS_SYSTEMD "systemd"
45 #define PCMK_RESOURCE_CLASS_UPSTART "upstart"
46 #define PCMK_RESOURCE_CLASS_NAGIOS "nagios"
47 #define PCMK_RESOURCE_CLASS_STONITH "stonith"
48 
49 /* This is the string passed in the OCF_EXIT_REASON_PREFIX environment variable.
50  * The stderr output that occurs after this prefix is encountered is considered
51  * the exit reason for a completed operation.
52  */
53 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
54 
55 // Agent version to use if agent doesn't specify one
56 #define PCMK_DEFAULT_AGENT_VERSION "0.1"
57 
67 };
68 
69 /* The return codes for the status operation are not the same for other
70  * operatios - go figure
71  */
78 
79  /* custom codes should be in the 150-199 range reserved for application use */
82 };
83 
84 /* Uniform exit codes
85  * Everything is mapped to its OCF equivalent so that Pacemaker only deals with one set of codes
86  */
95  PCMK_OCF_NOT_RUNNING = 7, /* End of overlap with LSB */
98 
99 
100  /* 150-199 reserved for application use */
101  PCMK_OCF_CONNECTION_DIED = 189, /* Operation failure implied by disconnection of the LRM API to a local or remote node */
102 
103  PCMK_OCF_DEGRADED = 190, /* Active resource that is no longer 100% functional */
104  PCMK_OCF_DEGRADED_MASTER = 191, /* Promoted resource that is no longer 100% functional */
105 
106  PCMK_OCF_EXEC_ERROR = 192, /* Generic problem invoking the agent */
107  PCMK_OCF_UNKNOWN = 193, /* State of the service is unknown - used for recording in-flight operations */
113  PCMK_OCF_OTHER_ERROR = 199, /* Keep the same codes as PCMK_LSB */
114 };
115 
116 enum op_status {
127 };
128 
135 
138 };
139 
141  /* On timeout, only kill pid, do not kill entire pid group */
143 };
144 
146 typedef struct svc_action_s {
147  char *id;
148  char *rsc;
149  char *action;
150  guint interval_ms;
151 
152  char *standard;
153  char *provider;
154  char *agent;
155 
156  int timeout;
157  GHashTable *params; /* used by OCF agents and alert agents */
158 
159  int rc;
160  int pid;
161  int cancel;
162  int status;
163  int sequence;
167 
168  char *stderr_data;
169  char *stdout_data;
170 
177  void *cb_data;
178 
180 } svc_action_t;
181 
192  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
193 
200  GList *services_list(void);
201 
210  GList *resources_list_providers(const char *standard);
211 
221  GList *resources_list_agents(const char *standard, const char *provider);
222 
229  GList *resources_list_standards(void);
230 
231 svc_action_t *services_action_create(const char *name, const char *action,
232  guint interval_ms, int timeout /* ms */);
233 
252 svc_action_t *resources_action_create(const char *name, const char *standard,
253  const char *provider, const char *agent,
254  const char *action, guint interval_ms,
255  int timeout /* ms */, GHashTable *params,
256  enum svc_action_flags flags);
257 
261 gboolean services_action_kick(const char *name, const char *action,
262  guint interval_ms);
263 
264  const char *resources_find_service_class(const char *agent);
265 
279  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
280 
283  int services_action_user(svc_action_t *op, const char *user);
284 
285  gboolean services_action_sync(svc_action_t * op);
286 
296  gboolean services_action_async(svc_action_t * op, void (*action_callback) (svc_action_t *));
297 
298 gboolean services_action_cancel(const char *name, const char *action,
299  guint interval_ms);
300 
301 /* functions for alert agents */
302 svc_action_t *services_alert_create(const char *id, const char *exec,
303  int timeout, GHashTable *params,
304  int sequence, void *cb_data);
306  void (*cb)(svc_action_t *op));
307 
308  static inline const char *services_lrm_status_str(enum op_status status) {
309  switch (status) {
310  case PCMK_LRM_OP_PENDING:
311  return "pending";
312  case PCMK_LRM_OP_DONE:return "complete";
313  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
314  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
315  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
316  case PCMK_LRM_OP_ERROR:return "Error";
317  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
318  default:return "UNKNOWN!";
319  }
320  }
321 
322  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
323  switch (code) {
324  case PCMK_OCF_OK:
325  return "ok";
327  return "unknown error";
329  return "invalid parameter";
331  return "unimplemented feature";
333  return "insufficient privileges";
335  return "not installed";
337  return "not configured";
339  return "not running";
341  return "master";
343  return "master (failed)";
344  case PCMK_OCF_SIGNAL:
345  return "OCF_SIGNAL";
347  return "OCF_NOT_SUPPORTED";
348  case PCMK_OCF_PENDING:
349  return "OCF_PENDING";
350  case PCMK_OCF_CANCELLED:
351  return "OCF_CANCELLED";
352  case PCMK_OCF_TIMEOUT:
353  return "OCF_TIMEOUT";
355  return "OCF_OTHER_ERROR";
356  case PCMK_OCF_DEGRADED:
357  return "OCF_DEGRADED";
359  return "OCF_DEGRADED_MASTER";
360  default:
361  return "unknown";
362  }
363  }
364 
373  static inline enum ocf_exitcode
374  services_get_ocf_exitcode(const char *action, int lsb_exitcode)
375  {
376  /* For non-status actions, LSB and OCF share error code meaning <= 7 */
377  if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
378  if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) {
379  return PCMK_OCF_UNKNOWN_ERROR;
380  }
381  return (enum ocf_exitcode)lsb_exitcode;
382  }
383 
384  /* status has different return codes */
385  switch (lsb_exitcode) {
386  case PCMK_LSB_STATUS_OK:
387  return PCMK_OCF_OK;
389  return PCMK_OCF_NOT_INSTALLED;
395  return PCMK_OCF_NOT_RUNNING;
396  }
397  return PCMK_OCF_UNKNOWN_ERROR;
398  }
399 
400 # ifdef __cplusplus
401 }
402 # endif
403 
404 #endif /* __PCMK_SERVICES__ */
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
Definition: services.c:578
struct svc_action_s svc_action_t
void services_action_free(svc_action_t *op)
Definition: services.c:500
guint interval_ms
Definition: services.h:150
char * standard
Definition: services.h:152
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Definition: services.c:645
char * id
Definition: services.h:147
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
Definition: services.c:62
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:301
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:158
char * rsc
Definition: services.h:148
svc_action_flags
Definition: services.h:140
void services_action_cleanup(svc_action_t *op)
Definition: services.c:461
enum svc_action_flags flags
Definition: services.h:166
op_status
Definition: services.h:116
svc_action_private_t * opaque
Definition: services.h:179
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:339
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:944
char * stdout_data
Definition: services.h:169
GHashTable * params
Definition: services.h:157
char * agent
Definition: services.h:154
int synchronous
Definition: services.h:165
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:1025
int sequence
Definition: services.h:163
lsb_exitcode
Definition: services.h:58
nagios_exitcode
Definition: services.h:129
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:369
char * action
Definition: services.h:149
ocf_exitcode
Definition: services.h:87
GList * resources_list_standards(void)
Definition: services.c:985
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:979
lsb_status_exitcode
Definition: services.h:72
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:1035
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:416
void * cb_data
Definition: services.h:177
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:768
char * provider
Definition: services.h:153
int expected_rc
Definition: services.h:164
char * stderr_data
Definition: services.h:168