This source file includes following definitions.
- services_lrm_status_str
- services_ocf_exitcode_str
- services_get_ocf_exitcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
47 # ifndef SYSTEMCTL
48 # define SYSTEMCTL "/bin/systemctl"
49 # endif
50
51
52 # ifndef SERVICE_SCRIPT
53 # define SERVICE_SCRIPT "/sbin/service"
54 # endif
55
56
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
67
68
69
70 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
71
72
73 #define PCMK_DEFAULT_AGENT_VERSION "0.1"
74
75 enum lsb_exitcode {
76 PCMK_LSB_OK = 0,
77 PCMK_LSB_UNKNOWN_ERROR = 1,
78 PCMK_LSB_INVALID_PARAM = 2,
79 PCMK_LSB_UNIMPLEMENT_FEATURE = 3,
80 PCMK_LSB_INSUFFICIENT_PRIV = 4,
81 PCMK_LSB_NOT_INSTALLED = 5,
82 PCMK_LSB_NOT_CONFIGURED = 6,
83 PCMK_LSB_NOT_RUNNING = 7,
84 };
85
86
87
88
89 enum lsb_status_exitcode {
90 PCMK_LSB_STATUS_OK = 0,
91 PCMK_LSB_STATUS_VAR_PID = 1,
92 PCMK_LSB_STATUS_VAR_LOCK = 2,
93 PCMK_LSB_STATUS_NOT_RUNNING = 3,
94 PCMK_LSB_STATUS_UNKNOWN = 4,
95
96
97 PCMK_LSB_STATUS_NOT_INSTALLED = 150,
98 PCMK_LSB_STATUS_INSUFFICIENT_PRIV = 151,
99 };
100
101
102
103
104 enum ocf_exitcode {
105 PCMK_OCF_OK = 0,
106 PCMK_OCF_UNKNOWN_ERROR = 1,
107 PCMK_OCF_INVALID_PARAM = 2,
108 PCMK_OCF_UNIMPLEMENT_FEATURE = 3,
109 PCMK_OCF_INSUFFICIENT_PRIV = 4,
110 PCMK_OCF_NOT_INSTALLED = 5,
111 PCMK_OCF_NOT_CONFIGURED = 6,
112 PCMK_OCF_NOT_RUNNING = 7,
113 PCMK_OCF_RUNNING_MASTER = 8,
114 PCMK_OCF_FAILED_MASTER = 9,
115
116
117
118 PCMK_OCF_CONNECTION_DIED = 189,
119
120 PCMK_OCF_DEGRADED = 190,
121 PCMK_OCF_DEGRADED_MASTER = 191,
122
123 PCMK_OCF_EXEC_ERROR = 192,
124 PCMK_OCF_UNKNOWN = 193,
125 PCMK_OCF_SIGNAL = 194,
126 PCMK_OCF_NOT_SUPPORTED = 195,
127 PCMK_OCF_PENDING = 196,
128 PCMK_OCF_CANCELLED = 197,
129 PCMK_OCF_TIMEOUT = 198,
130 PCMK_OCF_OTHER_ERROR = 199,
131 };
132
133 enum op_status {
134 PCMK_LRM_OP_PENDING = -1,
135 PCMK_LRM_OP_DONE,
136 PCMK_LRM_OP_CANCELLED,
137 PCMK_LRM_OP_TIMEOUT,
138 PCMK_LRM_OP_NOTSUPPORTED,
139 PCMK_LRM_OP_ERROR,
140 PCMK_LRM_OP_ERROR_HARD,
141 PCMK_LRM_OP_ERROR_FATAL,
142 PCMK_LRM_OP_NOT_INSTALLED,
143 };
144
145 enum nagios_exitcode {
146 NAGIOS_STATE_OK = 0,
147 NAGIOS_STATE_WARNING = 1,
148 NAGIOS_STATE_CRITICAL = 2,
149 NAGIOS_STATE_UNKNOWN = 3,
150 NAGIOS_STATE_DEPENDENT = 4,
151
152 NAGIOS_INSUFFICIENT_PRIV = 100,
153 NAGIOS_NOT_INSTALLED = 101,
154 };
155
156 enum svc_action_flags {
157
158 SVC_ACTION_LEAVE_GROUP = 0x01,
159 };
160
161 typedef struct svc_action_private_s svc_action_private_t;
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;
174
175 int rc;
176 int pid;
177 int cancel;
178 int status;
179 int sequence;
180 int expected_rc;
181 int synchronous;
182 enum svc_action_flags flags;
183
184 char *stderr_data;
185 char *stdout_data;
186
187
188
189
190
191
192
193 void *cb_data;
194
195 svc_action_private_t *opaque;
196 } svc_action_t;
197
198
199
200
201
202
203
204
205
206
207
208 GList *get_directory_list(const char *root, gboolean files, gboolean executable);
209
210
211
212
213
214
215
216 GList *services_list(void);
217
218
219
220
221
222
223
224
225
226 GList *resources_list_providers(const char *standard);
227
228
229
230
231
232
233
234
235
236
237 GList *resources_list_agents(const char *standard, const char *provider);
238
239
240
241
242
243
244
245 GList *resources_list_standards(void);
246
247 svc_action_t *services_action_create(const char *name, const char *action,
248 int interval , int timeout );
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
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 ,
271 int timeout , GHashTable * params,
272 enum svc_action_flags flags);
273
274
275
276
277 gboolean services_action_kick(const char *name, const char *action, int interval );
278
279 const char *resources_find_service_class(const char *agent);
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294 svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
295
296 void services_action_cleanup(svc_action_t * op);
297 void services_action_free(svc_action_t * op);
298 int services_action_user(svc_action_t *op, const char *user);
299
300 gboolean services_action_sync(svc_action_t * op);
301
302
303
304
305
306
307
308
309
310
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
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";
340 case PCMK_OCF_UNKNOWN_ERROR:
341 return "unknown error";
342 case PCMK_OCF_INVALID_PARAM:
343 return "invalid parameter";
344 case PCMK_OCF_UNIMPLEMENT_FEATURE:
345 return "unimplemented feature";
346 case PCMK_OCF_INSUFFICIENT_PRIV:
347 return "insufficient privileges";
348 case PCMK_OCF_NOT_INSTALLED:
349 return "not installed";
350 case PCMK_OCF_NOT_CONFIGURED:
351 return "not configured";
352 case PCMK_OCF_NOT_RUNNING:
353 return "not running";
354 case PCMK_OCF_RUNNING_MASTER:
355 return "master";
356 case PCMK_OCF_FAILED_MASTER:
357 return "master (failed)";
358 case PCMK_OCF_SIGNAL:
359 return "OCF_SIGNAL";
360 case PCMK_OCF_NOT_SUPPORTED:
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";
368 case PCMK_OCF_OTHER_ERROR:
369 return "OCF_OTHER_ERROR";
370 case PCMK_OCF_DEGRADED:
371 return "OCF_DEGRADED";
372 case PCMK_OCF_DEGRADED_MASTER:
373 return "OCF_DEGRADED_MASTER";
374 default:
375 return "unknown";
376 }
377 }
378
379
380
381
382
383
384
385
386
387 static inline enum ocf_exitcode
388 services_get_ocf_exitcode(const char *action, int lsb_exitcode)
389 {
390
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
399 switch (lsb_exitcode) {
400 case PCMK_LSB_STATUS_OK:
401 return PCMK_OCF_OK;
402 case PCMK_LSB_STATUS_NOT_INSTALLED:
403 return PCMK_OCF_NOT_INSTALLED;
404 case PCMK_LSB_STATUS_INSUFFICIENT_PRIV:
405 return PCMK_OCF_INSUFFICIENT_PRIV;
406 case PCMK_LSB_STATUS_VAR_PID:
407 case PCMK_LSB_STATUS_VAR_LOCK:
408 case PCMK_LSB_STATUS_NOT_RUNNING:
409 return PCMK_OCF_NOT_RUNNING;
410 }
411 return PCMK_OCF_UNKNOWN_ERROR;
412 }
413
414 # ifdef __cplusplus
415 }
416 # endif
417
418 #endif