pacemaker  1.1.17-b36b869ca8
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 
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 /* Deprecated and unused by Pacemaker, kept for API backward compatibility */
51 # ifndef SERVICE_SCRIPT
52 # define SERVICE_SCRIPT "/sbin/service"
53 # endif
54 
55 /* Known resource classes */
56 #define PCMK_RESOURCE_CLASS_OCF "ocf"
57 #define PCMK_RESOURCE_CLASS_SERVICE "service"
58 #define PCMK_RESOURCE_CLASS_LSB "lsb"
59 #define PCMK_RESOURCE_CLASS_SYSTEMD "systemd"
60 #define PCMK_RESOURCE_CLASS_UPSTART "upstart"
61 #define PCMK_RESOURCE_CLASS_HB "heartbeat"
62 #define PCMK_RESOURCE_CLASS_NAGIOS "nagios"
63 #define PCMK_RESOURCE_CLASS_STONITH "stonith"
64 
65 /* This is the string passed in the OCF_EXIT_REASON_PREFIX
66  * environment variable. The stderr output that occurs
67  * after this prefix is encountered is considered the exit
68  * reason for a completed operationt */
69 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
70 
71 /* *INDENT-OFF* */
81 };
82 
83 /* The return codes for the status operation are not the same for other
84  * operatios - go figure
85  */
92 
93  /* custom codes should be in the 150-199 range reserved for application use */
96 };
97 
98 /* Uniform exit codes
99  * Everything is mapped to its OCF equivalent so that Pacemaker only deals with one set of codes
100  */
109  PCMK_OCF_NOT_RUNNING = 7, /* End of overlap with LSB */
112 
113 
114  /* 150-199 reserved for application use */
115  PCMK_OCF_CONNECTION_DIED = 189, /* Operation failure implied by disconnection of the LRM API to a local or remote node */
116 
117  PCMK_OCF_DEGRADED = 190, /* Active resource that is no longer 100% functional */
118  PCMK_OCF_DEGRADED_MASTER = 191, /* Promoted resource that is no longer 100% functional */
119 
120  PCMK_OCF_EXEC_ERROR = 192, /* Generic problem invoking the agent */
121  PCMK_OCF_UNKNOWN = 193, /* State of the service is unknown - used for recording in-flight operations */
127  PCMK_OCF_OTHER_ERROR = 199, /* Keep the same codes as PCMK_LSB */
128 };
129 
130 enum op_status {
140 };
141 
148 
151 };
152 
154  /* On timeout, only kill pid, do not kill entire pid group */
156 };
157 
158 /* *INDENT-ON* */
159 
161  typedef struct svc_action_s {
162  char *id;
163  char *rsc;
164  char *action;
165  int interval;
166 
167  char *standard;
168  char *provider;
169  char *agent;
170 
171  int timeout;
172  GHashTable *params;
173 
174  int rc;
175  int pid;
176  int cancel;
177  int status;
178  int sequence;
182 
183  char *stderr_data;
184  char *stdout_data;
185 
192  void *cb_data;
193 
195 
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 
285  const char *resources_find_service_class(const char *agent);
286 
300  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
301 
303 
305 
306  gboolean services_action_sync(svc_action_t * op);
307 
317  gboolean services_action_async(svc_action_t * op, void (*action_callback) (svc_action_t *));
318 
319  gboolean services_action_cancel(const char *name, const char *action, int interval);
320 
321  static inline const char *services_lrm_status_str(enum op_status status) {
322  switch (status) {
323  case PCMK_LRM_OP_PENDING:
324  return "pending";
325  case PCMK_LRM_OP_DONE:return "complete";
326  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
327  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
328  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
329  case PCMK_LRM_OP_ERROR:return "Error";
330  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
331  default:return "UNKNOWN!";
332  }
333  }
334 
335  static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
336  switch (code) {
337  case PCMK_OCF_OK:
338  return "ok";
340  return "unknown error";
342  return "invalid parameter";
344  return "unimplemented feature";
346  return "insufficient privileges";
348  return "not installed";
350  return "not configured";
352  return "not running";
354  return "master";
356  return "master (failed)";
357  case PCMK_OCF_SIGNAL:
358  return "OCF_SIGNAL";
360  return "OCF_NOT_SUPPORTED";
361  case PCMK_OCF_PENDING:
362  return "OCF_PENDING";
363  case PCMK_OCF_CANCELLED:
364  return "OCF_CANCELLED";
365  case PCMK_OCF_TIMEOUT:
366  return "OCF_TIMEOUT";
368  return "OCF_OTHER_ERROR";
369  case PCMK_OCF_DEGRADED:
370  return "OCF_DEGRADED";
372  return "OCF_DEGRADED_MASTER";
373  default:
374  return "unknown";
375  }
376  }
377 
386  static inline enum ocf_exitcode
387  services_get_ocf_exitcode(const char *action, int lsb_exitcode)
388  {
389  /* For non-status actions, LSB and OCF share error code meaning <= 7 */
390  if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
391  if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) {
392  return PCMK_OCF_UNKNOWN_ERROR;
393  }
394  return (enum ocf_exitcode)lsb_exitcode;
395  }
396 
397  /* status has different return codes */
398  switch (lsb_exitcode) {
399  case PCMK_LSB_STATUS_OK:
400  return PCMK_OCF_OK;
402  return PCMK_OCF_NOT_INSTALLED;
408  return PCMK_OCF_NOT_RUNNING;
409  }
410  return PCMK_OCF_UNKNOWN_ERROR;
411  }
412 
413 # ifdef __cplusplus
414 }
415 # endif
416 
417 #endif /* __PCMK_SERVICES__ */
struct svc_action_s svc_action_t
void services_action_free(svc_action_t *op)
Definition: services.c:443
char * standard
Definition: services.h:167
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:162
const char * resources_find_service_class(const char *agent)
Definition: services.c:59
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:154
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
Definition: services.c:355
char * rsc
Definition: services.h:163
int interval
Definition: services.h:165
svc_action_flags
Definition: services.h:153
void services_action_cleanup(svc_action_t *op)
Definition: services.c:407
enum svc_action_flags flags
Definition: services.h:181
op_status
Definition: services.h:130
svc_action_private_t * opaque
Definition: services.h:194
gboolean services_action_sync(svc_action_t *op)
Definition: services.c:793
char * stdout_data
Definition: services.h:184
GHashTable * params
Definition: services.h:172
gboolean services_action_cancel(const char *name, const char *action, int interval)
Cancel a recurring action.
Definition: services.c:521
char * agent
Definition: services.h:169
int synchronous
Definition: services.h:180
GList * resources_list_providers(const char *standard)
Get a list of providers.
Definition: services.c:879
int sequence
Definition: services.h:178
lsb_exitcode
Definition: services.h:72
nagios_exitcode
Definition: services.h:142
gboolean services_action_kick(const char *name, const char *action, int interval)
Definition: services.c:584
char * action
Definition: services.h:164
ocf_exitcode
Definition: services.h:101
GList * resources_list_standards(void)
Definition: services.c:835
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:815
lsb_status_exitcode
Definition: services.h:86
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
Definition: services.c:889
void * cb_data
Definition: services.h:192
GList * services_list(void)
Definition: services.c:821
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Definition: services.c:707
char * provider
Definition: services.h:168
int expected_rc
Definition: services.h:179
char * stderr_data
Definition: services.h:183