ns_atsignal - Server callbacks
These commands provide hooks for you to register your own procedures to be called during the different stages of the server processes lifetime.
You can find out which callbacks are already registered with the ns_info callbacks command. Further callbacks can be registered via ns_ictl trace.
Pre-startup procs are called in FIFO order after the configuration file has been parsed and all modules loaded, but before the driver starts listening for and processing connections.
Startup procs are called in FIFO order just after the server is fully initialized and is listening for and processing connections.
Signal procs are called in FIFO order whenever a HUP signal is received by the server process.
The following example shows how to log the accumulated cache statistics and reset whenever the server is signaled.
ns_atsignal { foreach cache [ns_cache_names] { ns_log notice "cache\[$cache\]: [ns_cache_stats -reset -- $cache]" } }
At-shutdown procs are called in LIFO order when the server performs a controlled shutdown after all other subsystem have been stopped.
Orderly shutdown is attempted within shutdowntimeout, as specified in the configuration file. Tcl shutdown procs are called before C shutdown tasks are waited on, so should be well-behaved.
Do not attempt to use other subsystems for shutdown jobs, such as the ns_job command.
At-exit procs are called in LIFO order after all shutdown procs have been called and the server process is ready to exit. The atexit procs are basically the last code to run.