Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There are a number of ways to launch an event across multiple hosts. The most obvious are:

  1. create Create multiple events, one for each host.
  2. create Create a template, create multiple symlinks to the template.

In this example, we will show how to use a single event to do the same.

...

  • HOSTS holds the list of machines to launch on.
  • HOSTS splits as ["", "mach1", "mach2", "mach3"].
  • #HCRON_SELF_CHAIN starts at 1, skipping the empty entry in HOSTS.
  • both Both next_event and failover_event call the event itself ($HCRON_EVENT_NAME[-1]).
  • the The "loop" ends when #HCRON_SELF_CHAIN is greater than the number of hosts in HOSTS.

Multi Event with Failover Support

...

  • HOSTS splits as ["", "mach1", "", "mach2", "", "mach3"].
  • next_event calls a "dummy" event which only serves to increase $HCRON_SELF_CHAIN.
  • regardless Regardless of whether the next_event or failover_event is called, the $HCRON_SELF_CHAIN gets updated and the #HCRON_SELF_CHAIN will be 1, 3, 5, ...
Code Block
languagetext
titlemultihost-null
as_user=
host=localhost
command=/bin/true
notify_email=
notify_message=
when_year=2000
when_month=*
when_day=*
when_hour=*
when_minute=*
when_dow=*
next_event=$HCRON_EVENT_NAME[-1]
failover_event=$HCRON_EVENT_NAME[-1]

Notes:

  • serves Serves as a "dummy" event.
  • when_year=2000 ensures it is never scheduled, even if it is not ignored.
  • $HCRON_SELF_CHAIN updated with event name.
  • guarantees Guarantees to call the original event no matter how it is called.
Code Block
languagetext
titlemultihost-fail
as_user=
host=localhost
command=/bin/true
notify_email=<emailaddr>
notify_message=<message>
when_year=2000
when_month=*
when_day=*
when_hour=*
when_minute=*
when_dow=*
next_event=$HCRON_EVENT_NAME[-1]
failover_event=$HCRON_EVENT_NAME[-1]

Notes:

  • some Some command or email notification can be set up to send alert.
  • when_year=2000 ensures it is never scheduled, even if it is not ignored.
  • $HCRON_SELF_CHAIN updated with event name.
  • guarantees Guarantees to call the original event ($HCRON_EVENT_NAME[-1]) no matter how it is called.

Conclusion

In some situations, we may not want to create separate events for each host we want to launch on. These methods provide alternatives using event chaining and indexing. In effect, given a :-separated list of hosts (e.g., HOSTS) and specially configured next_event and failover_events settings, we can select a host to launch on using #HCRON_SELF_CHAIN as an index to iterate over the host list.