pacemaker  1.1.12-561c4cf
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules 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 
36 # ifndef OCF_ROOT_DIR
37 # define OCF_ROOT_DIR "/usr/lib/ocf"
38 # endif
39 
40 # ifndef LSB_ROOT_DIR
41 # define LSB_ROOT_DIR "/etc/init.d"
42 # endif
43 
44 /* TODO: Autodetect these two ?*/
45 # ifndef SYSTEMCTL
46 # define SYSTEMCTL "/bin/systemctl"
47 # endif
48 
49 # ifndef SERVICE_SCRIPT
50 # define SERVICE_SCRIPT "/sbin/service"
51 # endif
52 
53 /* *INDENT-OFF* */
63 };
64 
65 /* The return codes for the status operation are not the same for other
66  * operatios - go figure
67  */
74 };
75 
76 /* Uniform exit codes
77  * Everything is mapped to its OCF equivalent so that Pacemaker only deals with one set of codes
78  */
87  PCMK_OCF_NOT_RUNNING = 7, /* End of overlap with LSB */
90 
91 
92  /* 150-199 reserved for application use */
93  PCMK_OCF_EXEC_ERROR = 192, /* Generic problem invoking the agent */
94  PCMK_OCF_UNKNOWN = 193, /* State of the service is unknown - used for recording in-flight operations */
100  PCMK_OCF_OTHER_ERROR = 199, /* Keep the same codes as PCMK_LSB */
101 };
102 
103 enum op_status {
113 };
114 
121 
124 };
125 /* *INDENT-ON* */
126 
127  typedef struct svc_action_private_s svc_action_private_t;
128  typedef struct svc_action_s {
129  char *id;
130  char *rsc;
131  char *action;
132  int interval;
133 
134  char *standard;
135  char *provider;
136  char *agent;
137 
138  int timeout;
139  GHashTable *params;
140 
141  int rc;
142  int pid;
143  int cancel;
144  int status;
145  int sequence;
147 
148  char *stderr_data;
149  char *stdout_data;
150 
157  void *cb_data;
158 
160 
161  } svc_action_t;
162 
172  GList *get_directory_list(const char *root, gboolean files, gboolean executable);
173 
180  GList *services_list(void);
181 
190  GList *resources_list_providers(const char *standard);
191 
201  GList *resources_list_agents(const char *standard, const char *provider);
202 
209  GList *resources_list_standards(void);
210 
211  svc_action_t *services_action_create(const char *name, const char *action,
212  int interval /* ms */ , int timeout /* ms */ );
213 
223  svc_action_t *resources_action_create(const char *name, const char *standard,
224  const char *provider, const char *agent,
225  const char *action, int interval /* ms */ ,
226  int timeout /* ms */ , GHashTable * params);
227 
231  gboolean services_action_kick(const char *name, const char *action, int interval /* ms */);
232 
239  const char *resources_find_service_class(const char *agent);
240 
254  svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
255 
256  void
258 
259  gboolean services_action_sync(svc_action_t * op);
260 
270  gboolean services_action_async(svc_action_t * op, void (*action_callback) (svc_action_t *));
271 
272  gboolean services_action_cancel(const char *name, const char *action, int interval);
273 
274  static inline const char *services_lrm_status_str(enum op_status status) {
275  switch (status) {
276  case PCMK_LRM_OP_PENDING:
277  return "pending";
278  case PCMK_LRM_OP_DONE:return "complete";
279  case PCMK_LRM_OP_CANCELLED:return "Cancelled";
280  case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
281  case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
282  case PCMK_LRM_OP_ERROR:return "Error";
283  case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
284  default:return "UNKNOWN!";
285  }} static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
286  switch (code) {
287  case PCMK_OCF_OK:
288  return "ok";
290  return "unknown error";
292  return "invalid parameter";
294  return "unimplemented feature";
296  return "insufficient privileges";
298  return "not installed";
300  return "not configured";
302  return "not running";
304  return "master";
306  return "master (failed)";
307  case PCMK_OCF_SIGNAL:
308  return "OCF_SIGNAL";
310  return "OCF_NOT_SUPPORTED";
311  case PCMK_OCF_PENDING:
312  return "OCF_PENDING";
313  case PCMK_OCF_CANCELLED:
314  return "OCF_CANCELLED";
315  case PCMK_OCF_TIMEOUT:
316  return "OCF_TIMEOUT";
318  return "OCF_OTHER_ERROR";
319  default:
320  return "unknown";
321  }
322  }
323 
324  static inline enum ocf_exitcode
325  services_get_ocf_exitcode(char *action, int lsb_exitcode) {
326  if (action != NULL && strcmp("status", action) == 0) {
327  switch (lsb_exitcode) {
328  case PCMK_LSB_STATUS_OK:
329  return PCMK_OCF_OK;
331  return PCMK_OCF_NOT_RUNNING;
333  return PCMK_OCF_NOT_RUNNING;
335  return PCMK_OCF_NOT_RUNNING;
337  return PCMK_OCF_UNKNOWN_ERROR;
338  default:
339  return PCMK_OCF_UNKNOWN_ERROR;
340  }
341 
342  } else if (lsb_exitcode > PCMK_LSB_NOT_RUNNING) {
343  return PCMK_OCF_UNKNOWN_ERROR;
344  }
345 
346  /* For non-status operations, the PCMK_LSB and PCMK_OCF share error code meaning
347  * for rc <= 7 */
348  return (enum ocf_exitcode)lsb_exitcode;
349  }
350 
351 # ifdef __cplusplus
352 }
353 # endif
354 
355 #endif /* __PCMK_SERVICES__ */
struct svc_action_s svc_action_t
void services_action_free(svc_action_t *op)
char * standard
Definition: services.h:134
svc_action_t * services_action_create(const char *name, const char *action, int interval, int timeout)
char * id
Definition: services.h:129
const char * resources_find_service_class(const char *agent)
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
char * rsc
Definition: services.h:130
int interval
Definition: services.h:132
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)
struct svc_action_private_s svc_action_private_t
Definition: services.h:127
op_status
Definition: services.h:103
svc_action_private_t * opaque
Definition: services.h:159
gboolean services_action_sync(svc_action_t *op)
char * stdout_data
Definition: services.h:149
GHashTable * params
Definition: services.h:139
gboolean services_action_cancel(const char *name, const char *action, int interval)
char * agent
Definition: services.h:136
GList * resources_list_providers(const char *standard)
int sequence
Definition: services.h:145
lsb_exitcode
Definition: services.h:54
nagios_exitcode
Definition: services.h:115
gboolean services_action_kick(const char *name, const char *action, int interval)
char * action
Definition: services.h:131
ocf_exitcode
Definition: services.h:79
GList * resources_list_standards(void)
GList * get_directory_list(const char *root, gboolean files, gboolean executable)
lsb_status_exitcode
Definition: services.h:68
GList * resources_list_agents(const char *standard, const char *provider)
void * cb_data
Definition: services.h:157
GList * services_list(void)
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
char * provider
Definition: services.h:135
int expected_rc
Definition: services.h:146
char * stderr_data
Definition: services.h:148