pacemaker 2.1.4-dc6eb4362e
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 "common/results.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
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#define PCMK_RESOURCE_CLASS_ALERT "alert"
47
48/* This is the string passed in the OCF_EXIT_REASON_PREFIX environment variable.
49 * The stderr output that occurs after this prefix is encountered is considered
50 * the exit reason for a completed operation.
51 */
52#define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
53
54// Agent version to use if agent doesn't specify one
55#define PCMK_DEFAULT_AGENT_VERSION "0.1"
56
66};
67
68/* The return codes for the status operation are not the same for other
69 * operatios - go figure
70 */
77
78 /* custom codes should be in the 150-199 range reserved for application use */
81};
82
88
89 /* This is a custom Pacemaker value (not a nagios convention), used as an
90 * intermediate value between the services library and the executor, so the
91 * executor can map it to the corresponding OCF code.
92 */
94
95#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
98#endif
99};
100
102 /* On timeout, only kill pid, do not kill entire pid group */
105};
106
108
121typedef struct svc_action_s {
125 char *id;
126
128 char *rsc;
129
131 char *action;
132
135
137 char *standard;
138
140 char *provider;
141
143 char *agent;
144
146
152 GHashTable *params;
153
154 int rc;
155
158 int pid; // Process ID of child
159 int cancel; // Whether this is a cancellation of a recurring action
161
162 int status;
163
168
171 int expected_rc; // Unused
172 int synchronous; // Whether execution should be synchronous (blocking)
174
178 void *cb_data;
179
183
194 GList *get_directory_list(const char *root, gboolean files, gboolean executable);
195
204 GList *resources_list_providers(const char *standard);
205
215 GList *resources_list_agents(const char *standard, const char *provider);
216
223 GList *resources_list_standards(void);
224
234 gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent);
235
254svc_action_t *resources_action_create(const char *name, const char *standard,
255 const char *provider, const char *agent,
256 const char *action, guint interval_ms,
257 int timeout /* ms */, GHashTable *params,
259
263gboolean services_action_kick(const char *name, const char *action,
264 guint interval_ms);
265
266 const char *resources_find_service_class(const char *agent);
267
281 svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
282
285 int services_action_user(svc_action_t *op, const char *user);
286
287 gboolean services_action_sync(svc_action_t * op);
288
324 void (*action_callback) (svc_action_t *),
325 void (*action_fork_callback) (svc_action_t *));
326
359 void (*action_callback) (svc_action_t *));
360
361gboolean services_action_cancel(const char *name, const char *action,
362 guint interval_ms);
363
364/* functions for alert agents */
365svc_action_t *services_alert_create(const char *id, const char *exec,
366 int timeout, GHashTable *params,
367 int sequence, void *cb_data);
369 void (*cb)(svc_action_t *op));
370
371enum ocf_exitcode services_result2ocf(const char *standard, const char *action,
372 int exit_status);
373
374 static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
375 switch (code) {
376 case PCMK_OCF_OK:
377 return "ok";
379 return "error";
381 return "invalid parameter";
383 return "unimplemented feature";
385 return "insufficient privileges";
387 return "not installed";
389 return "not configured";
391 return "not running";
393 return "promoted";
395 return "promoted (failed)";
397 return "OCF_DEGRADED";
399 return "promoted (degraded)";
400
401#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
403 return "not supported (DEPRECATED STATUS)";
405 return "cancelled (DEPRECATED STATUS)";
407 return "other error (DEPRECATED STATUS)";
408 case PCMK_OCF_SIGNAL:
409 return "interrupted by signal (DEPRECATED STATUS)";
410 case PCMK_OCF_PENDING:
411 return "pending (DEPRECATED STATUS)";
412 case PCMK_OCF_TIMEOUT:
413 return "timeout (DEPRECATED STATUS)";
414#endif
415 default:
416 return "unknown";
417 }
418 }
419
420#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
421#include <crm/services_compat.h>
422#endif
423
424# ifdef __cplusplus
425}
426# endif
427
428#endif /* __PCMK_SERVICES__ */
const char * name
Definition: cib.c:24
uint64_t flags
Definition: remote.c:3
unsigned int timeout
Definition: pcmk_fence.c:31
const char * action
Definition: pcmk_fence.c:29
Function and executable result codes.
ocf_exitcode
Exit status codes for resource agents.
Definition: results.h:161
@ PCMK_OCF_INSUFFICIENT_PRIV
Insufficient privileges.
Definition: results.h:166
@ PCMK_OCF_FAILED_PROMOTED
Service failed and possibly in promoted role.
Definition: results.h:171
@ PCMK_OCF_RUNNING_PROMOTED
Service active and promoted.
Definition: results.h:170
@ PCMK_OCF_DEGRADED_PROMOTED
Service promoted but more likely to fail soon.
Definition: results.h:173
@ PCMK_OCF_UNIMPLEMENT_FEATURE
Requested action not implemented.
Definition: results.h:165
@ PCMK_OCF_NOT_CONFIGURED
Parameter invalid (inherently)
Definition: results.h:168
@ PCMK_OCF_SIGNAL
Definition: results.h:193
@ PCMK_OCF_DEGRADED
Service active but more likely to fail soon.
Definition: results.h:172
@ PCMK_OCF_NOT_INSTALLED
Dependencies not available locally.
Definition: results.h:167
@ PCMK_OCF_UNKNOWN_ERROR
Unspecified error.
Definition: results.h:163
@ PCMK_OCF_PENDING
Definition: results.h:195
@ PCMK_OCF_CANCELLED
Definition: results.h:196
@ PCMK_OCF_INVALID_PARAM
Parameter invalid (in local context)
Definition: results.h:164
@ PCMK_OCF_NOT_RUNNING
Service safely stopped.
Definition: results.h:169
@ PCMK_OCF_OK
Success.
Definition: results.h:162
@ PCMK_OCF_TIMEOUT
Definition: results.h:197
@ PCMK_OCF_NOT_SUPPORTED
Definition: results.h:194
@ PCMK_OCF_OTHER_ERROR
Definition: results.h:198
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
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
Definition: services.c:72
gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent)
Definition: services.c:1175
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
Definition: services.c:732
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
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:1119
svc_action_flags
Definition: services.h:101
@ SVC_ACTION_NON_BLOCKED
Definition: services.h:104
@ SVC_ACTION_LEAVE_GROUP
Definition: services.h:103
lsb_status_exitcode
Definition: services.h:71
@ PCMK_LSB_STATUS_NOT_INSTALLED
Definition: services.h:79
@ PCMK_LSB_STATUS_OK
Definition: services.h:72
@ PCMK_LSB_STATUS_VAR_PID
Definition: services.h:73
@ PCMK_LSB_STATUS_INSUFFICIENT_PRIV
Definition: services.h:80
@ PCMK_LSB_STATUS_UNKNOWN
Definition: services.h:76
@ PCMK_LSB_STATUS_VAR_LOCK
Definition: services.h:74
@ PCMK_LSB_STATUS_NOT_RUNNING
Definition: services.h:75
nagios_exitcode
Definition: services.h:83
@ NAGIOS_INSUFFICIENT_PRIV
Definition: services.h:93
@ NAGIOS_STATE_UNKNOWN
Definition: services.h:87
@ NAGIOS_STATE_CRITICAL
Definition: services.h:86
@ NAGIOS_STATE_OK
Definition: services.h:84
@ NAGIOS_STATE_DEPENDENT
Definition: services.h:96
@ NAGIOS_STATE_WARNING
Definition: services.h:85
@ NAGIOS_NOT_INSTALLED
Definition: services.h:97
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Run an action asynchronously.
Definition: services.c:901
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
Definition: services.c:664
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:1020
GList * resources_list_standards(void)
Definition: services.c:1061
void services_action_free(svc_action_t *op)
Definition: services.c:585
lsb_exitcode
Definition: services.h:57
@ PCMK_LSB_OK
Definition: services.h:58
@ PCMK_LSB_NOT_RUNNING
Definition: services.h:65
@ PCMK_LSB_UNIMPLEMENT_FEATURE
Definition: services.h:61
@ PCMK_LSB_NOT_INSTALLED
Definition: services.h:63
@ PCMK_LSB_UNKNOWN_ERROR
Definition: services.h:59
@ PCMK_LSB_NOT_CONFIGURED
Definition: services.h:64
@ PCMK_LSB_INVALID_PARAM
Definition: services.h:60
@ PCMK_LSB_INSUFFICIENT_PRIV
Definition: services.h:62
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:465
struct svc_action_s svc_action_t
Object for executing external actions.
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
enum ocf_exitcode services_result2ocf(const char *standard, const char *action, int exit_status)
Definition: services.c:550
void services_action_cleanup(svc_action_t *op)
Definition: services.c:501
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:1109
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Definition: services.c:356
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
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
Deprecated services API.
Object for executing external actions.
Definition: services.h:121
char * id
Definition: services.h:125
void * cb_data
For caller's use (not used by library)
Definition: services.h:178
char * provider
Resource provider for resource actions that require it, otherwise NULL.
Definition: services.h:140
char * agent
Resource agent name for resource actions, otherwise NULL.
Definition: services.h:143
char * standard
Resource standard for resource actions, otherwise NULL.
Definition: services.h:137
int rc
Exit status of action (set by library upon completion)
Definition: services.h:154
char * rsc
XML ID of resource being executed for resource actions, otherwise NULL.
Definition: services.h:128
char * action
Name of action being executed for resource actions, otherwise NULL.
Definition: services.h:131
enum svc_action_flags flags
Flag group of enum svc_action_flags.
Definition: services.h:175
int expected_rc
Definition: services.h:171
char * stderr_data
Action stderr (set by library)
Definition: services.h:176
GHashTable * params
Definition: services.h:152
int synchronous
Definition: services.h:172
int timeout
Action timeout (in milliseconds)
Definition: services.h:145
char * stdout_data
Action stdout (set by library)
Definition: services.h:177
guint interval_ms
Action interval for recurring resource actions, otherwise 0.
Definition: services.h:134
int sequence
Definition: services.h:167
int status
Execution status (enum pcmk_exec_status set by library)
Definition: services.h:162
svc_action_private_t * opaque
This field should be treated as internal to Pacemaker.
Definition: services.h:181