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