25 #include <sys/types.h> 50 static int operations = 0;
80 if (rc > 0 && stat(path, &st) == 0) {
109 static inline gboolean
119 const char *agent,
const char *action,
int interval,
int timeout,
129 if (crm_strlen_zero(name)) {
130 crm_err(
"A service or resource action must have a name.");
134 if (crm_strlen_zero(standard)) {
135 crm_err(
"A service action must have a valid standard.");
139 if (!strcasecmp(standard,
"ocf") && crm_strlen_zero(provider)) {
140 crm_err(
"An OCF resource action must have a provider.");
144 if (crm_strlen_zero(agent)) {
145 crm_err(
"A service or resource action must have an agent.");
149 if (crm_strlen_zero(action)) {
150 crm_err(
"A service or resource action must specify an action.");
168 op->
rsc = strdup(name);
169 op->
action = strdup(action);
173 op->
agent = strdup(agent);
177 if (asprintf(&op->
id,
"%s_%s_%d", name, action, interval) == -1) {
181 if (strcasecmp(op->
standard,
"service") == 0) {
197 if (strcasecmp(op->
standard,
"ocf") == 0) {
203 crm_err(
"Internal error: cannot create agent path");
209 }
else if (strcasecmp(op->
standard,
"lsb") == 0) {
210 if (op->
agent[0] ==
'/') {
215 crm_err(
"Internal error: cannot create agent path");
221 #if SUPPORT_HEARTBEAT 222 }
else if (strcasecmp(op->
standard,
"heartbeat") == 0) {
228 if (op->
agent[0] ==
'/') {
232 }
else if (asprintf(&op->
opaque->
exec,
"%s/%s", HB_RA_DIR, op->
agent) == -1) {
233 crm_err(
"Internal error: cannot create agent path");
241 for (index = 1; index <=
MAX_ARGC - 3; index++ ) {
242 snprintf(buf_tmp,
sizeof(buf_tmp),
"%d", index);
243 value_tmp = g_hash_table_lookup(params, buf_tmp);
244 if (value_tmp == NULL) {
249 op->
opaque->
args[param_num++] = strdup(value_tmp);
258 }
else if (strcasecmp(op->
standard,
"systemd") == 0) {
262 }
else if (strcasecmp(op->
standard,
"upstart") == 0) {
265 }
else if (strcasecmp(op->
standard,
"service") == 0) {
272 }
else if (strcasecmp(op->
standard,
"nagios") == 0) {
275 if (op->
agent[0] ==
'/') {
281 crm_err(
"Internal error: cannot create agent path");
290 op->
opaque->
args[index] = strdup(
"--version");
297 static int args_size =
sizeof(op->
opaque->
args) /
sizeof(
char *);
299 g_hash_table_iter_init(&iter, params);
301 while (g_hash_table_iter_next(&iter, (gpointer *) & key, (gpointer *) & value) &&
302 index <= args_size - 3) {
304 char *long_opt = NULL;
311 long_opt = calloc(1, len);
312 sprintf(long_opt,
"--%s", key);
313 long_opt[len - 1] = 0;
330 g_hash_table_destroy(params);
336 g_hash_table_destroy(params);
347 unsigned int cur_arg;
349 op = calloc(1,
sizeof(*op));
355 for (cur_arg = 1; args && args[cur_arg - 1]; cur_arg++) {
356 op->
opaque->
args[cur_arg] = strdup(args[cur_arg - 1]);
359 crm_err(
"svc_action_t args list not long enough for '%s' execution request.", exec);
376 services_set_op_pending(
svc_action_t *op, DBusPendingCall *pending)
378 if (op->
opaque->pending && (op->
opaque->pending != pending)) {
384 dbus_pending_call_unref(op->
opaque->pending);
386 op->
opaque->pending = pending;
388 crm_trace(
"Updated pending %s DBus call (%p)", op->
id, pending);
403 if(op->
opaque->timerid != 0) {
405 g_source_remove(op->
opaque->timerid);
411 if(dbus_pending_call_get_completed(op->
opaque->pending)) {
414 dbus_pending_call_cancel(op->
opaque->pending);
415 dbus_pending_call_unref(op->
opaque->pending);
416 op->
opaque->pending = NULL;
476 g_hash_table_destroy(op->
params);
512 gboolean cancelled = FALSE;
534 crm_info(
"Terminating in-flight op %s (pid %d) early because it was cancelled",
537 if (cancelled == FALSE) {
538 crm_err(
"Termination of %s (pid %d) failed",
id, op->
pid);
548 if (inflight_systemd_or_upstart(op)) {
549 crm_info(
"Will cancel %s op %s when in-flight instance completes",
576 if (asprintf(&
id,
"%s_%s_%d", name, action, interval) == -1) {
588 if (op->
pid || inflight_systemd_or_upstart(op)) {
617 if (dup && (dup != op)) {
696 if (action_callback) {
701 if (handle_duplicate_recurring(op, action_callback) == TRUE) {
714 return action_async_helper(op);
718 static gboolean processing_blocked_ops = FALSE;
726 for (gIter =
inflight_ops; gIter != NULL; gIter = gIter->next) {
739 GList *executed_ops = NULL;
742 gboolean res = FALSE;
744 if (processing_blocked_ops) {
749 processing_blocked_ops = TRUE;
753 for (gIter =
blocked_ops; gIter != NULL; gIter = gIter->next) {
758 executed_ops = g_list_append(executed_ops, op);
759 res = action_async_helper(op);
768 for (gIter = executed_ops; gIter != NULL; gIter = gIter->next) {
772 g_list_free(executed_ops);
774 processing_blocked_ops = FALSE;
821 #if SUPPORT_HEARTBEAT 823 resources_os_list_hb_agents(
void)
832 GList *standards = NULL;
833 GList *agents = NULL;
835 standards = g_list_append(standards, strdup(
"ocf"));
836 standards = g_list_append(standards, strdup(
"lsb"));
837 standards = g_list_append(standards, strdup(
"service"));
846 standards = g_list_append(standards, strdup(
"systemd"));
847 g_list_free_full(agents, free);
856 standards = g_list_append(standards, strdup(
"upstart"));
857 g_list_free_full(agents, free);
862 standards = g_list_append(standards, strdup(
"nagios"));
863 g_list_free_full(agents, free);
867 #if SUPPORT_HEARTBEAT 868 standards = g_list_append(standards, strdup(
"heartbeat"));
877 if (strcasecmp(standard,
"ocf") == 0) {
887 if (standard == NULL || strcasecmp(standard,
"service") == 0) {
892 if (standard == NULL) {
896 result = g_list_concat(tmp1, tmp2);
903 result = g_list_concat(tmp1, tmp2);
911 result = g_list_concat(tmp1, tmp2);
917 }
else if (strcasecmp(standard,
"ocf") == 0) {
919 }
else if (strcasecmp(standard,
"lsb") == 0) {
921 #if SUPPORT_HEARTBEAT 922 }
else if (strcasecmp(standard,
"heartbeat") == 0) {
923 return resources_os_list_hb_agents();
926 }
else if (strcasecmp(standard,
"systemd") == 0) {
930 }
else if (strcasecmp(standard,
"upstart") == 0) {
934 }
else if (strcasecmp(standard,
"nagios") == 0) {
gboolean services_action_cancel(const char *name, const char *action, int interval)
Cancel a recurring action.
#define CRM_CHECK(expr, failure_action)
void(* callback)(svc_action_t *op)
GList * resources_list_providers(const char *standard)
Get a list of providers.
gboolean upstart_job_exists(const char *name)
gboolean mainloop_child_kill(pid_t pid)
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, enum svc_action_flags flags)
Create a new resource action.
mainloop_io_t * stderr_gsource
GList * resources_os_list_ocf_agents(const char *provider)
GList * resources_os_list_ocf_providers(void)
gboolean recurring_action_timer(gpointer data)
GList * services_os_get_directory_list(const char *root, gboolean files, gboolean executable)
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
gboolean is_op_blocked(const char *rsc)
Wrappers for and extensions to glib mainloop.
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
GList * resources_os_list_lsb_agents(void)
gboolean upstart_job_exec(svc_action_t *op, gboolean synchronous)
enum svc_action_flags flags
gboolean services_os_action_execute(svc_action_t *op, gboolean synchronous)
#define crm_warn(fmt, args...)
GList * services_list(void)
gboolean cancel_recurring_action(svc_action_t *op)
svc_action_private_t * opaque
GList * upstart_job_listall(void)
#define crm_debug(fmt, args...)
gboolean operation_finalize(svc_action_t *op)
gboolean systemd_unit_exists(const char *name)
#define crm_trace(fmt, args...)
gboolean services_action_sync(svc_action_t *op)
#define SUPPORT_HEARTBEAT
gboolean services_action_kick(const char *name, const char *action, int interval)
GList * systemd_unit_listall(void)
const char * resources_find_service_class(const char *agent)
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
void services_add_inflight_op(svc_action_t *op)
GList * resources_list_standards(void)
void services_untrack_op(svc_action_t *op)
GList * get_directory_list(const char *root, gboolean files, gboolean executable)
Get a list of files or directories in a given path.
#define NAGIOS_PLUGIN_DIR
#define crm_err(fmt, args...)
GList * resources_os_list_nagios_agents(void)
GHashTable * recurring_actions
mainloop_io_t * stdout_gsource
#define XML_ATTR_CRM_VERSION
void mainloop_del_fd(mainloop_io_t *client)
void services_action_cleanup(svc_action_t *op)
char * generate_op_key(const char *rsc_id, const char *op_type, int interval)
#define safe_str_eq(a, b)
void handle_blocked_ops(void)
void services_action_free(svc_action_t *op)
gboolean systemd_unit_exec(svc_action_t *op)
#define crm_info(fmt, args...)
svc_action_t * services_action_create(const char *name, const char *action, int interval, int timeout)