InstallShutdownHandlers Method
Installs the operating system handlers that translate an external stop request into the notification awaited by WaitForShutdown.
Remarks
On POSIX, SIGTERM and SIGINT are trapped; the previous dispositions are saved and restored when the unit is finalized. On Windows, a console control handler is installed, covering Ctrl+C, Ctrl+Break and the console close button. Logoff and system shutdown are handled as well, although the system sends those two to services only -- an interactive console application is terminated before they are delivered. A process hosted by the Service Control Manager is a different contract and is out of scope for this unit.
Call this before starting the server. Until the handlers are in place the default disposition applies and a stop request terminates the process on the spot -- a window that matters precisely when startup is slow, or when a deployment tool stops a process it has just started.
Installation is all or nothing: if the second handler cannot be installed, the first is rolled back before the exception is raised.
Repeated calls from the initialization thread are harmless; the extra calls do nothing. Concurrent calls from several threads are not supported -- this manipulates process-global state and is not worth a lock, given that it belongs in startup code.
An exception EOSError is raised if the handlers could not be installed. Treat this as fatal: the process would otherwise die abruptly on the first stop request.
Syntax
Unit: Sparkle.Host.Shutdown
procedure InstallShutdownHandlers;