pacemaker  1.1.18-7fdfbbe
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 */
159 };
160 
162 typedef struct svc_action_s {
163  char *id;
164  char *rsc;
165  char *action;
166  int interval;
167 
168  char *standard;
169  char *provider;
170  char *agent;
171 
172  int timeout;
173  GHashTable *params; /* used by OCF agents and alert agents */
174 
175  int rc;
176  int pid;
177  int cancel;
178  int status;
179  int sequence;
183 
184  char *stderr_data;
185  char *stdout_data;
186 
193  void *cb_data;
194 
196 } svc_action_t;
197 
208  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
209 
216  GList *services_list(void);
217 
226  GList *resources_list_providers(const char *standard);
227 
237  GList *resources_list_agents(const char *standard, const char *provider);
238 
245  GList *resources_list_standards(void);
246 
247  svc_action_t *services_action_create(const char *name, const char *action,
248  int interval /* ms */ , int timeout /* ms */ );
249 
268  svc_action_t *resources_action_create(const char *name, const char *standard,
269  const char *provider, const char *agent,
270  const char *action, int interval /* ms */ ,
271  int timeout /* ms */ , GHashTable * params,
272  enum svc_action_flags flags);
273 
277  gboolean services_action_kick(const char *name, const char *action, int interval /* ms */);
278 
279  const char *resources_find_service_class(const char *agent);
280 
294  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
295 
298  int services_action_user(svc_action_t *op, const char *user);
299 
300  gboolean services_action_sync(svc_action_t * op);
301 
311  gboolean services_action_async(svc_action_t * op, void (*action_callback) (svc_action_t *));
312 
313  gboolean services_action_cancel(const char *name, const char *action, int interval);
314 
315 /* functions for alert agents */
316 svc_action_t *services_alert_create(const char *id, const char *exec,
317  int timeout, GHashTable *params,
318  int sequence, void *cb_data);
319 gboolean services_alert_async(svc_action_t *action,
320  void (*cb)(svc_action_t *op));
321 
322  static inline const char *services_lrm_status_str(enum op_status status) {
323  switch (status) {
324  case PCMK_LRM_OP_PENDING:
325  return "pending";
326  case PCMK_LRM_OP_DONE:return "complete";
327  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
328  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
329  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
330  case PCMK_LRM_OP_ERROR:return "Error";
331  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
332  default:return "UNKNOWN!";
333  }
334  }
335 
336  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
337  switch (code) {
338  case PCMK_OCF_OK:
339  return "ok";
341  return "unknown error";
343  return "invalid parameter";
345  return "unimplemented feature";
347  return "insufficient privileges";
349  return "not installed";
351  return "not configured";
353  return "not running";
355  return "master";
357  return "master (failed)";
358  case PCMK_OCF_SIGNAL:
359  return "OCF_SIGNAL";
361  return "OCF_NOT_SUPPORTED";
362  case PCMK_OCF_PENDING:
363  return "OCF_PENDING";
364  case PCMK_OCF_CANCELLED:
365  return "OCF_CANCELLED";
366  case PCMK_OCF_TIMEOUT:
367  return "OCF_TIMEOUT";
369  return "OCF_OTHER_ERROR";
370  case PCMK_OCF_DEGRADED:
371  return "OCF_DEGRADED";
373  return "OCF_DEGRADED_MASTER";
374  default:
375  return "unknown";
376  }
377  }
378 
387  static inline enum ocf_exitcode
388  services_get_ocf_exitcode(const char *action, int lsb_exitcode)
389  {
390  /* For non-status actions, LSB and OCF share error code meaning <= 7 */
391  if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
392  if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) {
393  return PCMK_OCF_UNKNOWN_ERROR;
394  }
395  return (enum ocf_exitcode)lsb_exitcode;
396  }
397 
398  /* status has different return codes */
399  switch (lsb_exitcode) {
400  case PCMK_LSB_STATUS_OK:
401  return PCMK_OCF_OK;
403  return PCMK_OCF_NOT_INSTALLED;
409  return PCMK_OCF_NOT_RUNNING;
410  }
411  return PCMK_OCF_UNKNOWN_ERROR;
412  }
413 
414 # ifdef __cplusplus
415 }
416 # endif
417 
418 #endif /* __PCMK_SERVICES__ */
struct svc_action_s svc_action_t
void services_action_free(svc_action_t *op)
Definition: services.c:563
char * standard
Definition: services.h:168
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:163
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
Definition: services.c:70
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:165
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Definition: services.c:367
char * rsc
Definition: services.h:164
int interval
Definition: services.h:166
svc_action_flags
Definition: services.h:156
void services_action_cleanup(svc_action_t *op)
Definition: services.c:527
enum svc_action_flags flags
Definition: services.h:182
op_status
Definition: services.h:133
svc_action_private_t * opaque
Definition: services.h:195
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:405
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:1316
char * stdout_data
Definition: services.h:185
GHashTable * params
Definition: services.h:173
gboolean services_action_cancel(const char *name, const char *action, int interval)
Cancel a recurring action.
Definition: services.c:641
char * agent
Definition: services.h:170
int synchronous
Definition: services.h:181
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:1415
int sequence
Definition: services.h:179
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:435
gboolean services_action_kick(const char *name, const char *action, int interval)
Definition: services.c:704
char * action
Definition: services.h:165
ocf_exitcode
Definition: services.h:104
GList * resources_list_standards(void)
Definition: services.c:1371
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:1351
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:1425
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
Definition: services.c:482
void * cb_data
Definition: services.h:193
GList * services_list(void)
Definition: services.c:1357
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Definition: services.c:827
char * provider
Definition: services.h:169
uint64_t flags
Definition: remote.c:156
int expected_rc
Definition: services.h:180
char * stderr_data
Definition: services.h:184