lookyloo/bin/start_website.py

38 lines
1.2 KiB
Python
Raw Normal View History

2019-01-23 15:13:29 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
import signal
2019-01-23 15:13:29 +01:00
from subprocess import Popen
from lookyloo.helpers import get_homedir, shutdown_requested, set_running, unset_running, get_socket_path
2019-04-05 16:14:30 +02:00
from redis import StrictRedis
2019-01-23 15:13:29 +01:00
if __name__ == '__main__':
r = StrictRedis(unix_socket_path=get_socket_path('cache'), db=1)
r.delete('cache_loaded')
2019-01-30 14:30:01 +01:00
website_dir = get_homedir() / 'website'
2019-01-23 15:13:29 +01:00
Popen([str(website_dir / '3rdparty.sh')], cwd=website_dir)
try:
p = Popen(['gunicorn', '--worker-class', 'eventlet', '-w', '10',
'--graceful-timeout', '2', '--timeout', '30',
'-b', '0.0.0.0:5100',
'web:app'],
cwd=website_dir)
set_running('website')
while True:
if shutdown_requested() or p.poll() is not None:
break
time.sleep(1)
2019-01-23 15:13:29 +01:00
except KeyboardInterrupt:
print('Website killed by user.')
finally:
print('Shutting down website.')
try:
# Killing everything if possible.
p.send_signal(signal.SIGWINCH)
p.send_signal(signal.SIGTERM)
except Exception:
pass
unset_running('website')