pacemaker  2.1.0-7c3f660
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-2021 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 <crm_config.h> // OCF_ROOT_DIR
31 # include "common/results.h"
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 enum op_status {
99 };
100 
107 
110 };
111 
113  /* On timeout, only kill pid, do not kill entire pid group */
116 };
117 
119 typedef struct svc_action_s {
120  char *id;
121  char *rsc;
122  char *action;
123  guint interval_ms;
124 
125  char *standard;
126  char *provider;
127  char *agent;
128 
129  int timeout;
130  GHashTable *params; /* used for setting up environment for ocf-ra &
131  alert agents
132  and to be sent via stdin for fence-agents
133  */
134 
135  int rc;
136  int pid;
137  int cancel;
138  int status;
139  int sequence;
143 
144  char *stderr_data;
145  char *stdout_data;
146 
153  void *cb_data;
154 
156 } svc_action_t;
157 
168  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
169 
176  GList *services_list(void);
177 
186  GList *resources_list_providers(const char *standard);
187 
197  GList *resources_list_agents(const char *standard, const char *provider);
198 
205  GList *resources_list_standards(void);
206 
216  gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent);
217 
218 svc_action_t *services_action_create(const char *name, const char *action,
219  guint interval_ms, int timeout /* ms */);
220 
239 svc_action_t *resources_action_create(const char *name, const char *standard,
240  const char *provider, const char *agent,
241  const char *action, guint interval_ms,
242  int timeout /* ms */, GHashTable *params,
243  enum svc_action_flags flags);
244 
248 gboolean services_action_kick(const char *name, const char *action,
249  guint interval_ms);
250 
251  const char *resources_find_service_class(const char *agent);
252 
266  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
267 
270  int services_action_user(svc_action_t *op, const char *user);
271 
272  gboolean services_action_sync(svc_action_t * op);
273 
285  void (*action_callback) (svc_action_t *),
286  void (*action_fork_callback) (svc_action_t *));
287 
288  gboolean services_action_async(svc_action_t * op,
289  void (*action_callback) (svc_action_t *));
290 
291 gboolean services_action_cancel(const char *name, const char *action,
292  guint interval_ms);
293 
294 /* functions for alert agents */
295 svc_action_t *services_alert_create(const char *id, const char *exec,
296  int timeout, GHashTable *params,
297  int sequence, void *cb_data);
299  void (*cb)(svc_action_t *op));
300 
301  static inline const char *services_lrm_status_str(enum op_status status) {
302  switch (status) {
303  case PCMK_LRM_OP_PENDING:
304  return "pending";
305  case PCMK_LRM_OP_DONE:return "complete";
306  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
307  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
308  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
309  case PCMK_LRM_OP_ERROR:return "Error";
310  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
311  case PCMK_LRM_OP_NOT_CONNECTED:return "No executor connection";
312  case PCMK_LRM_OP_INVALID:return "Cannot execute now";
313  default:return "UNKNOWN!";
314  }
315  }
316 
317  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
318  switch (code) {
319  case PCMK_OCF_OK:
320  return "ok";
322  return "error";
324  return "invalid parameter";
326  return "unimplemented feature";
328  return "insufficient privileges";
330  return "not installed";
332  return "not configured";
334  return "not running";
336  return "promoted";
338  return "promoted (failed)";
339  case PCMK_OCF_SIGNAL:
340  return "OCF_SIGNAL";
342  return "OCF_NOT_SUPPORTED";
343  case PCMK_OCF_PENDING:
344  return "OCF_PENDING";
345  case PCMK_OCF_CANCELLED:
346  return "OCF_CANCELLED";
347  case PCMK_OCF_TIMEOUT:
348  return "OCF_TIMEOUT";
350  return "OCF_OTHER_ERROR";
351  case PCMK_OCF_DEGRADED:
352  return "OCF_DEGRADED";
354  return "promoted (degraded)";
355  default:
356  return "unknown";
357  }
358  }
359 
368  static inline enum ocf_exitcode
369  services_get_ocf_exitcode(const char *action, int lsb_exitcode)
370  {
371  /* For non-status actions, LSB and OCF share error code meaning <= 7 */
372  if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
373  if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) {
374  return PCMK_OCF_UNKNOWN_ERROR;
375  }
376  return (enum ocf_exitcode)lsb_exitcode;
377  }
378 
379  /* status has different return codes */
380  switch (lsb_exitcode) {
381  case PCMK_LSB_STATUS_OK:
382  return PCMK_OCF_OK;
384  return PCMK_OCF_NOT_INSTALLED;
390  return PCMK_OCF_NOT_RUNNING;
391  }
392  return PCMK_OCF_UNKNOWN_ERROR;
393  }
394 
395 # ifdef __cplusplus
396 }
397 # endif
398 
399 #endif /* __PCMK_SERVICES__ */
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
Definition: services.c:591
struct svc_action_s svc_action_t
ocf_exitcode
Definition: results.h:150
void services_action_free(svc_action_t *op)
Definition: services.c:513
guint interval_ms
Definition: services.h:123
char * standard
Definition: services.h:125
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Definition: services.c:658
char * id
Definition: services.h:120
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
Definition: services.c:71
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:352
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:781
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:335
char * rsc
Definition: services.h:121
svc_action_flags
Definition: services.h:112
const char * action
Definition: pcmk_fence.c:30
void services_action_cleanup(svc_action_t *op)
Definition: services.c:474
enum svc_action_flags flags
Definition: services.h:142
op_status
Definition: services.h:86
svc_action_private_t * opaque
Definition: services.h:155
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:390
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:918
char * stdout_data
Definition: services.h:145
GHashTable * params
Definition: services.h:130
char * agent
Definition: services.h:127
int synchronous
Definition: services.h:141
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:999
int sequence
Definition: services.h:139
Function and executable result codes.
lsb_exitcode
Definition: services.h:60
nagios_exitcode
Definition: services.h:101
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:420
char * action
Definition: services.h:122
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:438
void * cb_data
Definition: services.h:153
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:813
char * name
Definition: pcmk_fence.c:31
unsigned int timeout
Definition: pcmk_fence.c:32
char * provider
Definition: services.h:126
uint64_t flags
Definition: remote.c:149
int expected_rc
Definition: services.h:140
char * stderr_data
Definition: services.h:144