pacemaker  1.1.24-3850484742
Scalable High-Availability cluster resource manager
services.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
25 #ifndef __PCMK_SERVICES__
26 # define __PCMK_SERVICES__
27 
28 # ifdef __cplusplus
29 extern "C" {
30 # endif
31 
32 # include <glib.h>
33 # include <stdio.h>
34 # include <string.h>
35 # include <stdbool.h>
36 # include <sys/types.h>
37 
38 # ifndef OCF_ROOT_DIR
39 # define OCF_ROOT_DIR "/usr/lib/ocf"
40 # endif
41 
42 # ifndef LSB_ROOT_DIR
43 # define LSB_ROOT_DIR "/etc/init.d"
44 # endif
45 
46 /* TODO: Autodetect these two ?*/
47 # ifndef SYSTEMCTL
48 # define SYSTEMCTL "/bin/systemctl"
49 # endif
50 
51 /* Deprecated and unused by Pacemaker, kept for API backward compatibility */
52 # ifndef SERVICE_SCRIPT
53 # define SERVICE_SCRIPT "/sbin/service"
54 # endif
55 
56 /* Known resource classes */
57 #define PCMK_RESOURCE_CLASS_OCF "ocf"
58 #define PCMK_RESOURCE_CLASS_SERVICE "service"
59 #define PCMK_RESOURCE_CLASS_LSB "lsb"
60 #define PCMK_RESOURCE_CLASS_SYSTEMD "systemd"
61 #define PCMK_RESOURCE_CLASS_UPSTART "upstart"
62 #define PCMK_RESOURCE_CLASS_HB "heartbeat"
63 #define PCMK_RESOURCE_CLASS_NAGIOS "nagios"
64 #define PCMK_RESOURCE_CLASS_STONITH "stonith"
65 
66 /* This is the string passed in the OCF_EXIT_REASON_PREFIX
67  * environment variable. The stderr output that occurs
68  * after this prefix is encountered is considered the exit
69  * reason for a completed operationt */
70 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
71 
72 // Agent version to use if agent doesn't specify one
73 #define PCMK_DEFAULT_AGENT_VERSION "0.1"
74 
84 };
85 
86 /* The return codes for the status operation are not the same for other
87  * operatios - go figure
88  */
95 
96  /* custom codes should be in the 150-199 range reserved for application use */
99 };
100 
101 /* Uniform exit codes
102  * Everything is mapped to its OCF equivalent so that Pacemaker only deals with one set of codes
103  */
112  PCMK_OCF_NOT_RUNNING = 7, /* End of overlap with LSB */
115 
116 
117  /* 150-199 reserved for application use */
118  PCMK_OCF_CONNECTION_DIED = 189, /* Operation failure implied by disconnection of the LRM API to a local or remote node */
119 
120  PCMK_OCF_DEGRADED = 190, /* Active resource that is no longer 100% functional */
121  PCMK_OCF_DEGRADED_MASTER = 191, /* Promoted resource that is no longer 100% functional */
122 
123  PCMK_OCF_EXEC_ERROR = 192, /* Generic problem invoking the agent */
124  PCMK_OCF_UNKNOWN = 193, /* State of the service is unknown - used for recording in-flight operations */
130  PCMK_OCF_OTHER_ERROR = 199, /* Keep the same codes as PCMK_LSB */
131 };
132 
133 enum op_status {
143 };
144 
151 
154 };
155 
157  /* On timeout, only kill pid, do not kill entire pid group */
160 };
161 
163 typedef struct svc_action_s {
164  char *id;
165  char *rsc;
166  char *action;
167  int interval;
168 
169  char *standard;
170  char *provider;
171  char *agent;
172 
173  int timeout;
174  GHashTable *params; /* used for setting up environment for ocf-ra &
175  alert agents
176  and to be sent via stdin for fence-agents
177  */
178 
179  int rc;
180  int pid;
181  int cancel;
182  int status;
183  int sequence;
187 
188  char *stderr_data;
189  char *stdout_data;
190 
197  void *cb_data;
198 
200 } svc_action_t;
201 
212  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
213 
220  GList *services_list(void);
221 
230  GList *resources_list_providers(const char *standard);
231 
241  GList *resources_list_agents(const char *standard, const char *provider);
242 
249  GList *resources_list_standards(void);
250 
251  svc_action_t *services_action_create(const char *name, const char *action,
252  int interval /* ms */ , int timeout /* ms */ );
253 
272  svc_action_t *resources_action_create(const char *name, const char *standard,
273  const char *provider, const char *agent,
274  const char *action, int interval /* ms */ ,
275  int timeout /* ms */ , GHashTable * params,
276  enum svc_action_flags flags);
277 
281  gboolean services_action_kick(const char *name, const char *action, int interval /* ms */);
282 
283  const char *resources_find_service_class(const char *agent);
284 
298  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
299 
302  int services_action_user(svc_action_t *op, const char *user);
303 
304  gboolean services_action_sync(svc_action_t * op);
305 
317  void (*action_callback) (svc_action_t *),
318  void (*action_fork_callback) (svc_action_t *));
319 
320  gboolean services_action_async(svc_action_t * op,
321  void (*action_callback) (svc_action_t *));
322 
323  gboolean services_action_cancel(const char *name, const char *action, int interval);
324 
325 /* functions for alert agents */
326 svc_action_t *services_alert_create(const char *id, const char *exec,
327  int timeout, GHashTable *params,
328  int sequence, void *cb_data);
330  void (*cb)(svc_action_t *op));
331 
332  static inline const char *services_lrm_status_str(enum op_status status) {
333  switch (status) {
334  case PCMK_LRM_OP_PENDING:
335  return "pending";
336  case PCMK_LRM_OP_DONE:return "complete";
337  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
338  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
339  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
340  case PCMK_LRM_OP_ERROR:return "Error";
341  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
342  default:return "UNKNOWN!";
343  }
344  }
345 
346  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
347  switch (code) {
348  case PCMK_OCF_OK:
349  return "ok";
351  return "unknown error";
353  return "invalid parameter";
355  return "unimplemented feature";
357  return "insufficient privileges";
359  return "not installed";
361  return "not configured";
363  return "not running";
365  return "master";
367  return "master (failed)";
368  case PCMK_OCF_SIGNAL:
369  return "OCF_SIGNAL";
371  return "OCF_NOT_SUPPORTED";
372  case PCMK_OCF_PENDING:
373  return "OCF_PENDING";
374  case PCMK_OCF_CANCELLED:
375  return "OCF_CANCELLED";
376  case PCMK_OCF_TIMEOUT:
377  return "OCF_TIMEOUT";
379  return "OCF_OTHER_ERROR";
380  case PCMK_OCF_DEGRADED:
381  return "OCF_DEGRADED";
383  return "OCF_DEGRADED_MASTER";
384  default:
385  return "unknown";
386  }
387  }
388 
397  static inline enum ocf_exitcode
398  services_get_ocf_exitcode(const char *action, int lsb_exitcode)
399  {
400  /* For non-status actions, LSB and OCF share error code meaning <= 7 */
401  if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
402  if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) {
403  return PCMK_OCF_UNKNOWN_ERROR;
404  }
405  return (enum ocf_exitcode)lsb_exitcode;
406  }
407 
408  /* status has different return codes */
409  switch (lsb_exitcode) {
410  case PCMK_LSB_STATUS_OK:
411  return PCMK_OCF_OK;
413  return PCMK_OCF_NOT_INSTALLED;
419  return PCMK_OCF_NOT_RUNNING;
420  }
421  return PCMK_OCF_UNKNOWN_ERROR;
422  }
423 
424 # ifdef __cplusplus
425 }
426 # endif
427 
428 #endif /* __PCMK_SERVICES__ */
struct svc_action_s svc_action_t
void services_action_free(svc_action_t *op)
Definition: services.c:540
char * standard
Definition: services.h:169
svc_action_t * services_action_create(const char *name, const char *action, int interval, int timeout)
Definition: services.c:52
char * id
Definition: services.h:164
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
Definition: services.c:89
svc_action_t * resources_action_create(const char *name, const char *standard, const char *provider, const char *agent, const char *action, int interval, int timeout, GHashTable *params, enum svc_action_flags flags)
Create a new resource action.
Definition: services.c:175
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Definition: services.c:379
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:808
char * rsc
Definition: services.h:165
int interval
Definition: services.h:167
svc_action_flags
Definition: services.h:156
void services_action_cleanup(svc_action_t *op)
Definition: services.c:501
enum svc_action_flags flags
Definition: services.h:186
op_status
Definition: services.h:133
svc_action_private_t * opaque
Definition: services.h:199
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:417
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:1309
char * stdout_data
Definition: services.h:189
GHashTable * params
Definition: services.h:174
gboolean services_action_cancel(const char *name, const char *action, int interval)
Cancel a recurring action.
Definition: services.c:618
char * agent
Definition: services.h:171
int synchronous
Definition: services.h:185
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:1408
int sequence
Definition: services.h:183
lsb_exitcode
Definition: services.h:75
nagios_exitcode
Definition: services.h:145
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:447
gboolean services_action_kick(const char *name, const char *action, int interval)
Definition: services.c:685
char * action
Definition: services.h:166
ocf_exitcode
Definition: services.h:104
GList * resources_list_standards(void)
Definition: services.c:1364
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:1344
lsb_status_exitcode
Definition: services.h:89
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:1418
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
Definition: services.h:197
GList * services_list(void)
Definition: services.c:1350
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Definition: services.c:840
char * provider
Definition: services.h:170
int expected_rc
Definition: services.h:184
char * stderr_data
Definition: services.h:188