HTTP health check endpoint using socat

What do you do when you need to expose an HTTP health check endpoint but the thing you’re health checking isn’t a web server? You socat it! Here’s a complete example:

nohup socat TCP-LISTEN:8080,reuseaddr,fork,crnl SYSTEM:"
  supervisorctl status celery | grep -q RUNNING &&
    echo HTTP/1.0 200 OK ||
    echo HTTP/1.0 500 Down
  echo
" &>/dev/null &

In short, the above will run a web server on port 8080 which will respond with HTTP status code of 200 if celery is running, or 500 otherwise. You can replace supervisorctl status celery | grep -q RUNNING with any other command. The exit code of that command determines the web server’s response. Pretty neat ha!