A minimal Python 3 HTTP server that keeps running even when it receives graceful shutdown signals (SIGTERM / SIGINT). Useful for demonstrating long-running containerized processes.
- Python 3
make(optional, for convenience)- Docker (optional, for containerized run)
Run locally:
make runOr without make:
python3 server.pyThe server listens on 0.0.0.0:8080 by default. Change the port with the PORT environment variable:
PORT=9000 python3 server.py| Method | Path | Response |
|---|---|---|
| GET | / |
Hello, World! (text/plain) |
| GET | /health |
{"status":"ok"} (application/json) |
| * | * | 404 Not Found |
make testThis starts the server in the background, verifies both endpoints with curl, and then forcefully terminates the process.
Build and run:
make docker-build
make docker-runStop the container:
make stopThe server registers handlers for SIGTERM and SIGINT. When either signal arrives, the handler logs the signal and returns, allowing the server to continue serving. The process exits only on SIGKILL or an unhandled fatal error.