pacemaker  1.1.14-70404b0
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 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 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 
37 # ifndef OCF_ROOT_DIR
38 # define OCF_ROOT_DIR "/usr/lib/ocf"
39 # endif
40 
41 # ifndef LSB_ROOT_DIR
42 # define LSB_ROOT_DIR "/etc/init.d"
43 # endif
44 
45 /* TODO: Autodetect these two ?*/
46 # ifndef SYSTEMCTL
47 # define SYSTEMCTL "/bin/systemctl"
48 # endif
49 
50 # ifndef SERVICE_SCRIPT
51 # define SERVICE_SCRIPT "/sbin/service"
52 # endif
53 
54 
55 /* This is the string passed in the OCF_EXIT_REASON_PREFIX
56  * environment variable. The stderr output that occurs
57  * after this prefix is encountered is considered the exit
58  * reason for a completed operationt */
59 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
60 
61 /* *INDENT-OFF* */
71 };
72 
73 /* The return codes for the status operation are not the same for other
74  * operatios - go figure
75  */
82 
83  /* custom codes should be in the 150-199 range reserved for application use */
86 };
87 
88 /* Uniform exit codes
89  * Everything is mapped to its OCF equivalent so that Pacemaker only deals with one set of codes
90  */
99  PCMK_OCF_NOT_RUNNING = 7, /* End of overlap with LSB */
102 
103 
104  /* 150-199 reserved for application use */
105  PCMK_OCF_CONNECTION_DIED = 189, /* Operation failure implied by disconnection of the LRM API to a local or remote node */
106 
107  PCMK_OCF_DEGRADED = 190, /* Active reasource that is no longer 100% functional */
108  PCMK_OCF_DEGRADED_MASTER = 191, /* Promoted reasource that is no longer 100% functional */
109 
110  PCMK_OCF_EXEC_ERROR = 192, /* Generic problem invoking the agent */
111  PCMK_OCF_UNKNOWN = 193, /* State of the service is unknown - used for recording in-flight operations */
117  PCMK_OCF_OTHER_ERROR = 199, /* Keep the same codes as PCMK_LSB */
118 };
119 
120 enum op_status {
130 };
131 
138 
141 };
142 
144  /* On timeout, only kill pid, do not kill entire pid group */
146 };
147 
148 /* *INDENT-ON* */
149 
151  typedef struct svc_action_s {
152  char *id;
153  char *rsc;
154  char *action;
155  int interval;
156 
157  char *standard;
158  char *provider;
159  char *agent;
160 
161  int timeout;
162  GHashTable *params;
163 
164  int rc;
165  int pid;
166  int cancel;
167  int status;
168  int sequence;
172 
173  char *stderr_data;
174  char *stdout_data;
175 
182  void *cb_data;
183 
185 
186  } svc_action_t;
187 
198  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
199 
206  GList *services_list(void);
207 
216  GList *resources_list_providers(const char *standard);
217 
227  GList *resources_list_agents(const char *standard, const char *provider);
228 
235  GList *resources_list_standards(void);
236 
237  svc_action_t *services_action_create(const char *name, const char *action,
238  int interval /* ms */ , int timeout /* ms */ );
239 
258  svc_action_t *resources_action_create(const char *name, const char *standard,
259  const char *provider, const char *agent,
260  const char *action, int interval /* ms */ ,
261  int timeout /* ms */ , GHashTable * params,
262  enum svc_action_flags flags);
263 
267  gboolean services_action_kick(const char *name, const char *action, int interval /* ms */);
268 
275  const char *resources_find_service_class(const char *agent);
276 
290  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
291 
293 
295 
296  gboolean services_action_sync(svc_action_t * op);
297 
307  gboolean services_action_async(svc_action_t * op, void (*action_callback) (svc_action_t *));
308 
309  gboolean services_action_cancel(const char *name, const char *action, int interval);
310 
311  static inline const char *services_lrm_status_str(enum op_status status) {
312  switch (status) {
313  case PCMK_LRM_OP_PENDING:
314  return "pending";
315  case PCMK_LRM_OP_DONE:return "complete";
316  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
317  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
318  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
319  case PCMK_LRM_OP_ERROR:return "Error";
320  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
321  default:return "UNKNOWN!";
322  }
323  }
324 
325  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
326  switch (code) {
327  case PCMK_OCF_OK:
328  return "ok";
330  return "unknown error";
332  return "invalid parameter";
334  return "unimplemented feature";
336  return "insufficient privileges";
338  return "not installed";
340  return "not configured";
342  return "not running";
344  return "master";
346  return "master (failed)";
347  case PCMK_OCF_SIGNAL:
348  return "OCF_SIGNAL";
350  return "OCF_NOT_SUPPORTED";
351  case PCMK_OCF_PENDING:
352  return "OCF_PENDING";
353  case PCMK_OCF_CANCELLED:
354  return "OCF_CANCELLED";
355  case PCMK_OCF_TIMEOUT:
356  return "OCF_TIMEOUT";
358  return "OCF_OTHER_ERROR";
359  case PCMK_OCF_DEGRADED:
360  return "OCF_DEGRADED";
362  return "OCF_DEGRADED_MASTER";
363  default:
364  return "unknown";
365  }
366  }
367 
376  static inline enum ocf_exitcode
377  services_get_ocf_exitcode(const char *action, int lsb_exitcode)
378  {
379  /* For non-status actions, LSB and OCF share error code meaning <= 7 */
380  if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
381  if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) {
382  return PCMK_OCF_UNKNOWN_ERROR;
383  }
384  return (enum ocf_exitcode)lsb_exitcode;
385  }
386 
387  /* status has different return codes */
388  switch (lsb_exitcode) {
389  case PCMK_LSB_STATUS_OK:
390  return PCMK_OCF_OK;
392  return PCMK_OCF_NOT_INSTALLED;
398  return PCMK_OCF_NOT_RUNNING;
399  }
400  return PCMK_OCF_UNKNOWN_ERROR;
401  }
402 
403 # ifdef __cplusplus
404 }
405 # endif
406 
407 #endif /* __PCMK_SERVICES__ */
struct svc_action_s svc_action_t
void services_action_free(svc_action_t *op)
Definition: services.c:417
char * standard
Definition: services.h:157
svc_action_t * services_action_create(const char *name, const char *action, int interval, int timeout)
Definition: services.c:61
char * id
Definition: services.h:152
const char * resources_find_service_class(const char *agent)
Definition: services.c:67
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:103
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Definition: services.c:329
char * rsc
Definition: services.h:153
int interval
Definition: services.h:155
svc_action_flags
Definition: services.h:143
void services_action_cleanup(svc_action_t *op)
Definition: services.c:381
enum svc_action_flags flags
Definition: services.h:171
op_status
Definition: services.h:120
svc_action_private_t * opaque
Definition: services.h:184
uint64_t flags
Definition: remote.c:121
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:703
char * stdout_data
Definition: services.h:174
GHashTable * params
Definition: services.h:162
gboolean services_action_cancel(const char *name, const char *action, int interval)
Definition: services.c:476
char * agent
Definition: services.h:159
int synchronous
Definition: services.h:170
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:800
int sequence
Definition: services.h:168
lsb_exitcode
Definition: services.h:62
nagios_exitcode
Definition: services.h:132
gboolean services_action_kick(const char *name, const char *action, int interval)
Definition: services.c:514
char * action
Definition: services.h:154
ocf_exitcode
Definition: services.h:91
GList * resources_list_standards(void)
Definition: services.c:755
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:735
lsb_status_exitcode
Definition: services.h:76
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:810
void * cb_data
Definition: services.h:182
GList * services_list(void)
Definition: services.c:741
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Definition: services.c:618
char * provider
Definition: services.h:158
int expected_rc
Definition: services.h:169
char * stderr_data
Definition: services.h:173