server restart
Browse files
run.py
CHANGED
|
@@ -1,13 +1,29 @@
|
|
| 1 |
import os
|
| 2 |
from api.app import create_app
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
app = create_app()
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
if __name__ == "__main__":
|
| 7 |
import sys
|
| 8 |
host = os.environ.get("HOST", "0.0.0.0")
|
| 9 |
port = int(os.environ.get("PORT", 5000))
|
| 10 |
debug = os.environ.get("FLASK_DEBUG", "0") == "1"
|
|
|
|
|
|
|
|
|
|
| 11 |
try:
|
| 12 |
app.run(host=host, port=port, debug=debug, use_reloader=False, threaded=True)
|
| 13 |
except KeyboardInterrupt:
|
|
|
|
| 1 |
import os
|
| 2 |
from api.app import create_app
|
| 3 |
|
| 4 |
+
import threading
|
| 5 |
+
import signal
|
| 6 |
+
|
| 7 |
app = create_app()
|
| 8 |
|
| 9 |
+
def _restart_process():
|
| 10 |
+
print("Scheduled restart: exiting process to allow external restart.")
|
| 11 |
+
os._exit(0)
|
| 12 |
+
|
| 13 |
+
def _schedule_restart(hours: int):
|
| 14 |
+
if hours > 0:
|
| 15 |
+
timer = threading.Timer(hours * 3600, _restart_process)
|
| 16 |
+
timer.daemon = True
|
| 17 |
+
timer.start()
|
| 18 |
+
|
| 19 |
if __name__ == "__main__":
|
| 20 |
import sys
|
| 21 |
host = os.environ.get("HOST", "0.0.0.0")
|
| 22 |
port = int(os.environ.get("PORT", 5000))
|
| 23 |
debug = os.environ.get("FLASK_DEBUG", "0") == "1"
|
| 24 |
+
# Schedule automatic restart after 5 hours if RESTART_AFTER_HOURS not set
|
| 25 |
+
restart_hours = int(os.getenv("RESTART_AFTER_HOURS", "5"))
|
| 26 |
+
_schedule_restart(restart_hours)
|
| 27 |
try:
|
| 28 |
app.run(host=host, port=port, debug=debug, use_reloader=False, threaded=True)
|
| 29 |
except KeyboardInterrupt:
|