pacemaker  2.1.5-b7adf64e51
Scalable High-Availability cluster resource manager
services.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2022 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__CRM_SERVICES__H
11 # define PCMK__CRM_SERVICES__H
12 
13 
14 # include <glib.h>
15 # include <stdio.h>
16 # include <stdint.h>
17 # include <string.h>
18 # include <stdbool.h>
19 # include <sys/types.h>
20 
21 # include <crm_config.h> // OCF_ROOT_DIR
22 # include <crm/common/agents.h>
23 # include <crm/common/results.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
35 /* TODO: Autodetect these two ?*/
36 # ifndef SYSTEMCTL
37 # define SYSTEMCTL "/bin/systemctl"
38 # endif
39 
40 /* This is the string passed in the OCF_EXIT_REASON_PREFIX environment variable.
41  * The stderr output that occurs after this prefix is encountered is considered
42  * the exit reason for a completed operation.
43  */
44 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
45 
46 // Agent version to use if agent doesn't specify one
47 #define PCMK_DEFAULT_AGENT_VERSION "0.1"
48 
58 };
59 
60 // LSB uses different return codes for status actions
67 
68  /* custom codes should be in the 150-199 range reserved for application use */
71 };
72 
78 
79  /* This is a custom Pacemaker value (not a nagios convention), used as an
80  * intermediate value between the services library and the executor, so the
81  * executor can map it to the corresponding OCF code.
82  */
84 
85 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
88 #endif
89 };
90 
92  /* On timeout, only kill pid, do not kill entire pid group */
95 };
96 
98 
108 /*
109  * NOTE: Internally, services__create_resource_action() is preferable to
110  * resources_action_create().
111  */
112 typedef struct svc_action_s {
116  char *id;
117 
119  char *rsc;
120 
122  char *action;
123 
125  guint interval_ms;
126 
128  char *standard;
129 
131  char *provider;
132 
134  char *agent;
135 
136  int timeout;
137 
143  GHashTable *params;
144 
145  int rc;
146 
149  int pid; // Process ID of child
150  int cancel; // Whether this is a cancellation of a recurring action
152 
153  int status;
154 
158  int sequence;
159 
162  int expected_rc; // Unused
163  int synchronous; // Whether execution should be synchronous (blocking)
165 
167  char *stderr_data;
168  char *stdout_data;
169  void *cb_data;
170 
173 } svc_action_t;
174 
186 GList *get_directory_list(const char *root, gboolean files,
187  gboolean executable);
188 
199 GList *resources_list_providers(const char *standard);
200 
211 GList *resources_list_agents(const char *standard, const char *provider);
212 
220 GList *resources_list_standards(void);
221 
231 gboolean resources_agent_exists(const char *standard, const char *provider,
232  const char *agent);
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, GHashTable *params,
256  enum svc_action_flags flags);
257 
267 gboolean services_action_kick(const char *name, const char *action,
268  guint interval_ms);
269 
270 const char *resources_find_service_class(const char *agent);
271 
284  const char *args[]);
285 
288 int services_action_user(svc_action_t *op, const char *user);
289 gboolean services_action_sync(svc_action_t *op);
290 
325  void (*action_callback) (svc_action_t *),
326  void (*action_fork_callback) (svc_action_t *));
327 
358  void (*action_callback) (svc_action_t *));
359 
360 gboolean services_action_cancel(const char *name, const char *action,
361  guint interval_ms);
362 
363 /* functions for alert agents */
364 svc_action_t *services_alert_create(const char *id, const char *exec,
365  int timeout, GHashTable *params,
366  int sequence, void *cb_data);
368  void (*cb)(svc_action_t *op));
369 
370 enum ocf_exitcode services_result2ocf(const char *standard, const char *action,
371  int exit_status);
372 
373  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
374  switch (code) {
375  case PCMK_OCF_OK:
376  return "ok";
378  return "error";
380  return "invalid parameter";
382  return "unimplemented feature";
384  return "insufficient privileges";
386  return "not installed";
388  return "not configured";
390  return "not running";
392  return "promoted";
394  return "promoted (failed)";
395  case PCMK_OCF_DEGRADED:
396  return "OCF_DEGRADED";
398  return "promoted (degraded)";
399 
400 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
402  return "not supported (DEPRECATED STATUS)";
403  case PCMK_OCF_CANCELLED:
404  return "cancelled (DEPRECATED STATUS)";
406  return "other error (DEPRECATED STATUS)";
407  case PCMK_OCF_SIGNAL:
408  return "interrupted by signal (DEPRECATED STATUS)";
409  case PCMK_OCF_PENDING:
410  return "pending (DEPRECATED STATUS)";
411  case PCMK_OCF_TIMEOUT:
412  return "timeout (DEPRECATED STATUS)";
413 #endif
414  default:
415  return "unknown";
416  }
417  }
418 
419 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
420 #include <crm/services_compat.h>
421 #endif
422 
423 # ifdef __cplusplus
424 }
425 # endif
426 
427 #endif /* __PCMK_SERVICES__ */
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
Definition: services.c:664
int rc
Exit status of action (set by library upon completion)
Definition: services.h:145
API related to resource agents.
struct svc_action_s svc_action_t
Object for executing external actions.
ocf_exitcode
Exit status codes for resource agents.
Definition: results.h:163
Service failed and possibly in promoted role.
Definition: results.h:173
void services_action_free(svc_action_t *op)
Definition: services.c:585
guint interval_ms
Action interval for recurring resource actions, otherwise 0.
Definition: services.h:125
Service active and promoted.
Definition: results.h:172
char * standard
Resource standard for resource actions, otherwise NULL.
Definition: services.h:128
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Reschedule a recurring action for immediate execution.
Definition: services.c:732
const char * name
Definition: cib.c:24
char * id
Definition: services.h:116
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:171
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Request execution of an arbitrary command.
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, with callback after process is forked.
Definition: services.c:867
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:119
enum ocf_exitcode services_result2ocf(const char *standard, const char *action, int exit_status)
Definition: services.c:550
Service promoted but more likely to fail soon.
Definition: results.h:175
svc_action_flags
Definition: services.h:91
int timeout
Action timeout (in milliseconds)
Definition: services.h:136
const char * action
Definition: pcmk_fence.c:30
void services_action_cleanup(svc_action_t *op)
Definition: services.c:501
enum svc_action_flags flags
Flag group of enum svc_action_flags.
Definition: services.h:166
svc_action_private_t * opaque
This field should be treated as internal to Pacemaker.
Definition: services.h:172
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:1020
Parameter invalid (in local context)
Definition: results.h:166
char * stdout_data
Action stdout (set by library)
Definition: services.h:168
Parameter invalid (inherently)
Definition: results.h:170
GHashTable * params
Definition: services.h:143
Object for executing external actions.
Definition: services.h:112
Insufficient privileges.
Definition: results.h:168
char * agent
Resource agent name for resource actions, otherwise NULL.
Definition: services.h:134
int synchronous
Definition: services.h:163
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:1109
Deprecated services API.
Dependencies not available locally.
Definition: results.h:169
int sequence
Definition: services.h:158
Function and executable result codes.
lsb_exitcode
Definition: services.h:49
nagios_exitcode
Definition: services.h:73
Unspecified error.
Definition: results.h:165
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:445
Requested action not implemented.
Definition: results.h:167
Service active but more likely to fail soon.
Definition: results.h:174
char * action
Name of action being executed for resource actions, otherwise NULL.
Definition: services.h:122
GList * resources_list_standards(void)
Definition: services.c:1061
Success.
Definition: results.h:164
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:1055
int status
Execution status (enum pcmk_exec_status set by library)
Definition: services.h:153
lsb_status_exitcode
Definition: services.h:61
gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent)
Check whether a resource agent exists on the local host.
Definition: services.c:1175
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:1119
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:465
void * cb_data
For caller&#39;s use (not used by library)
Definition: services.h:169
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Request asynchronous execution of an action.
Definition: services.c:901
unsigned int timeout
Definition: pcmk_fence.c:32
char * provider
Resource provider for resource actions that require it, otherwise NULL.
Definition: services.h:131
uint64_t flags
Definition: remote.c:215
int expected_rc
Definition: services.h:162
char * stderr_data
Action stderr (set by library)
Definition: services.h:167