pacemaker  2.1.2-ada5c3b36
Scalable High-Availability cluster resource manager
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 /* TODO: Autodetect these two ?*/
34 # ifndef SYSTEMCTL
35 # define SYSTEMCTL "/bin/systemctl"
36 # endif
37 
38 /* Known resource classes */
39 #define PCMK_RESOURCE_CLASS_OCF "ocf"
40 #define PCMK_RESOURCE_CLASS_SERVICE "service"
41 #define PCMK_RESOURCE_CLASS_LSB "lsb"
42 #define PCMK_RESOURCE_CLASS_SYSTEMD "systemd"
43 #define PCMK_RESOURCE_CLASS_UPSTART "upstart"
44 #define PCMK_RESOURCE_CLASS_NAGIOS "nagios"
45 #define PCMK_RESOURCE_CLASS_STONITH "stonith"
46 
47 /* This is the string passed in the OCF_EXIT_REASON_PREFIX environment variable.
48  * The stderr output that occurs after this prefix is encountered is considered
49  * the exit reason for a completed operation.
50  */
51 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
52 
53 // Agent version to use if agent doesn't specify one
54 #define PCMK_DEFAULT_AGENT_VERSION "0.1"
55 
65 };
66 
67 /* The return codes for the status operation are not the same for other
68  * operatios - go figure
69  */
76 
77  /* custom codes should be in the 150-199 range reserved for application use */
80 };
81 
87 
88  /* This is a custom Pacemaker value (not a nagios convention), used as an
89  * intermediate value between the services library and the executor, so the
90  * executor can map it to the corresponding OCF code.
91  */
93 
94 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
97 #endif
98 };
99 
101  /* On timeout, only kill pid, do not kill entire pid group */
104 };
105 
107 
120 typedef struct svc_action_s {
124  char *id;
125 
127  char *rsc;
128 
130  char *action;
131 
133  guint interval_ms;
134 
136  char *standard;
137 
139  char *provider;
140 
142  char *agent;
143 
144  int timeout;
145 
151  GHashTable *params;
152 
153  int rc;
154 
157  int pid; // Process ID of child
158  int cancel; // Whether this is a cancellation of a recurring action
160 
161  int status;
162 
166  int sequence;
167 
170  int expected_rc; // Unused
171  int synchronous; // Whether execution should be synchronous (blocking)
173 
175  char *stderr_data;
176  char *stdout_data;
177  void *cb_data;
178 
181 } svc_action_t;
182 
193  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
194 
203  GList *resources_list_providers(const char *standard);
204 
214  GList *resources_list_agents(const char *standard, const char *provider);
215 
222  GList *resources_list_standards(void);
223 
233  gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent);
234 
253 svc_action_t *resources_action_create(const char *name, const char *standard,
254  const char *provider, const char *agent,
255  const char *action, guint interval_ms,
256  int timeout /* ms */, GHashTable *params,
257  enum svc_action_flags flags);
258 
262 gboolean services_action_kick(const char *name, const char *action,
263  guint interval_ms);
264 
265  const char *resources_find_service_class(const char *agent);
266 
280  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
281 
284  int services_action_user(svc_action_t *op, const char *user);
285 
286  gboolean services_action_sync(svc_action_t * op);
287 
299  void (*action_callback) (svc_action_t *),
300  void (*action_fork_callback) (svc_action_t *));
301 
302  gboolean services_action_async(svc_action_t * op,
303  void (*action_callback) (svc_action_t *));
304 
305 gboolean services_action_cancel(const char *name, const char *action,
306  guint interval_ms);
307 
308 /* functions for alert agents */
309 svc_action_t *services_alert_create(const char *id, const char *exec,
310  int timeout, GHashTable *params,
311  int sequence, void *cb_data);
313  void (*cb)(svc_action_t *op));
314 
315 enum ocf_exitcode services_result2ocf(const char *standard, const char *action,
316  int exit_status);
317 
318  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
319  switch (code) {
320  case PCMK_OCF_OK:
321  return "ok";
323  return "error";
325  return "invalid parameter";
327  return "unimplemented feature";
329  return "insufficient privileges";
331  return "not installed";
333  return "not configured";
335  return "not running";
337  return "promoted";
339  return "promoted (failed)";
340  case PCMK_OCF_DEGRADED:
341  return "OCF_DEGRADED";
343  return "promoted (degraded)";
344 
345 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
347  return "not supported (DEPRECATED STATUS)";
348  case PCMK_OCF_CANCELLED:
349  return "cancelled (DEPRECATED STATUS)";
351  return "other error (DEPRECATED STATUS)";
352  case PCMK_OCF_SIGNAL:
353  return "interrupted by signal (DEPRECATED STATUS)";
354  case PCMK_OCF_PENDING:
355  return "pending (DEPRECATED STATUS)";
356  case PCMK_OCF_TIMEOUT:
357  return "timeout (DEPRECATED STATUS)";
358 #endif
359  default:
360  return "unknown";
361  }
362  }
363 
364 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
365 #include <crm/services_compat.h>
366 #endif
367 
368 # ifdef __cplusplus
369 }
370 # endif
371 
372 #endif /* __PCMK_SERVICES__ */
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
Definition: services.c:659
int rc
Exit status of action (set by library upon completion)
Definition: services.h:153
struct svc_action_s svc_action_t
Object for executing external actions.
ocf_exitcode
Exit status codes for resource agents.
Definition: results.h:161
Service failed and possibly in promoted role.
Definition: results.h:171
void services_action_free(svc_action_t *op)
Definition: services.c:580
guint interval_ms
Action interval for recurring resource actions, otherwise 0.
Definition: services.h:133
Service active and promoted.
Definition: results.h:170
char * standard
Resource standard for resource actions, otherwise NULL.
Definition: services.h:136
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Definition: services.c:727
char * id
Definition: services.h:124
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
Definition: services.c:72
Service safely stopped.
Definition: results.h:169
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Definition: services.c:356
gboolean services_action_async_fork_notify(svc_action_t *op, void(*action_callback)(svc_action_t *), void(*action_fork_callback)(svc_action_t *))
Run an action asynchronously.
Definition: services.c:862
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
XML ID of resource being executed for resource actions, otherwise NULL.
Definition: services.h:127
enum ocf_exitcode services_result2ocf(const char *standard, const char *action, int exit_status)
Definition: services.c:545
Service promoted but more likely to fail soon.
Definition: results.h:173
svc_action_flags
Definition: services.h:100
int timeout
Action timeout (in milliseconds)
Definition: services.h:144
const char * action
Definition: pcmk_fence.c:30
void services_action_cleanup(svc_action_t *op)
Definition: services.c:496
enum svc_action_flags flags
Flag group of enum svc_action_flags.
Definition: services.h:174
svc_action_private_t * opaque
This field should be treated as internal to Pacemaker.
Definition: services.h:180
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:413
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:1013
Parameter invalid (in local context)
Definition: results.h:164
char * stdout_data
Action stdout (set by library)
Definition: services.h:176
Parameter invalid (inherently)
Definition: results.h:168
GHashTable * params
Definition: services.h:151
Object for executing external actions.
Definition: services.h:120
Insufficient privileges.
Definition: results.h:166
char * agent
Resource agent name for resource actions, otherwise NULL.
Definition: services.h:142
int synchronous
Definition: services.h:171
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:1102
Deprecated services API.
Dependencies not available locally.
Definition: results.h:167
int sequence
Definition: services.h:166
Function and executable result codes.
lsb_exitcode
Definition: services.h:56
nagios_exitcode
Definition: services.h:82
Unspecified error.
Definition: results.h:163
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:442
Requested action not implemented.
Definition: results.h:165
Service active but more likely to fail soon.
Definition: results.h:172
char * action
Name of action being executed for resource actions, otherwise NULL.
Definition: services.h:130
GList * resources_list_standards(void)
Definition: services.c:1054
Success.
Definition: results.h:162
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:1048
int status
Execution status (enum pcmk_exec_status set by library)
Definition: services.h:161
lsb_status_exitcode
Definition: services.h:70
gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent)
Definition: services.c:1168
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:1112
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:460
void * cb_data
For caller&#39;s use (not used by library)
Definition: services.h:177
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Definition: services.c:894
char * name
Definition: pcmk_fence.c:31
unsigned int timeout
Definition: pcmk_fence.c:32
char * provider
Resource provider for resource actions that require it, otherwise NULL.
Definition: services.h:139
uint64_t flags
Definition: remote.c:149
int expected_rc
Definition: services.h:170
char * stderr_data
Action stderr (set by library)
Definition: services.h:175