mirror of
https://gitlab.com/RemixDev/deemix-gui-pyweb.git
synced 2024-12-28 18:36:07 +00:00
Use signal handler to ensure queue saved on SIGINT/SIGTERM
This commit is contained in:
parent
e00d908bca
commit
4a55772e03
16
server.py
16
server.py
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import logging
|
import logging
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
from os import path
|
from os import path
|
||||||
|
@ -123,6 +124,14 @@ def check_for_updates():
|
||||||
else:
|
else:
|
||||||
print("You're running the latest version")
|
print("You're running the latest version")
|
||||||
|
|
||||||
|
def shutdown(interface=None):
|
||||||
|
if app is not None:
|
||||||
|
app.shutdown(interface=interface)
|
||||||
|
socketio.stop()
|
||||||
|
|
||||||
|
def shutdown_handler(signalnum, frame):
|
||||||
|
shutdown()
|
||||||
|
|
||||||
@server.route('/')
|
@server.route('/')
|
||||||
def landing():
|
def landing():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
@ -133,8 +142,7 @@ def not_found_handler(e):
|
||||||
|
|
||||||
@server.route('/shutdown')
|
@server.route('/shutdown')
|
||||||
def closing():
|
def closing():
|
||||||
app.shutdown(interface=socket_interface)
|
shutdown(interface=socket_interface)
|
||||||
socketio.stop()
|
|
||||||
return 'Server Closed'
|
return 'Server Closed'
|
||||||
|
|
||||||
serverwide_arl = "--serverwide-arl" in sys.argv
|
serverwide_arl = "--serverwide-arl" in sys.argv
|
||||||
|
@ -399,4 +407,8 @@ if __name__ == '__main__':
|
||||||
portable = path.join(path.dirname(path.realpath(__file__)), 'config')
|
portable = path.join(path.dirname(path.realpath(__file__)), 'config')
|
||||||
if '--host' in sys.argv:
|
if '--host' in sys.argv:
|
||||||
host = str(sys.argv[sys.argv.index("--host")+1])
|
host = str(sys.argv[sys.argv.index("--host")+1])
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, shutdown_handler)
|
||||||
|
signal.signal(signal.SIGTERM, shutdown_handler)
|
||||||
|
|
||||||
run_server(port, host, portable)
|
run_server(port, host, portable)
|
||||||
|
|
Loading…
Reference in a new issue