Skip to main content

Health Check Wrap

@readwithai - X - blog - machine-aided reading - 📖⚡️🖋️

Wrap a daemon in a periodic health check. Terminate the process and exit if the health check fails allowing your service manager like systemd to restart your process.

Motivation

I am using a service manager (specifically circusd) to manage some processes. One of these processes is intermittently breaking but the error is rare and in code that I did not write myself. I therefore want to periodically run a health check to see if my service is working and then restart the process if it is not.

However, I dislike the code of my application communicating with my service manager. It feels like it breaks a layer of abstraction, does not allow me to switch out the service manager, and in theory allows one part of the system to restart all processes. Instead, I want to combine the health check with command to run the service and restart the service when the health check dies.

Usage

To monitor 'service' and terminate it and exit when 'check1' completes with a non-zero exit code you can use the following command:

health-check-wrap --service service --health-check check1

This runs a health check every minute. Normally, you would run this command from a service manager such as systemd, supervisor or circusd which would then restart health-check-wrap and so the service.

You can use quotes to specify a full command with arguments to run:

You can run multiple health check commands using repeated --health-check arguments.

You can use the --interval argument to change how often a command runs.

Caveats

This is very much written with the single-server set up in mind. This is useful for home servers, single board (raspberry pi) projects, and any project that does not yet have users paying you money. Other tools provide tools for distributing services across machines together with health check functionality such as kubernetes but these are too heavy weight for many projects.

Alternatives and prior work

It may be better to merely fix the bug. This sort of layering can add complexity and it can be far simpler to have something work consistently rather than try to fix the results of it not working.

The general approach of "die if something breaks" is influenced by Erlang's concept of a supervision tree.

I produce a stream of command-line tools like this which you may be interested in.

Most similar to this is killable sudo which allows you to run processes as another user, such as root, with sudo but kill the process with SIGTERM. Many service managers kill processes with SIGTERM.

env subset is a tool to help you control the environment uses to run a process. This is useful for debugging.

About me

I am @readwithai. I create tools for reading, research and agency sometimes using the markdown editor Obsidian.

I also create a stream of tools that are related to carrying out my work.

I write about lots of things - including tools like this - on X. My blog is more about reading and research and agency.

Metadata

Release files for health-check-wrap 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for health-check-wrap 1.0.0
File Size Uploaded Provenance Actions
health_check_wrap-1.0.0.tar.gz 6.4 kB Without provenance Details for health_check_wrap-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for health-check-wrap 1.0.0
File Interpreter ABI Platform Actions
health_check_wrap-1.0.0-py3-none-any.whl Python 3 none any Details for health_check_wrap-1.0.0-py3-none-any.whl

Total release size: 13.4 kB

Release files / health_check_wrap-1.0.0.tar.gz

Download URL health_check_wrap-1.0.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5b2250fa484e221474104983cb6a47777e76c56bc821ee946d50fa2dfd7958d0
BLAKE2b-256 checksum
How to use checksums
3dd320a13a6ce029fea48cbb11e289b87547bf0736e141c47c309b8a4d016e61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / health_check_wrap-1.0.0-py3-none-any.whl

Download URL health_check_wrap-1.0.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
052cec85f85b6ca9ffd9fa8b0ad4219599d22ca53764830f13d021f1a1482a59
BLAKE2b-256 checksum
How to use checksums
4811047c970510d3c2a46bad696193c70b884c7872f22291858331fe84ee02be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Security for health-check-wrap 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page