When an event fails to be launched, hcron can trigger an event if it is listed in the
failover_event field. Failover events are typically not intended to be run in general, although they can.
In the examples below, we will see how such events can be organized and used.
We first need an event that will be guaranteed to fail:
- This event should always fail because connecting to
thishostdoesnotexistshould never succeed.
- hcron will attempt to run this event every minute.
- When it fails, hcron will try to run
Next, we provide the failover event:
- Run the event on the localhost (change the
hostor make sure that localhost is allowed to run hcron events).
- Sends email notification to address at
- Email notification message indicates failure and identifies the failed event (
template_nameis set so that hcron ignores/rejects the event and does not try to run it.
Reload the events and wait:
Check the status of the events:
The events should be marked as:
The notification email body will look like:
A Common Failover Event
Instead of defining multiple failover events, a common failover event could be defined for all other events to reference. It could be defined at
template_nameis updated to
commonto make sure it is treated as a template.
commandfields are left empty
- An empty
commandis allowed with hcron v1.
- Only the notification will be done.
And all regular events would contain:
Targetted Failover Events
When a lot of events are defined, it may not be appropriate to use a single, common failover event. E.g., a common failover can only notify one email address via the
notify_email field. Perhaps failures should be reported to different individuals/groups depending on the failed event. To support this, we can create multiple failover events. But, this would mean managing multiple event files. So, instead, we will create a template and symlinks to identify the various email recipients.
The template is very familiar:
- The event name is
template_namefield is set to
email_target_templateso that it is treated as a template.
notify_emailfield is set to
$HCRON_EVENT_NAME[-1]which is the name of the event.
commandfields are empty.
So, for each target we want to support, we create symlinks:
Then, in the various regular event files, we use:
and so on.
There are many different ways to set up failover events. The level of complexity depends on the need. But being able to set up failover events with such flexibility and then have them be triggered as needed makes for a documentable and traceable way to manage a large number of relationships easily.