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 #ifndef __PCMK_SERVICES__
11 # define __PCMK_SERVICES__
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17
18
19
20
21
22
23 # include <glib.h>
24 # include <stdio.h>
25 # include <stdint.h>
26 # include <string.h>
27 # include <stdbool.h>
28 # include <sys/types.h>
29
30 # include "common/results.h"
31
32 # ifndef OCF_ROOT_DIR
33 # define OCF_ROOT_DIR "/usr/lib/ocf"
34 # endif
35
36 # ifndef LSB_ROOT_DIR
37 # define LSB_ROOT_DIR "/etc/init.d"
38 # endif
39
40
41 # ifndef SYSTEMCTL
42 # define SYSTEMCTL "/bin/systemctl"
43 # endif
44
45
46 #define PCMK_RESOURCE_CLASS_OCF "ocf"
47 #define PCMK_RESOURCE_CLASS_SERVICE "service"
48 #define PCMK_RESOURCE_CLASS_LSB "lsb"
49 #define PCMK_RESOURCE_CLASS_SYSTEMD "systemd"
50 #define PCMK_RESOURCE_CLASS_UPSTART "upstart"
51 #define PCMK_RESOURCE_CLASS_NAGIOS "nagios"
52 #define PCMK_RESOURCE_CLASS_STONITH "stonith"
53
54
55
56
57
58 #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:"
59
60
61 #define PCMK_DEFAULT_AGENT_VERSION "0.1"
62
63 enum lsb_exitcode {
64 PCMK_LSB_OK = 0,
65 PCMK_LSB_UNKNOWN_ERROR = 1,
66 PCMK_LSB_INVALID_PARAM = 2,
67 PCMK_LSB_UNIMPLEMENT_FEATURE = 3,
68 PCMK_LSB_INSUFFICIENT_PRIV = 4,
69 PCMK_LSB_NOT_INSTALLED = 5,
70 PCMK_LSB_NOT_CONFIGURED = 6,
71 PCMK_LSB_NOT_RUNNING = 7,
72 };
73
74
75
76
77 enum lsb_status_exitcode {
78 PCMK_LSB_STATUS_OK = 0,
79 PCMK_LSB_STATUS_VAR_PID = 1,
80 PCMK_LSB_STATUS_VAR_LOCK = 2,
81 PCMK_LSB_STATUS_NOT_RUNNING = 3,
82 PCMK_LSB_STATUS_UNKNOWN = 4,
83
84
85 PCMK_LSB_STATUS_NOT_INSTALLED = 150,
86 PCMK_LSB_STATUS_INSUFFICIENT_PRIV = 151,
87 };
88
89 enum op_status {
90 PCMK_LRM_OP_UNKNOWN = -2,
91 PCMK_LRM_OP_PENDING = -1,
92 PCMK_LRM_OP_DONE,
93 PCMK_LRM_OP_CANCELLED,
94 PCMK_LRM_OP_TIMEOUT,
95 PCMK_LRM_OP_NOTSUPPORTED,
96 PCMK_LRM_OP_ERROR,
97 PCMK_LRM_OP_ERROR_HARD,
98 PCMK_LRM_OP_ERROR_FATAL,
99 PCMK_LRM_OP_NOT_INSTALLED,
100 PCMK_LRM_OP_NOT_CONNECTED,
101 PCMK_LRM_OP_INVALID,
102 };
103
104 enum nagios_exitcode {
105 NAGIOS_STATE_OK = 0,
106 NAGIOS_STATE_WARNING = 1,
107 NAGIOS_STATE_CRITICAL = 2,
108 NAGIOS_STATE_UNKNOWN = 3,
109 NAGIOS_STATE_DEPENDENT = 4,
110
111 NAGIOS_INSUFFICIENT_PRIV = 100,
112 NAGIOS_NOT_INSTALLED = 101,
113 };
114
115 enum svc_action_flags {
116
117 SVC_ACTION_LEAVE_GROUP = 0x01,
118 SVC_ACTION_NON_BLOCKED = 0x02,
119 };
120
121 typedef struct svc_action_private_s svc_action_private_t;
122 typedef struct svc_action_s {
123 char *id;
124 char *rsc;
125 char *action;
126 guint interval_ms;
127
128 char *standard;
129 char *provider;
130 char *agent;
131
132 int timeout;
133 GHashTable *params;
134
135
136
137
138 int rc;
139 int pid;
140 int cancel;
141 int status;
142 int sequence;
143 int expected_rc;
144 int synchronous;
145 enum svc_action_flags flags;
146
147 char *stderr_data;
148 char *stdout_data;
149
150
151
152
153
154
155
156 void *cb_data;
157
158 svc_action_private_t *opaque;
159 } svc_action_t;
160
161
162
163
164
165
166
167
168
169
170
171 GList *get_directory_list(const char *root, gboolean files, gboolean executable);
172
173
174
175
176
177
178
179 GList *services_list(void);
180
181
182
183
184
185
186
187
188
189 GList *resources_list_providers(const char *standard);
190
191
192
193
194
195
196
197
198
199
200 GList *resources_list_agents(const char *standard, const char *provider);
201
202
203
204
205
206
207
208 GList *resources_list_standards(void);
209
210
211
212
213
214
215
216
217
218
219 gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent);
220
221 svc_action_t *services_action_create(const char *name, const char *action,
222 guint interval_ms, int timeout );
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242 svc_action_t *resources_action_create(const char *name, const char *standard,
243 const char *provider, const char *agent,
244 const char *action, guint interval_ms,
245 int timeout , GHashTable *params,
246 enum svc_action_flags flags);
247
248
249
250
251 gboolean services_action_kick(const char *name, const char *action,
252 guint interval_ms);
253
254 const char *resources_find_service_class(const char *agent);
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269 svc_action_t *services_action_create_generic(const char *exec, const char *args[]);
270
271 void services_action_cleanup(svc_action_t * op);
272 void services_action_free(svc_action_t * op);
273 int services_action_user(svc_action_t *op, const char *user);
274
275 gboolean services_action_sync(svc_action_t * op);
276
277
278
279
280
281
282
283
284
285
286
287 gboolean services_action_async_fork_notify(svc_action_t * op,
288 void (*action_callback) (svc_action_t *),
289 void (*action_fork_callback) (svc_action_t *));
290
291 gboolean services_action_async(svc_action_t * op,
292 void (*action_callback) (svc_action_t *));
293
294 gboolean services_action_cancel(const char *name, const char *action,
295 guint interval_ms);
296
297
298 svc_action_t *services_alert_create(const char *id, const char *exec,
299 int timeout, GHashTable *params,
300 int sequence, void *cb_data);
301 gboolean services_alert_async(svc_action_t *action,
302 void (*cb)(svc_action_t *op));
303
304 static inline const char *services_lrm_status_str(enum op_status status) {
305 switch (status) {
306 case PCMK_LRM_OP_PENDING:
307 return "pending";
308 case PCMK_LRM_OP_DONE:return "complete";
309 case PCMK_LRM_OP_CANCELLED:return "Cancelled";
310 case PCMK_LRM_OP_TIMEOUT:return "Timed Out";
311 case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED";
312 case PCMK_LRM_OP_ERROR:return "Error";
313 case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed";
314 case PCMK_LRM_OP_NOT_CONNECTED:return "No executor connection";
315 case PCMK_LRM_OP_INVALID:return "Cannot execute now";
316 default:return "UNKNOWN!";
317 }
318 }
319
320 static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) {
321 switch (code) {
322 case PCMK_OCF_OK:
323 return "ok";
324 case PCMK_OCF_UNKNOWN_ERROR:
325 return "error";
326 case PCMK_OCF_INVALID_PARAM:
327 return "invalid parameter";
328 case PCMK_OCF_UNIMPLEMENT_FEATURE:
329 return "unimplemented feature";
330 case PCMK_OCF_INSUFFICIENT_PRIV:
331 return "insufficient privileges";
332 case PCMK_OCF_NOT_INSTALLED:
333 return "not installed";
334 case PCMK_OCF_NOT_CONFIGURED:
335 return "not configured";
336 case PCMK_OCF_NOT_RUNNING:
337 return "not running";
338 case PCMK_OCF_RUNNING_MASTER:
339 return "master";
340 case PCMK_OCF_FAILED_MASTER:
341 return "master (failed)";
342 case PCMK_OCF_SIGNAL:
343 return "OCF_SIGNAL";
344 case PCMK_OCF_NOT_SUPPORTED:
345 return "OCF_NOT_SUPPORTED";
346 case PCMK_OCF_PENDING:
347 return "OCF_PENDING";
348 case PCMK_OCF_CANCELLED:
349 return "OCF_CANCELLED";
350 case PCMK_OCF_TIMEOUT:
351 return "OCF_TIMEOUT";
352 case PCMK_OCF_OTHER_ERROR:
353 return "OCF_OTHER_ERROR";
354 case PCMK_OCF_DEGRADED:
355 return "OCF_DEGRADED";
356 case PCMK_OCF_DEGRADED_MASTER:
357 return "OCF_DEGRADED_MASTER";
358 default:
359 return "unknown";
360 }
361 }
362
363
364
365
366
367
368
369
370
371 static inline enum ocf_exitcode
372 services_get_ocf_exitcode(const char *action, int lsb_exitcode)
373 {
374
375 if (action && strcmp(action, "status") && strcmp(action, "monitor")) {
376 if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) {
377 return PCMK_OCF_UNKNOWN_ERROR;
378 }
379 return (enum ocf_exitcode)lsb_exitcode;
380 }
381
382
383 switch (lsb_exitcode) {
384 case PCMK_LSB_STATUS_OK:
385 return PCMK_OCF_OK;
386 case PCMK_LSB_STATUS_NOT_INSTALLED:
387 return PCMK_OCF_NOT_INSTALLED;
388 case PCMK_LSB_STATUS_INSUFFICIENT_PRIV:
389 return PCMK_OCF_INSUFFICIENT_PRIV;
390 case PCMK_LSB_STATUS_VAR_PID:
391 case PCMK_LSB_STATUS_VAR_LOCK:
392 case PCMK_LSB_STATUS_NOT_RUNNING:
393 return PCMK_OCF_NOT_RUNNING;
394 }
395 return PCMK_OCF_UNKNOWN_ERROR;
396 }
397
398 # ifdef __cplusplus
399 }
400 # endif
401
402 #endif