Skip to content

Instantly share code, notes, and snippets.

@darrenboyd
Created September 10, 2020 19:35
Show Gist options
  • Save darrenboyd/c0022f95d679294184cb6632dc6da2e3 to your computer and use it in GitHub Desktop.
Save darrenboyd/c0022f95d679294184cb6632dc6da2e3 to your computer and use it in GitHub Desktop.
Simple Docker Pythong Server
FROM python:3.8
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
WORKDIR /app
COPY server.py .
# Ingored, for now
# HEALTHCHECK CMD find health_check || exit 1
CMD [ "python", "server.py" ]
"""Main startup script to run Loeding"""
import os
import sys
import signal
import time
from datetime import datetime
RUNNING = True
def main(given_args):
counter = 0
while RUNNING:
if counter % 60 == 0:
for key in sorted(os.environ.keys()):
print(f"{key} => {os.environ[key]}")
counter += 1
time.sleep(1)
shut_down()
def shut_down():
print("Shutting down")
def _handle_shutdown(signum, _):
global RUNNING
print(f"Handling signal: {signum}")
RUNNING = False
if __name__ == "__main__":
signal.signal(signal.SIGTERM, _handle_shutdown)
signal.signal(signal.SIGINT, _handle_shutdown)
print(f"Starting with PID: {os.getpid()}")
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment