2019-01-23 15:13:29 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-05 14:01:36 +02:00
|
|
|
import time
|
|
|
|
import signal
|
2019-01-23 15:13:29 +01:00
|
|
|
from subprocess import Popen
|
2019-04-05 15:07:22 +02:00
|
|
|
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-04-05 15:07:22 +02:00
|
|
|
|
2019-01-23 15:13:29 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-04-05 15:07:22 +02:00
|
|
|
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:
|
2019-04-05 14:13:07 +02:00
|
|
|
p = Popen(['gunicorn', '--worker-class', 'eventlet', '-w', '10',
|
|
|
|
'--graceful-timeout', '2', '--timeout', '30',
|
|
|
|
'-b', '0.0.0.0:5100',
|
|
|
|
'web:app'],
|
2019-04-05 14:01:36 +02:00
|
|
|
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:
|
2019-04-05 14:01:36 +02:00
|
|
|
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')
|