| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef __PCMK_SERVICES__ |
| # define __PCMK_SERVICES__ |
| |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
| |
| |
| |
| |
| |
| |
| |
| # include <glib.h> |
| # include <stdio.h> |
| # include <stdint.h> |
| # include <string.h> |
| # include <stdbool.h> |
| # include <sys/types.h> |
| |
| # include "common/results.h" |
| |
| # ifndef OCF_ROOT_DIR |
| # define OCF_ROOT_DIR "/usr/lib/ocf" |
| # endif |
| |
| # ifndef LSB_ROOT_DIR |
| # define LSB_ROOT_DIR "/etc/init.d" |
| # endif |
| |
| |
| # ifndef SYSTEMCTL |
| # define SYSTEMCTL "/bin/systemctl" |
| # endif |
| |
| |
| #define PCMK_RESOURCE_CLASS_OCF "ocf" |
| #define PCMK_RESOURCE_CLASS_SERVICE "service" |
| #define PCMK_RESOURCE_CLASS_LSB "lsb" |
| #define PCMK_RESOURCE_CLASS_SYSTEMD "systemd" |
| #define PCMK_RESOURCE_CLASS_UPSTART "upstart" |
| #define PCMK_RESOURCE_CLASS_NAGIOS "nagios" |
| #define PCMK_RESOURCE_CLASS_STONITH "stonith" |
| |
| |
| |
| |
| |
| #define PCMK_OCF_REASON_PREFIX "ocf-exit-reason:" |
| |
| |
| #define PCMK_DEFAULT_AGENT_VERSION "0.1" |
| |
| enum lsb_exitcode { |
| PCMK_LSB_OK = 0, |
| PCMK_LSB_UNKNOWN_ERROR = 1, |
| PCMK_LSB_INVALID_PARAM = 2, |
| PCMK_LSB_UNIMPLEMENT_FEATURE = 3, |
| PCMK_LSB_INSUFFICIENT_PRIV = 4, |
| PCMK_LSB_NOT_INSTALLED = 5, |
| PCMK_LSB_NOT_CONFIGURED = 6, |
| PCMK_LSB_NOT_RUNNING = 7, |
| }; |
| |
| |
| |
| |
| enum lsb_status_exitcode { |
| PCMK_LSB_STATUS_OK = 0, |
| PCMK_LSB_STATUS_VAR_PID = 1, |
| PCMK_LSB_STATUS_VAR_LOCK = 2, |
| PCMK_LSB_STATUS_NOT_RUNNING = 3, |
| PCMK_LSB_STATUS_UNKNOWN = 4, |
| |
| |
| PCMK_LSB_STATUS_NOT_INSTALLED = 150, |
| PCMK_LSB_STATUS_INSUFFICIENT_PRIV = 151, |
| }; |
| |
| enum op_status { |
| PCMK_LRM_OP_UNKNOWN = -2, |
| PCMK_LRM_OP_PENDING = -1, |
| PCMK_LRM_OP_DONE, |
| PCMK_LRM_OP_CANCELLED, |
| PCMK_LRM_OP_TIMEOUT, |
| PCMK_LRM_OP_NOTSUPPORTED, |
| PCMK_LRM_OP_ERROR, |
| PCMK_LRM_OP_ERROR_HARD, |
| PCMK_LRM_OP_ERROR_FATAL, |
| PCMK_LRM_OP_NOT_INSTALLED, |
| PCMK_LRM_OP_NOT_CONNECTED, |
| PCMK_LRM_OP_INVALID, |
| }; |
| |
| enum nagios_exitcode { |
| NAGIOS_STATE_OK = 0, |
| NAGIOS_STATE_WARNING = 1, |
| NAGIOS_STATE_CRITICAL = 2, |
| NAGIOS_STATE_UNKNOWN = 3, |
| NAGIOS_STATE_DEPENDENT = 4, |
| |
| NAGIOS_INSUFFICIENT_PRIV = 100, |
| NAGIOS_NOT_INSTALLED = 101, |
| }; |
| |
| enum svc_action_flags { |
| |
| SVC_ACTION_LEAVE_GROUP = 0x01, |
| SVC_ACTION_NON_BLOCKED = 0x02, |
| }; |
| |
| typedef struct svc_action_private_s svc_action_private_t; |
| typedef struct svc_action_s { |
| char *id; |
| char *rsc; |
| char *action; |
| guint interval_ms; |
| |
| char *standard; |
| char *provider; |
| char *agent; |
| |
| int timeout; |
| GHashTable *params; |
| |
| |
| |
| |
| int rc; |
| int pid; |
| int cancel; |
| int status; |
| int sequence; |
| int expected_rc; |
| int synchronous; |
| enum svc_action_flags flags; |
| |
| char *stderr_data; |
| char *stdout_data; |
| |
| |
| |
| |
| |
| |
| |
| void *cb_data; |
| |
| svc_action_private_t *opaque; |
| } svc_action_t; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| GList *get_directory_list(const char *root, gboolean files, gboolean executable); |
| |
| |
| |
| |
| |
| |
| |
| GList *services_list(void); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| GList *resources_list_providers(const char *standard); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| GList *resources_list_agents(const char *standard, const char *provider); |
| |
| |
| |
| |
| |
| |
| |
| GList *resources_list_standards(void); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent); |
| |
| svc_action_t *services_action_create(const char *name, const char *action, |
| guint interval_ms, int timeout ); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| svc_action_t *resources_action_create(const char *name, const char *standard, |
| const char *provider, const char *agent, |
| const char *action, guint interval_ms, |
| int timeout , GHashTable *params, |
| enum svc_action_flags flags); |
| |
| |
| |
| |
| gboolean services_action_kick(const char *name, const char *action, |
| guint interval_ms); |
| |
| const char *resources_find_service_class(const char *agent); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| svc_action_t *services_action_create_generic(const char *exec, const char *args[]); |
| |
| void services_action_cleanup(svc_action_t * op); |
| void services_action_free(svc_action_t * op); |
| int services_action_user(svc_action_t *op, const char *user); |
| |
| gboolean services_action_sync(svc_action_t * op); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| gboolean services_action_async_fork_notify(svc_action_t * op, |
| void (*action_callback) (svc_action_t *), |
| void (*action_fork_callback) (svc_action_t *)); |
| |
| gboolean services_action_async(svc_action_t * op, |
| void (*action_callback) (svc_action_t *)); |
| |
| gboolean services_action_cancel(const char *name, const char *action, |
| guint interval_ms); |
| |
| |
| svc_action_t *services_alert_create(const char *id, const char *exec, |
| int timeout, GHashTable *params, |
| int sequence, void *cb_data); |
| gboolean services_alert_async(svc_action_t *action, |
| void (*cb)(svc_action_t *op)); |
| |
| static inline const char *services_lrm_status_str(enum op_status status) { |
| switch (status) { |
| case PCMK_LRM_OP_PENDING: |
| return "pending"; |
| case PCMK_LRM_OP_DONE:return "complete"; |
| case PCMK_LRM_OP_CANCELLED:return "Cancelled"; |
| case PCMK_LRM_OP_TIMEOUT:return "Timed Out"; |
| case PCMK_LRM_OP_NOTSUPPORTED:return "NOT SUPPORTED"; |
| case PCMK_LRM_OP_ERROR:return "Error"; |
| case PCMK_LRM_OP_NOT_INSTALLED:return "Not installed"; |
| case PCMK_LRM_OP_NOT_CONNECTED:return "No executor connection"; |
| case PCMK_LRM_OP_INVALID:return "Cannot execute now"; |
| default:return "UNKNOWN!"; |
| } |
| } |
| |
| static inline const char *services_ocf_exitcode_str(enum ocf_exitcode code) { |
| switch (code) { |
| case PCMK_OCF_OK: |
| return "ok"; |
| case PCMK_OCF_UNKNOWN_ERROR: |
| return "error"; |
| case PCMK_OCF_INVALID_PARAM: |
| return "invalid parameter"; |
| case PCMK_OCF_UNIMPLEMENT_FEATURE: |
| return "unimplemented feature"; |
| case PCMK_OCF_INSUFFICIENT_PRIV: |
| return "insufficient privileges"; |
| case PCMK_OCF_NOT_INSTALLED: |
| return "not installed"; |
| case PCMK_OCF_NOT_CONFIGURED: |
| return "not configured"; |
| case PCMK_OCF_NOT_RUNNING: |
| return "not running"; |
| case PCMK_OCF_RUNNING_MASTER: |
| return "master"; |
| case PCMK_OCF_FAILED_MASTER: |
| return "master (failed)"; |
| case PCMK_OCF_SIGNAL: |
| return "OCF_SIGNAL"; |
| case PCMK_OCF_NOT_SUPPORTED: |
| return "OCF_NOT_SUPPORTED"; |
| case PCMK_OCF_PENDING: |
| return "OCF_PENDING"; |
| case PCMK_OCF_CANCELLED: |
| return "OCF_CANCELLED"; |
| case PCMK_OCF_TIMEOUT: |
| return "OCF_TIMEOUT"; |
| case PCMK_OCF_OTHER_ERROR: |
| return "OCF_OTHER_ERROR"; |
| case PCMK_OCF_DEGRADED: |
| return "OCF_DEGRADED"; |
| case PCMK_OCF_DEGRADED_MASTER: |
| return "OCF_DEGRADED_MASTER"; |
| default: |
| return "unknown"; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static inline enum ocf_exitcode |
| services_get_ocf_exitcode(const char *action, int lsb_exitcode) |
| { |
| |
| if (action && strcmp(action, "status") && strcmp(action, "monitor")) { |
| if ((lsb_exitcode < 0) || (lsb_exitcode > PCMK_LSB_NOT_RUNNING)) { |
| return PCMK_OCF_UNKNOWN_ERROR; |
| } |
| return (enum ocf_exitcode)lsb_exitcode; |
| } |
| |
| |
| switch (lsb_exitcode) { |
| case PCMK_LSB_STATUS_OK: |
| return PCMK_OCF_OK; |
| case PCMK_LSB_STATUS_NOT_INSTALLED: |
| return PCMK_OCF_NOT_INSTALLED; |
| case PCMK_LSB_STATUS_INSUFFICIENT_PRIV: |
| return PCMK_OCF_INSUFFICIENT_PRIV; |
| case PCMK_LSB_STATUS_VAR_PID: |
| case PCMK_LSB_STATUS_VAR_LOCK: |
| case PCMK_LSB_STATUS_NOT_RUNNING: |
| return PCMK_OCF_NOT_RUNNING; |
| } |
| return PCMK_OCF_UNKNOWN_ERROR; |
| } |
| |
| # ifdef __cplusplus |
| } |
| # endif |
| |
| #endif /* __PCMK_SERVICES__ */ |