pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
Macros | Functions
services.c File Reference
#include <crm_internal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <crm/crm.h>
#include <crm/common/mainloop.h>
#include <crm/services.h>
#include <crm/services_internal.h>
#include <crm/stonith-ng.h>
#include <crm/common/xml.h>
#include "services_private.h"
#include "services_ocf.h"
#include "services_lsb.h"
Include dependency graph for services.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

const char * resources_find_service_class (const char *agent)
 Find first service class that can provide a specified agent. More...
 
svc_action_tservices__create_resource_action (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)
 Create a new resource action. More...
 
svc_action_tresources_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)
 Create a new resource action. More...
 
svc_action_tservices_action_create_generic (const char *exec, const char *args[])
 Request execution of an arbitrary command. More...
 
svc_action_tservices_alert_create (const char *id, const char *exec, int timeout, GHashTable *params, int sequence, void *cb_data)
 Create an alert agent action. More...
 
int services_action_user (svc_action_t *op, const char *user)
 Set the user and group that an action will execute as. More...
 
gboolean services_alert_async (svc_action_t *action, void(*cb)(svc_action_t *op))
 Execute an alert agent action. More...
 
void services_action_cleanup (svc_action_t *op)
 
enum ocf_exitcode services_result2ocf (const char *standard, const char *action, int exit_status)
 
void services_action_free (svc_action_t *op)
 
gboolean cancel_recurring_action (svc_action_t *op)
 
gboolean services_action_cancel (const char *name, const char *action, guint interval_ms)
 Cancel a recurring action. More...
 
gboolean services_action_kick (const char *name, const char *action, guint interval_ms)
 Reschedule a recurring action for immediate execution. More...
 
void services_add_inflight_op (svc_action_t *op)
 
void services_untrack_op (const 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 *))
 Run an action asynchronously, with callback after process is forked. More...
 
gboolean services_action_async (svc_action_t *op, void(*action_callback)(svc_action_t *))
 Request asynchronous execution of an action. More...
 
gboolean is_op_blocked (const char *rsc)
 
gboolean services_action_sync (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. More...
 
GList * resources_list_standards (void)
 
GList * resources_list_providers (const char *standard)
 Get a list of providers. More...
 
GList * resources_list_agents (const char *standard, const char *provider)
 Get a list of resource agents. More...
 
gboolean resources_agent_exists (const char *standard, const char *provider, const char *agent)
 Check whether a resource agent exists on the local host. More...
 
void services__set_result (svc_action_t *action, int agent_status, enum pcmk_exec_status exec_status, const char *reason)
 
void services__format_result (svc_action_t *action, int agent_status, enum pcmk_exec_status exec_status, const char *format,...)
 
void services__set_cancelled (svc_action_t *action)
 
const char * services__action_kind (const svc_action_t *action)
 
const char * services__exit_reason (const svc_action_t *action)
 
char * services__grab_stdout (svc_action_t *action)
 
char * services__grab_stderr (svc_action_t *action)
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 13 of file services.c.

Function Documentation

◆ cancel_recurring_action()

gboolean cancel_recurring_action ( svc_action_t op)

Definition at line 636 of file services.c.

◆ get_directory_list()

GList* get_directory_list ( const char *  root,
gboolean  files,
gboolean  executable 
)

Get a list of files or directories in a given path.

Parameters
[in]rootFull path to a directory to read
[in]filesReturn list of files if TRUE or directories if FALSE
[in]executableIf TRUE and files is TRUE, only return executable files
Returns
List of what was found as char * items.
Note
The caller is responsibile for freeing the result with g_list_free_full(list, free).

Definition at line 1053 of file services.c.

◆ is_op_blocked()

gboolean is_op_blocked ( const char *  rsc)

Definition at line 908 of file services.c.

◆ resources_action_create()

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 
)

Create a new resource action.

Parameters
[in]nameName of resource that action is for
[in]standardResource agent standard
[in]providerResource agent provider
[in]agentResource agent name
[in]actionName of action to create
[in]interval_msHow often to repeat action (if 0, execute once)
[in]timeoutError if not complete within this time (ms)
[in,out]paramsAction parameters
[in]flagsGroup of enum svc_action_flags
Returns
Newly allocated action
Note
This function assumes ownership of (and may free) params.
The caller is responsible for freeing the return value using services_action_free().

Definition at line 335 of file services.c.

◆ resources_agent_exists()

gboolean resources_agent_exists ( const char *  standard,
const char *  provider,
const char *  agent 
)

Check whether a resource agent exists on the local host.

Parameters
[in]standardResource agent standard of agent to check
[in]providerProvider of agent to check (or NULL)
[in]agentName of agent to check
Returns
TRUE if agent exists locally, otherwise FALSE

Definition at line 1173 of file services.c.

◆ resources_find_service_class()

const char* resources_find_service_class ( const char *  agent)

Find first service class that can provide a specified agent.

Parameters
[in]agentName of agent to search for
Returns
Service class if found, NULL otherwise
Note
The priority is LSB, then systemd, then upstart. It would be preferable to put systemd first, but LSB merely requires a file existence check, while systemd requires contacting D-Bus.

Definition at line 72 of file services.c.

◆ resources_list_agents()

GList* resources_list_agents ( const char *  standard,
const char *  provider 
)

Get a list of resource agents.

Parameters
[in]standardList agents of this standard (or NULL for all)
[in]providerList agents of this provider (or NULL for all)
Returns
List of resource agents as char * items.
Note
The caller is responsible for freeing the result using g_list_free_full(list, free).

Definition at line 1117 of file services.c.

◆ resources_list_providers()

GList* resources_list_providers ( const char *  standard)

Get a list of providers.

Parameters
[in]standardList providers of this resource agent standard
Returns
List of providers as char * list items (or NULL if standard does not support providers)
Note
The caller is responsible for freeing the result using g_list_free_full(list, free).

Definition at line 1107 of file services.c.

◆ resources_list_standards()

GList* resources_list_standards ( void  )

Get list of available standards

Returns
List of resource standards as char * items.
Note
The caller is responsible for freeing the result using g_list_free_full(list, free).

Definition at line 1059 of file services.c.

◆ services__action_kind()

const char* services__action_kind ( const svc_action_t action)

Definition at line 1350 of file services.c.

◆ services__create_resource_action()

svc_action_t* services__create_resource_action ( 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 
)

Create a new resource action.

Parameters
[in]nameName of resource
[in]standardResource agent standard
[in]providerResource agent provider
[in]agentResource agent name
[in]actionName of action
[in]interval_msHow often to repeat action (if 0, execute once)
[in]timeoutError if not complete within this time (ms)
[in,out]paramsAction parameters
[in]flagsGroup of enum svc_action_flags
Returns
NULL if not enough memory, otherwise newly allocated action instance (if its rc member is not PCMK_OCF_UNKNOWN, the action is invalid)
Note
This function assumes ownership of (and may free) params.
The caller is responsible for freeing the return value using services_action_free().

Definition at line 254 of file services.c.

◆ services__exit_reason()

const char* services__exit_reason ( const svc_action_t action)

Definition at line 1374 of file services.c.

◆ services__format_result()

void services__format_result ( svc_action_t action,
int  agent_status,
enum pcmk_exec_status  exec_status,
const char *  format,
  ... 
)

Definition at line 1298 of file services.c.

◆ services__grab_stderr()

char* services__grab_stderr ( svc_action_t action)

Definition at line 1409 of file services.c.

◆ services__grab_stdout()

char* services__grab_stdout ( svc_action_t action)

Definition at line 1390 of file services.c.

◆ services__set_cancelled()

void services__set_cancelled ( svc_action_t action)

Definition at line 1332 of file services.c.

◆ services__set_result()

void services__set_result ( svc_action_t action,
int  agent_status,
enum pcmk_exec_status  exec_status,
const char *  reason 
)

Definition at line 1269 of file services.c.

◆ services_action_async()

gboolean services_action_async ( svc_action_t op,
void(*)(svc_action_t *)  action_callback 
)

Request asynchronous execution of an action.

Parameters
[in,out]opAction to execute
[in]action_callbackFunction to call when the action completes (if NULL, any previously set callback will continue to be used)
Return values
TRUEif the caller should not free or otherwise use op again, because one of these conditions is true:
  • op is NULL.
  • The action was successfully initiated, in which case action_callback has not been called (it will be called when the action completes).
  • The action's ID matched an existing recurring action. The existing action has taken over the callback and callback data from op and has been re-initiated asynchronously, and op has been freed.
  • Another action for the same resource is in flight, and op will be blocked until it completes.
  • The action could not be initiated, and is either non-recurring or being cancelled. action_callback has been called, and op has been freed.
Return values
FALSEif is still valid, because the action cannot be initiated, and is a recurring action that is not being cancelled. action_callback has been called, and a timer has been set for the next invocation of op.

Definition at line 899 of file services.c.

◆ services_action_async_fork_notify()

gboolean services_action_async_fork_notify ( svc_action_t op,
void(*)(svc_action_t *)  action_callback,
void(*)(svc_action_t *)  action_fork_callback 
)

Run an action asynchronously, with callback after process is forked.

Parameters
[in,out]opAction to run
[in]action_callbackFunction to call when action completes (if NULL, any previously set callback will continue to be used)
[in]action_fork_callbackFunction to call after child process is forked for action (if NULL, any previously set callback will continue to be used)
Return values
TRUEif the caller should not free or otherwise use op again, because one of these conditions is true:
  • op is NULL.
  • The action was successfully initiated, in which case action_fork_callback has been called, but action_callback has not (it will be called when the action completes).
  • The action's ID matched an existing recurring action. The existing action has taken over the callback and callback data from op and has been re-initiated asynchronously, and op has been freed.
  • Another action for the same resource is in flight, and op will be blocked until it completes.
  • The action could not be initiated, and is either non-recurring or being cancelled. action_fork_callback has not been called, but action_callback has, and op has been freed.
Return values
FALSEif is still valid, because the action cannot be initiated, and is a recurring action that is not being cancelled. action_fork_callback has not been called, but action_callback has, and a timer has been set for the next invocation of op.

Definition at line 865 of file services.c.

◆ services_action_cancel()

gboolean services_action_cancel ( const char *  name,
const char *  action,
guint  interval_ms 
)

Cancel a recurring action.

Parameters
[in]nameName of resource that operation is for
[in]actionName of operation to cancel
[in]interval_msInterval of operation to cancel
Returns
TRUE if action was successfully cancelled, FALSE otherwise

Definition at line 662 of file services.c.

◆ services_action_cleanup()

void services_action_cleanup ( svc_action_t op)

Definition at line 499 of file services.c.

◆ services_action_create_generic()

svc_action_t* services_action_create_generic ( const char *  exec,
const char *  args[] 
)

Request execution of an arbitrary command.

This API has useful infrastructure in place to be able to run a command in the background and get notified via a callback when the command finishes.

Parameters
[in]execFull path to command executable
[in]argsNULL-terminated list of arguments to pass to command
Returns
Newly allocated action object

Definition at line 356 of file services.c.

◆ services_action_free()

void services_action_free ( svc_action_t op)

Definition at line 583 of file services.c.

◆ services_action_kick()

gboolean services_action_kick ( const char *  name,
const char *  action,
guint  interval_ms 
)

Reschedule a recurring action for immediate execution.

Parameters
[in]nameName of resource that action is for
[in]actionAction's name
[in]interval_msAction's interval (in milliseconds)
Returns
TRUE on success, otherwise FALSE

Definition at line 730 of file services.c.

◆ services_action_sync()

gboolean services_action_sync ( svc_action_t op)

Definition at line 1018 of file services.c.

◆ services_action_user()

int services_action_user ( svc_action_t op,
const char *  user 
)

Set the user and group that an action will execute as.

Parameters
[in,out]opAction to modify
[in]userName of user to execute action as
[in]groupName of group to execute action as
Returns
pcmk_ok on success, -errno otherwise
Note
This will have no effect unless the process executing the action runs as root, and the action is not a systemd or upstart action. We could implement this for systemd by adding User= and Group= to [Service] in the override file, but that seems more likely to cause problems than be useful.

Definition at line 443 of file services.c.

◆ services_add_inflight_op()

void services_add_inflight_op ( svc_action_t op)

Definition at line 833 of file services.c.

◆ services_alert_async()

gboolean services_alert_async ( svc_action_t action,
void(*)(svc_action_t *op)  cb 
)

Execute an alert agent action.

Parameters
[in,out]actionAction to execute
[in]cbFunction to call when action completes
Returns
TRUE if the library will free action, FALSE otherwise
Note
If this function returns FALSE, it is the caller's responsibility to free the action with services_action_free(). However, unless someone intentionally creates a recurring alert action, this will never return FALSE.

Definition at line 463 of file services.c.

◆ services_alert_create()

svc_action_t* services_alert_create ( const char *  id,
const char *  exec,
int  timeout,
GHashTable *  params,
int  sequence,
void *  cb_data 
)

Create an alert agent action.

Parameters
[in]idAlert ID
[in]execPath to alert agent executable
[in]timeoutAction timeout
[in]paramsParameters to use with action
[in]sequenceAction sequence number
[in]cb_dataData to pass to callback function
Returns
New action on success, NULL on error
Note
It is the caller's responsibility to free cb_data. The caller should not free params explicitly.

Definition at line 413 of file services.c.

◆ services_result2ocf()

enum ocf_exitcode services_result2ocf ( const char *  standard,
const char *  action,
int  exit_status 
)

Definition at line 548 of file services.c.

◆ services_untrack_op()

void services_untrack_op ( const svc_action_t op)

Definition at line 854 of file services.c.