restreamer: Implement graceful stop on SIGTERM

pull/15/head
Mike Lang 6 years ago committed by Mike Lang
parent 7ffa90c7e6
commit afe19ca33e

@ -3,9 +3,12 @@ import datetime
import errno import errno
import functools import functools
import json import json
import logging
import os import os
import signal
import dateutil.parser import dateutil.parser
import gevent
from flask import Flask, url_for, request, abort from flask import Flask, url_for, request, abort
from gevent.pywsgi import WSGIServer 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='.'): def main(host='0.0.0.0', port=8000, base_dir='.'):
app.static_folder = base_dir app.static_folder = base_dir
server = WSGIServer((host, port), app) 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() server.serve_forever()
logging.info("Gracefully shut down")

Loading…
Cancel
Save