|
| 1 | + |
| 2 | +Start, Stop and Status Monitoring |
| 3 | +================================= |
| 4 | + |
| 5 | +A typical SHC application consists of multiple parallel activities that need to be initialized and gracefully stopped at shutdown: |
| 6 | +Most *Interfaces* have an internal loop task for interacting with external systems and each of SHC's :ref:`timers <timer>` has an internal loop to wait for the next trigger time. |
| 7 | +In addition, “initializable” *Reading* objects, like SHC :ref:`variables` need to read their initial value during startup. |
| 8 | + |
| 9 | +For this purpose, the :mod:`shc.supervisor` module implements functions for controlling startup and shutdown of SHC applications. |
| 10 | + |
| 11 | +The main entry point of SHC applications, after all objects have been constructed and *connected*, should be the :func:`shc.supervisor.main` function, we already encountered in the examples. |
| 12 | +It performs the following startup procedure: |
| 13 | + |
| 14 | +* Register a signal handler to initiate shutdown when receiving a SIGTERM (or similar) |
| 15 | +* Start all interface instances via their :meth:`start() <shc.supervisor.AbstractInterface.start>` coroutine and await their successful startup |
| 16 | +* Trigger initialization of variables via *read* |
| 17 | +* Start timers (incl. :class:`Once <shc.timer.Once>` triggers) |
| 18 | + |
| 19 | +When a shutdown is initiated, all interfaces (and the SHC timers) are stopped by calling and awaiting their :meth:`stop() <shc.supervisor.AbstractInterface.stop>` coroutine. |
| 20 | +The SHC application only quits when all these coroutines have returned successfully. |
| 21 | + |
| 22 | +When an interface fails starting up, it shall raise an exception from its :meth:`start() <shc.supervisor.AbstractInterface.start>` coroutine, which will interrupt the SHC startup process. |
| 23 | + |
| 24 | +When an interface encounters a critical error during operation, after successful startup, it may call :func:`shc.supervisor.interface_failure` to initiate a shutdown. |
| 25 | +In this case, SHC will wait for the remaining interfaces to stop and exit with an non-zero exit code. |
| 26 | + |
| 27 | +Some interfaces, especially client interfaces inheriting from :class:`shc.interfaces._helper.SupervisedClientInterface`, can be configured to automatically retry the external connection on errors, even if an an error is encountered during the initial startup. |
| 28 | +As the SHC application will continue to run in these cases, it's useful to monitor the status of individual interfaces. |
| 29 | + |
| 30 | + |
| 31 | +Monitoring of Interface Status |
| 32 | +------------------------------ |
| 33 | + |
| 34 | +For this purpose, most interfaces, implement a "monitoring connector" (also called "status connector"). |
| 35 | +It is a *Readable* object of value type :class:`shc.supervisor.InterfaceStatus` that be retrieved via the :meth:`monitoring_connector <shc.supervisor.AbstractInterface.monitoring_connector>`. |
| 36 | + |
| 37 | +If an interfaces does not provide monitoring capabilities, this method will raise a :class:`NotImplementedError`. |
| 38 | + |
| 39 | +In many cases, the monitoring connector object is not only *Readable* but also *Subscribable*. |
| 40 | +This can be used to interactively react to interface status changes, e.g. set some variables to an emergency-fallback mode when the :class:`SHC client <shc.interfaces.shc_client.SHCWebClient>` connection to a primary SHC server is lost. |
| 41 | + |
| 42 | +.. autoclass:: shc.supervisor.ServiceStatus |
| 43 | + |
| 44 | +.. autonamedtuple:: shc.supervisor.InterfaceStatus |
| 45 | + |
| 46 | + |
| 47 | +Monitoring via HTTP |
| 48 | +^^^^^^^^^^^^^^^^^^^ |
| 49 | + |
| 50 | +TODO monitoring via HTTP using the WebServer |
| 51 | + |
| 52 | +TODO :meth:`shc.web.interface.WebServer.configure_monitoring` |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +Monitoring Helper classes |
| 58 | +^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 59 | + |
| 60 | +TODO :class:`shc.interfaces.system_monitoring.EventLoopMonitor` |
| 61 | + |
| 62 | + |
0 commit comments