certwrangler.daemon module#

class certwrangler.daemon.ThreadWithContext(group: None = None, target: Callable[[...], object] | None = None, name: str | None = None, args: Iterable[Any] = [], kwargs: Mapping[str, Any] | None = None, *, daemon: bool | None = None)[source]#

Bases: Thread

Base thread class for certwrangler. Takes the same args and works like threading.Thread, but adds support for the click context and adds support to handle graceful stop events for normal threads and threads that are running a coroutine.

Subclasses should define their thread logic under the _run() method instead of run(). _run() can either be a normal method or a coroutine. For a normal method, the thread should support gracefully stopping when the self.graceful_stop_event threading.Event is set. For coroutines the thread should support gracefully stopping when the self.async_graceful_stop_event asyncio.Event is set.

run() None[source]#

Runs _run() within the click context. If _run() is a coroutine this also takes care of setting up an asyncio event loop to run it in.

graceful_stop() None[source]#

Sets self.graceful_stop_event and self.async_graceful_stop_event to trigger a graceful stop.

class certwrangler.daemon.WebServerThread(group: None = None, target: Callable[[...], object] | None = None, name: str | None = None, args: Iterable[Any] = [], kwargs: Mapping[str, Any] | None = None, *, daemon: bool | None = None)[source]#

Bases: ThreadWithContext

Thread that runs the webserver.

async _run() None[source]#
class certwrangler.daemon.ReconcilerThread(group: None = None, target: Callable[[...], object] | None = None, name: str | None = None, args: Iterable[Any] = [], kwargs: Mapping[str, Any] | None = None, *, daemon: bool | None = None)[source]#

Bases: ThreadWithContext

Thread that runs the reconciler loop. This thread will run the reconciler by the interval defined under the reconciler configuration.

_run() None[source]#
class certwrangler.daemon.Daemon[source]#

Bases: object

The thread manager class for certwrangler. It is responsible for the lifecycle of the threads, including starting, stopping, and handling reloads.

_create_threads() None[source]#

Creates the threads.

Raises:

DaemonError – Raised if any threads already exist.

_start_threads() None[source]#

Starts the threads.

_stop_threads() None[source]#

Stops the threads by issuing ThreadWithContext.graceful_stop() to each thread. Does not return until all threads are stopped.

_reload_handler(signal_number: int, _frame: FrameType | None) None[source]#

Handles processing a reload of the config on SIGHUP. This will gracefully stop the threads, reload and re-initialize the config, then start the threads back up.

_stop_handler(signal_number: int, _frame: FrameType | None) None[source]#

Handles processing stopping the threads on SIGTERM and SIGINT. This will first attempt to gracefully stop the threads, then forcefully exits if it catches a second SIGTERM or SIGINT.

run() None[source]#

Runs the daemon. This loads and initializes the config, starts the threads, sets up the signal handlers for graceful stop and reload, and sets up a watchdog on the threads to raise an exception if one of the threads die unexpectedly.

The watchdog interval can be set under the daemon section in the config.

Raises:

DaemonError – Raised if any of the threads die unexpectedly.