The ElectPrimaryPolicy acts to keep exactly one of its children or members as primary, promoting and demoting them when required.
A simple use case is where we have two children, call them North and South, and we wish for North to be primary. If North fails, however, we want to promote and fail over to South. This can be done by:
- adding this policy at the parent
- setting ` ha.primary.weight` on North
- optionally defining `promote` on North and South (if action is required there to promote it)
- observing the `primary` sensor to see which is primary
- optionally setting `propagate.primary.sensors: [ main.uri ]` to publish `main.uri` from whichever of North or South is active
- optionally setting `primary.selection.mode: best` to switch back to North if it comes back online
The policy works by listening for service-up changes in the target pool (children or members) and listening for `ha.primary.weight` sensor values from those elements.
On any change, it invokes an effector to perform the primary election.
By default, the effector invoked is `electPrimary`, but this can be changed with the `primary.election.effector` config key. If this effector does not exist, the policy will add a default behaviour using `ElectPrimaryEffector`. Details of the election are described in that effector, but to summarize, it will find an appropriate primary from the target pool and publish a sensor indicating who the new primary is.
If the effector is not defined this policy will add one with the standard election behaviour
(
ElectPrimaryEffector
).
That effector will also invoke `promote` and `demote` on the relevant entities.
All the `primary.*` parameters accepted by that effector can be defined on this policy
and will be passed to the effector, along with an `event` parameter indicating the sensor which triggered the election.
If no quorum.up or quorum.running is set on the entity, both will be set to a constant 1.