Versions Compared

Key

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

...

Default Event Handlers present in Utopia

Each service has three default events that it should handle:
${SERVICE_NAME}-start
${SERVICE_NAME}-stop
${SERVICE_NAME}-restart


For each case following functionality is implemented:

  1. Clear the service's errinfo
  2. Set the service's status
  3. Do the work (Actual Functionality)
  4. Check the error code (check_err will set service's status and service's errinfo upon error)
  5. If no error then set the service's status

Registration of Event Handlers with SYSEVENT

Sysevent is the utility that will activate respective handlers upon events. It provides quite a bit of flexibility to how events are triggered, and how handlers are run. This flexibility is controlled by activation flags (describing how to run the handler), and tuple flags (describing how to interpret events). The default is to trigger an event only when the tuple value changes and to serialise the activation of each unique handler.

When an event is triggered, the handler will be called with a parameter specifying the name of the event. It is also possible to specify additional parameters to be passed to a handler. The parameters may be constants, and/or run-time values of syscfg, and/or run-time values of sysevent.

The following example demonstrate the range of behaviours:

Name of a handler to be activated upon some event:

HANDLER="/etc/utopia/service.d/new_service_handler.sh”

Register for $HANDLER to be activated whenever <event_name> changes value. Ensure that if multiple value changes occur, then only one instance of $HANDLER will be run at a time.

sysevent async event_name $HANDLER

Register for $HANDLER to be activated whenever any value is SET for <event_name>

sysevent async event_name $HANDLER
sysevent setoptions event_name $TUPLE_FLAG_EVENT

Register for $HANDLER to be activated whenever <event_name> changes value. If multiple value changes occur, do NOT enforce that only one instance of $HANDLER will be run at a time.

sysevent async_with_flags $ACTION_FLAG_NOT_THREADSAFE event_name $HANDLER

Register for $HANDLER to be activated whenever <event_name> changes and pass the parameter "new_param" as the second parameter in the activation of the handler

sysevent async event_name $HANDLER new_param

Unregistering

The calls to sysevent async or sysevent async_with_flags will return an async id. The async id can be used to cancel notifications.
Example:

asyncid=`sysevent async event_name $HANDLER`;
sysevent set event_name_asyncid_1 $asyncid

and later

sysevent rm_async `sysevent get event_name_asyncid_1`