Skip to main content

A lightweight process supervisor that restarts a service if health checks fail.

Project description

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.

Related tools

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

health_check_wrap-1.0.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

health_check_wrap-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file health_check_wrap-1.0.0.tar.gz.

File metadata

  • Download URL: health_check_wrap-1.0.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for health_check_wrap-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5b2250fa484e221474104983cb6a47777e76c56bc821ee946d50fa2dfd7958d0
MD5 11f02cad9da7cbf9b6e5129b38d8f43a
BLAKE2b-256 3dd320a13a6ce029fea48cbb11e289b87547bf0736e141c47c309b8a4d016e61

See more details on using hashes here.

File details

Details for the file health_check_wrap-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for health_check_wrap-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 052cec85f85b6ca9ffd9fa8b0ad4219599d22ca53764830f13d021f1a1482a59
MD5 8071a79bfdfe2cc5b383826598ae2c33
BLAKE2b-256 4811047c970510d3c2a46bad696193c70b884c7872f22291858331fe84ee02be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page