diff --git a/docker/Dockerfile b/docker/Dockerfile index 2c79e78..db92dd2 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -10,4 +10,6 @@ COPY . . EXPOSE 5000 -CMD ["gunicorn", "--preload", "-w", "4", "-b", "0.0.0.0:5000", "app:app"] +STOPSIGNAL SIGTERM + +CMD ["python", "app.py"] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 9b2af2e..31d51c6 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -5,8 +5,8 @@ services: build: context: ../src dockerfile: ../docker/Dockerfile - ports: - - 5000:5000 + network_mode: host + stop_signal: SIGTERM environment: FLASK_ENV: production volumes: diff --git a/src/.env.dev b/src/.env.dev index 470c0b1..9b5c367 100644 --- a/src/.env.dev +++ b/src/.env.dev @@ -1,6 +1,6 @@ DATABASE=sqlite:///endpoints.db -API_HOST=RoomF7203.local -SERVICE_NAME=RoomF7203 +API_HOST=room7200.local +SERVICE_NAME=room7200 SERVICE_TYPE=_http._tcp.local. SERVICE_IP=192.168.137.1 SERVICE_PORT=5000 \ No newline at end of file diff --git a/src/app.py b/src/app.py index 4f59af9..d38e7a1 100644 --- a/src/app.py +++ b/src/app.py @@ -1,4 +1,8 @@ +import signal +import sys + from flask import Flask, render_template +from waitress import serve from api import api from config import API_HOST, DATABASE_URI @@ -13,6 +17,14 @@ app.register_blueprint(api) init_db(app) +def handle_exit(*args): + unregister_service() + sys.exit(0) + + +signal.signal(signal.SIGTERM, handle_exit) + + @app.route("/") def homepage(): endpoints = get_endpoints_from_db() @@ -23,6 +35,6 @@ if __name__ == "__main__": register_service() try: - app.run(host="0.0.0.0", port=5000) + serve(app, host="0.0.0.0", port=5000) finally: unregister_service()