pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
services.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2024 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 
29 // NOTE: booth (as of at least 1.1) checks for the existence of this header
30 
37 /* TODO: Autodetect these two ?*/
38 # ifndef SYSTEMCTL
39 # define SYSTEMCTL "/bin/systemctl"
40 # endif
41 
42 /* This is the string passed in the OCF_EXIT_REASON_PREFIX environment variable.
43  * The stderr output that occurs after this prefix is encountered is considered
44  * the exit reason for a completed operation.
45  */
46 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
47 
48 // Agent version to use if agent doesn't specify one
49 #define PCMK_DEFAULT_AGENT_VERSION "0.1"
50 
53 
54  // NOTE: booth (as of at least 1.1) uses this value
56 
63 };
64 
65 // LSB uses different return codes for status actions
72 
73  /* custom codes should be in the 150-199 range reserved for application use */
76 };
77 
80 
86 
87  /* This is a custom Pacemaker value (not a nagios convention), used as an
88  * intermediate value between the services library and the executor, so the
89  * executor can map it to the corresponding OCF code.
90  */
92 
93 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
96 #endif
97 };
98 
100 
102  /* On timeout, only kill pid, do not kill entire pid group */
105 };
106 
108 
118 /*
119  * NOTE: Internally, services__create_resource_action() is preferable to
120  * resources_action_create().
121  */
122 typedef struct svc_action_s {
126  char *id;
127 
129  char *rsc;
130 
132  char *action;
133 
135  guint interval_ms;
136 
138  char *standard;
139 
141  char *provider;
142 
144  char *agent;
145 
146  int timeout;
147 
153  GHashTable *params;
154 
155  int rc;
156 
159  int pid; // Process ID of child
160  int cancel; // Whether this is a cancellation of a recurring action
162 
163  int status;
164 
168  int sequence;
169 
172  int expected_rc; // Unused
173  int synchronous; // Whether execution should be synchronous (blocking)
175 
177  char *stderr_data;
178  char *stdout_data;
179  void *cb_data;
180 
183 } svc_action_t;
184 
196 GList *get_directory_list(const char *root, gboolean files,
197  gboolean executable);
198 
209 GList *resources_list_providers(const char *standard);
210 
221 GList *resources_list_agents(const char *standard, const char *provider);
222 
230 GList *resources_list_standards(void);
231 
241 gboolean resources_agent_exists(const char *standard, const char *provider,
242  const char *agent);
243 
262 svc_action_t *resources_action_create(const char *name, const char *standard,
263  const char *provider, const char *agent,
264  const char *action, guint interval_ms,
265  int timeout, GHashTable *params,
266  enum svc_action_flags flags);
267 
277 gboolean services_action_kick(const char *name, const char *action,
278  guint interval_ms);
279 
280 const char *resources_find_service_class(const char *agent);
281 
294  const char *args[]);
295 
298 int services_action_user(svc_action_t *op, const char *user);
299 gboolean services_action_sync(svc_action_t *op);
300 
335  void (*action_callback) (svc_action_t *),
336  void (*action_fork_callback) (svc_action_t *));
337 
368  void (*action_callback) (svc_action_t *));
369 
370 gboolean services_action_cancel(const char *name, const char *action,
371  guint interval_ms);
372 
373 /* functions for alert agents */
374 svc_action_t *services_alert_create(const char *id, const char *exec,
375  int timeout, GHashTable *params,
376  int sequence, void *cb_data);
378  void (*cb)(svc_action_t *op));
379 
380 enum ocf_exitcode services_result2ocf(const char *standard, const char *action,
381  int exit_status);
382 
383  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
384  switch (code) {
385  case PCMK_OCF_OK:
386  return "ok";
388  return "error";
390  return "invalid parameter";
392  return "unimplemented feature";
394  return "insufficient privileges";
396  return "not installed";
398  return "not configured";
400  return "not running";
402  return "promoted";
404  return "promoted (failed)";
405  case PCMK_OCF_DEGRADED:
406  return "OCF_DEGRADED";
408  return "promoted (degraded)";
409 
410 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
412  return "not supported (DEPRECATED STATUS)";
413  case PCMK_OCF_CANCELLED:
414  return "cancelled (DEPRECATED STATUS)";
416  return "other error (DEPRECATED STATUS)";
417  case PCMK_OCF_SIGNAL:
418  return "interrupted by signal (DEPRECATED STATUS)";
419  case PCMK_OCF_PENDING:
420  return "pending (DEPRECATED STATUS)";
421  case PCMK_OCF_TIMEOUT:
422  return "timeout (DEPRECATED STATUS)";
423 #endif
424  default:
425  return "unknown";
426  }
427  }
428 
429 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
430 #include <crm/services_compat.h>
431 #endif
432 
433 # ifdef __cplusplus
434 }
435 # endif
436 
437 #endif /* __PCMK_SERVICES__ */
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
Definition: services.c:662
int rc
Exit status of action (set by library upon completion)
Definition: services.h:155
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:177
Service failed and possibly in promoted role.
Definition: results.h:193
void services_action_free(svc_action_t *op)
Definition: services.c:583
guint interval_ms
Action interval for recurring resource actions, otherwise 0.
Definition: services.h:135
Service active and promoted.
Definition: results.h:192
char * standard
Resource standard for resource actions, otherwise NULL.
Definition: services.h:138
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Reschedule a recurring action for immediate execution.
Definition: services.c:730
const char * name
Definition: cib.c:26
char * id
Definition: services.h:126
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:190
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:865
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:129
enum ocf_exitcode services_result2ocf(const char *standard, const char *action, int exit_status)
Definition: services.c:548
Service promoted but more likely to fail soon.
Definition: results.h:195
svc_action_flags
Definition: services.h:101
int timeout
Action timeout (in milliseconds)
Definition: services.h:146
const char * action
Definition: pcmk_fence.c:30
void services_action_cleanup(svc_action_t *op)
Definition: services.c:499
enum svc_action_flags flags
Flag group of enum svc_action_flags.
Definition: services.h:176
svc_action_private_t * opaque
This field should be treated as internal to Pacemaker.
Definition: services.h:182
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:1018
Parameter invalid (in local context)
Definition: results.h:183
char * stdout_data
Action stdout (set by library)
Definition: services.h:178
Parameter invalid (inherently)
Definition: results.h:187
GHashTable * params
Definition: services.h:153
Object for executing external actions.
Definition: services.h:122
Insufficient privileges.
Definition: results.h:185
char * agent
Resource agent name for resource actions, otherwise NULL.
Definition: services.h:144
int synchronous
Definition: services.h:173
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:1107
Deprecated services API.
Dependencies not available locally.
Definition: results.h:186
int sequence
Definition: services.h:168
Function and executable result codes.
lsb_exitcode
Definition: services.h:51
nagios_exitcode
Definition: services.h:81
Unspecified error.
Definition: results.h:181
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:443
Requested action not implemented.
Definition: results.h:184
Service active but more likely to fail soon.
Definition: results.h:194
char * action
Name of action being executed for resource actions, otherwise NULL.
Definition: services.h:132
GList * resources_list_standards(void)
Definition: services.c:1059
Success.
Definition: results.h:178
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:1053
int status
Execution status (enum pcmk_exec_status set by library)
Definition: services.h:163
lsb_status_exitcode
Definition: services.h:66
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:1173
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:1117
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:463
void * cb_data
For caller&#39;s use (not used by library)
Definition: services.h:179
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Request asynchronous execution of an action.
Definition: services.c:899
unsigned int timeout
Definition: pcmk_fence.c:32
char * provider
Resource provider for resource actions that require it, otherwise NULL.
Definition: services.h:141
uint64_t flags
Definition: remote.c:215
int expected_rc
Definition: services.h:172
char * stderr_data
Action stderr (set by library)
Definition: services.h:177