Restarting a resource can be a complex affair if there are things that depend on that resource or if any of the operations might take a long time.

Stopping a resource is easy, but it can be hard for scripts to determine at what point the the target resource has stopped (in order to know when to re-enable it), at what point it is appropriate to give up, and even what resources might have prevented the stop or start phase from completing.

For this reason, I am pleased to report that we will be introducing a --restart option for crm_resource in Pacemaker 1.1.13.

How it works

Assuming the following invocation

crm_resource --restart --resource dummy

The tool will:

Check the current state of the cluster

Set the target-role for dummy to stopped

Calculate the future state of the cluster

Compare the current state to the future state

Work out the list of resources that still need to stop

If there are resources to be stopped

Work out the longest timeout of all stopping resource

Look for changes until the timeout

If nothing changed, indicate which resources failed to stop and exit

Go back to step 4.

Now that everything has stopped, remove the target-role setting for dummy to allow it to start again

Calculate the future state of the cluster

Compare the current state to the future state

Work out the list of resources that still need to stop

If there are resources to be stopped

Work out the longest timeout of all stopping resource

Look for changes until the timeout

If nothing changed, indicate which resources failed to start and exit

Go back to step 9.

Done

Considering Clones

crm_resource is also smart enough to restart clone instances running on specific nodes with the optional --node hostname argument. In this scenario instead of setting target-role (which would take down the entire clone), we use the same logic as crm_resource --ban and crm_resource --clear to enable/disable the clone from running on the named host.