pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
services.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2020 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 <stdint.h>
26 # include <string.h>
27 # include <stdbool.h>
28 # include <sys/types.h>
29 
30 # include "common/results.h"
31 
32 # ifndef OCF_ROOT_DIR
33 # define OCF_ROOT_DIR "/usr/lib/ocf"
34 # endif
35 
36 # ifndef LSB_ROOT_DIR
37 # define LSB_ROOT_DIR "/etc/init.d"
38 # endif
39 
40 /* TODO: Autodetect these two ?*/
41 # ifndef SYSTEMCTL
42 # define SYSTEMCTL "/bin/systemctl"
43 # endif
44 
45 /* Known resource classes */
46 #define PCMK_RESOURCE_CLASS_OCF "ocf"
47 #define PCMK_RESOURCE_CLASS_SERVICE "service"
48 #define PCMK_RESOURCE_CLASS_LSB "lsb"
49 #define PCMK_RESOURCE_CLASS_SYSTEMD "systemd"
50 #define PCMK_RESOURCE_CLASS_UPSTART "upstart"
51 #define PCMK_RESOURCE_CLASS_NAGIOS "nagios"
52 #define PCMK_RESOURCE_CLASS_STONITH "stonith"
53 
54 /* This is the string passed in the OCF_EXIT_REASON_PREFIX environment variable.
55  * The stderr output that occurs after this prefix is encountered is considered
56  * the exit reason for a completed operation.
57  */
58 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
59 
60 // Agent version to use if agent doesn't specify one
61 #define PCMK_DEFAULT_AGENT_VERSION "0.1"
62 
72 };
73 
74 /* The return codes for the status operation are not the same for other
75  * operatios - go figure
76  */
83 
84  /* custom codes should be in the 150-199 range reserved for application use */
87 };
88 
89 enum op_status {
102 };
103 
110 
113 };
114 
116  /* On timeout, only kill pid, do not kill entire pid group */
119 };
120 
122 typedef struct svc_action_s {
123  char *id;
124  char *rsc;
125  char *action;
126  guint interval_ms;
127 
128  char *standard;
129  char *provider;
130  char *agent;
131 
132  int timeout;
133  GHashTable *params; /* used for setting up environment for ocf-ra &
134  alert agents
135  and to be sent via stdin for fence-agents
136  */
137 
138  int rc;
139  int pid;
140  int cancel;
141  int status;
142  int sequence;
146 
147  char *stderr_data;
148  char *stdout_data;
149 
156  void *cb_data;
157 
159 } svc_action_t;
160 
171  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
172 
179  GList *services_list(void);
180 
189  GList *resources_list_providers(const char *standard);
190 
200  GList *resources_list_agents(const char *standard, const char *provider);
201 
208  GList *resources_list_standards(void);
209 
219  gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent);
220 
221 svc_action_t *services_action_create(const char *name, const char *action,
222  guint interval_ms, int timeout /* ms */);
223 
242 svc_action_t *resources_action_create(const char *name, const char *standard,
243  const char *provider, const char *agent,
244  const char *action, guint interval_ms,
245  int timeout /* ms */, GHashTable *params,
246  enum svc_action_flags flags);
247 
251 gboolean services_action_kick(const char *name, const char *action,
252  guint interval_ms);
253 
254  const char *resources_find_service_class(const char *agent);
255 
269  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
270 
273  int services_action_user(svc_action_t *op, const char *user);
274 
275  gboolean services_action_sync(svc_action_t * op);
276 
288  void (*action_callback) (svc_action_t *),
289  void (*action_fork_callback) (svc_action_t *));
290 
291  gboolean services_action_async(svc_action_t * op,
292  void (*action_callback) (svc_action_t *));
293 
294 gboolean services_action_cancel(const char *name, const char *action,
295  guint interval_ms);
296 
297 /* functions for alert agents */
298 svc_action_t *services_alert_create(const char *id, const char *exec,
299  int timeout, GHashTable *params,
300  int sequence, void *cb_data);
302  void (*cb)(svc_action_t *op));
303 
304  static inline const char *services_lrm_status_str(enum op_status status) {
305  switch (status) {
306  case PCMK_LRM_OP_PENDING:
307  return "pending";
308  case PCMK_LRM_OP_DONE:return "complete";
309  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
310  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
311  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
312  case PCMK_LRM_OP_ERROR:return "Error";
313  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
314  case PCMK_LRM_OP_NOT_CONNECTED:return "No executor connection";
315  case PCMK_LRM_OP_INVALID:return "Cannot execute now";
316  default:return "UNKNOWN!";
317  }
318  }
319 
320  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
321  switch (code) {
322  case PCMK_OCF_OK:
323  return "ok";
325  return "error";
327  return "invalid parameter";
329  return "unimplemented feature";
331  return "insufficient privileges";
333  return "not installed";
335  return "not configured";
337  return "not running";
339  return "master";
341  return "master (failed)";
342  case PCMK_OCF_SIGNAL:
343  return "OCF_SIGNAL";
345  return "OCF_NOT_SUPPORTED";
346  case PCMK_OCF_PENDING:
347  return "OCF_PENDING";
348  case PCMK_OCF_CANCELLED:
349  return "OCF_CANCELLED";
350  case PCMK_OCF_TIMEOUT:
351  return "OCF_TIMEOUT";
353  return "OCF_OTHER_ERROR";
354  case PCMK_OCF_DEGRADED:
355  return "OCF_DEGRADED";
357  return "OCF_DEGRADED_MASTER";
358  default:
359  return "unknown";
360  }
361  }
362 
371  static inline enum ocf_exitcode
372  services_get_ocf_exitcode(const char *action, int lsb_exitcode)
373  {
374  /* For non-status actions, LSB and OCF share error code meaning <= 7 */
375  if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
377  return PCMK_OCF_UNKNOWN_ERROR;
378  }
379  return (enum ocf_exitcode)lsb_exitcode;
380  }
381 
382  /* status has different return codes */
383  switch (lsb_exitcode) {
384  case PCMK_LSB_STATUS_OK:
385  return PCMK_OCF_OK;
387  return PCMK_OCF_NOT_INSTALLED;
393  return PCMK_OCF_NOT_RUNNING;
394  }
395  return PCMK_OCF_UNKNOWN_ERROR;
396  }
397 
398 # ifdef __cplusplus
399 }
400 # endif
401 
402 #endif /* __PCMK_SERVICES__ */
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
Definition: services.c:550
struct svc_action_s svc_action_t
ocf_exitcode
Definition: results.h:150
void services_action_free(svc_action_t *op)
Definition: services.c:472
guint interval_ms
Definition: services.h:126
char * standard
Definition: services.h:128
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Definition: services.c:617
char * id
Definition: services.h:123
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:311
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:740
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:124
svc_action_flags
Definition: services.h:115
const char * action
Definition: pcmk_fence.c:30
void services_action_cleanup(svc_action_t *op)
Definition: services.c:433
enum svc_action_flags flags
Definition: services.h:145
op_status
Definition: services.h:89
svc_action_private_t * opaque
Definition: services.h:158
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:349
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:877
char * stdout_data
Definition: services.h:148
GHashTable * params
Definition: services.h:133
char * agent
Definition: services.h:130
int synchronous
Definition: services.h:144
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:958
int sequence
Definition: services.h:142
Function and executable result codes.
lsb_exitcode
Definition: services.h:63
nagios_exitcode
Definition: services.h:104
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:379
char * action
Definition: services.h:125
GList * resources_list_standards(void)
Definition: services.c:918
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:912
lsb_status_exitcode
Definition: services.h:77
gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent)
Definition: services.c:1024
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:968
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:397
void * cb_data
Definition: services.h:156
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:772
char * name
Definition: pcmk_fence.c:31
unsigned int timeout
Definition: pcmk_fence.c:32
char * provider
Definition: services.h:129
uint64_t flags
Definition: remote.c:149
int expected_rc
Definition: services.h:143
char * stderr_data
Definition: services.h:147