25 #include <sys/types.h> 50 static int operations = 0;
80 if (rc > 0 && stat(path, &st) == 0) {
104 const char *agent,
const char *action,
int interval,
int timeout,
114 if (crm_strlen_zero(name)) {
115 crm_err(
"A service or resource action must have a name.");
119 if (crm_strlen_zero(standard)) {
120 crm_err(
"A service action must have a valid standard.");
124 if (!strcasecmp(standard,
"ocf") && crm_strlen_zero(provider)) {
125 crm_err(
"An OCF resource action must have a provider.");
129 if (crm_strlen_zero(agent)) {
130 crm_err(
"A service or resource action must have an agent.");
134 if (crm_strlen_zero(action)) {
135 crm_err(
"A service or resource action must specify an action.");
153 op->
rsc = strdup(name);
154 op->
action = strdup(action);
158 op->
agent = strdup(agent);
162 if (asprintf(&op->
id,
"%s_%s_%d", name, action, interval) == -1) {
166 if (strcasecmp(op->
standard,
"service") == 0) {
182 if (strcasecmp(op->
standard,
"ocf") == 0) {
188 crm_err(
"Internal error: cannot create agent path");
194 }
else if (strcasecmp(op->
standard,
"lsb") == 0) {
195 if (op->
agent[0] ==
'/') {
200 crm_err(
"Internal error: cannot create agent path");
206 #if SUPPORT_HEARTBEAT 207 }
else if (strcasecmp(op->
standard,
"heartbeat") == 0) {
213 if (op->
agent[0] ==
'/') {
217 }
else if (asprintf(&op->
opaque->
exec,
"%s/%s", HB_RA_DIR, op->
agent) == -1) {
218 crm_err(
"Internal error: cannot create agent path");
226 for (index = 1; index <=
MAX_ARGC - 3; index++ ) {
227 snprintf(buf_tmp,
sizeof(buf_tmp),
"%d", index);
228 value_tmp = g_hash_table_lookup(params, buf_tmp);
229 if (value_tmp == NULL) {
234 op->
opaque->
args[param_num++] = strdup(value_tmp);
243 }
else if (strcasecmp(op->
standard,
"systemd") == 0) {
247 }
else if (strcasecmp(op->
standard,
"upstart") == 0) {
250 }
else if (strcasecmp(op->
standard,
"service") == 0) {
257 }
else if (strcasecmp(op->
standard,
"nagios") == 0) {
260 if (op->
agent[0] ==
'/') {
266 crm_err(
"Internal error: cannot create agent path");
275 op->
opaque->
args[index] = strdup(
"--version");
282 static int args_size =
sizeof(op->
opaque->
args) /
sizeof(
char *);
284 g_hash_table_iter_init(&iter, params);
286 while (g_hash_table_iter_next(&iter, (gpointer *) & key, (gpointer *) & value) &&
287 index <= args_size - 3) {
289 char *long_opt = NULL;
296 long_opt = calloc(1, len);
297 sprintf(long_opt,
"--%s", key);
298 long_opt[len - 1] = 0;
315 g_hash_table_destroy(params);
321 g_hash_table_destroy(params);
332 unsigned int cur_arg;
334 op = calloc(1,
sizeof(*op));
340 for (cur_arg = 1; args && args[cur_arg - 1]; cur_arg++) {
341 op->
opaque->
args[cur_arg] = strdup(args[cur_arg - 1]);
344 crm_err(
"svc_action_t args list not long enough for '%s' execution request.", exec);
361 services_set_op_pending(
svc_action_t *op, DBusPendingCall *pending)
363 if (op->
opaque->pending && (op->
opaque->pending != pending)) {
369 dbus_pending_call_unref(op->
opaque->pending);
371 op->
opaque->pending = pending;
373 crm_trace(
"Updated pending %s DBus call (%p)", op->
id, pending);
388 if(op->
opaque->timerid != 0) {
390 g_source_remove(op->
opaque->timerid);
396 if(dbus_pending_call_get_completed(op->
opaque->pending)) {
399 dbus_pending_call_cancel(op->
opaque->pending);
400 dbus_pending_call_unref(op->
opaque->pending);
401 op->
opaque->pending = NULL;
451 g_hash_table_destroy(op->
params);
481 snprintf(
id,
sizeof(
id),
"%s_%s_%d", name, action, interval);
500 crm_info(
"Cancelling in-flight op: performing early termination of %s (pid=%d)",
id, op->
pid);
505 crm_err(
"Termination of %s (pid=%d) failed",
id, op->
pid);
519 if (asprintf(&
id,
"%s_%s_%d", name, action, interval) == -1) {
559 if (dup && (dup != op)) {
621 if (action_callback) {
626 if (handle_duplicate_recurring(op, action_callback) == TRUE) {
639 return action_async_helper(op);
643 static gboolean processing_blocked_ops = FALSE;
651 for (gIter =
inflight_ops; gIter != NULL; gIter = gIter->next) {
664 GList *executed_ops = NULL;
667 gboolean res = FALSE;
669 if (processing_blocked_ops) {
674 processing_blocked_ops = TRUE;
678 for (gIter =
blocked_ops; gIter != NULL; gIter = gIter->next) {
683 executed_ops = g_list_append(executed_ops, op);
684 res = action_async_helper(op);
693 for (gIter = executed_ops; gIter != NULL; gIter = gIter->next) {
697 g_list_free(executed_ops);
699 processing_blocked_ops = FALSE;
746 #if SUPPORT_HEARTBEAT 748 resources_os_list_hb_agents(
void)
757 GList *standards = NULL;
758 GList *agents = NULL;
760 standards = g_list_append(standards, strdup(
"ocf"));
761 standards = g_list_append(standards, strdup(
"lsb"));
762 standards = g_list_append(standards, strdup(
"service"));
771 standards = g_list_append(standards, strdup(
"systemd"));
772 g_list_free_full(agents, free);
781 standards = g_list_append(standards, strdup(
"upstart"));
782 g_list_free_full(agents, free);
787 standards = g_list_append(standards, strdup(
"nagios"));
788 g_list_free_full(agents, free);
792 #if SUPPORT_HEARTBEAT 793 standards = g_list_append(standards, strdup(
"heartbeat"));
802 if (strcasecmp(standard,
"ocf") == 0) {
812 if (standard == NULL || strcasecmp(standard,
"service") == 0) {
817 if (standard == NULL) {
821 result = g_list_concat(tmp1, tmp2);
828 result = g_list_concat(tmp1, tmp2);
836 result = g_list_concat(tmp1, tmp2);
842 }
else if (strcasecmp(standard,
"ocf") == 0) {
844 }
else if (strcasecmp(standard,
"lsb") == 0) {
846 #if SUPPORT_HEARTBEAT 847 }
else if (strcasecmp(standard,
"heartbeat") == 0) {
848 return resources_os_list_hb_agents();
851 }
else if (strcasecmp(standard,
"systemd") == 0) {
855 }
else if (strcasecmp(standard,
"upstart") == 0) {
859 }
else if (strcasecmp(standard,
"nagios") == 0) {
gboolean services_action_cancel(const char *name, const char *action, int interval)
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)
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)
#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)