From afe19ca33e33305b84412d53dbcd4f6b64b5e6fd Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 30 Dec 2018 03:29:26 -0800 Subject: [PATCH] restreamer: Implement graceful stop on SIGTERM --- restreamer/restreamer/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/restreamer/restreamer/main.py b/restreamer/restreamer/main.py index 41adfd0..51e02ad 100644 --- a/restreamer/restreamer/main.py +++ b/restreamer/restreamer/main.py @@ -3,9 +3,12 @@ import datetime import errno import functools import json +import logging import os +import signal import dateutil.parser +import gevent from flask import Flask, url_for, request, abort from gevent.pywsgi import WSGIServer @@ -166,4 +169,12 @@ def generate_media_playlist(stream, variant): def main(host='0.0.0.0', port=8000, base_dir='.'): app.static_folder = base_dir server = WSGIServer((host, port), app) + + def stop(): + logging.info("Shutting down") + server.stop() + gevent.signal(signal.SIGTERM, stop) + + logging.info("Starting up") server.serve_forever() + logging.info("Gracefully shut down")