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-16 16:04:58 +02:00
|
|
|
r = StrictRedis(unix_socket_path=get_socket_path('cache'))
|
2019-04-05 15:07:22 +02:00
|
|
|
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:
|
2020-01-23 11:32:36 +01:00
|
|
|
p = Popen(['gunicorn','-w', '10',
|
2020-01-21 17:39:18 +01:00
|
|
|
'--graceful-timeout', '2', '--timeout', '300',
|
2019-04-05 14:13:07 +02:00
|
|
|
'-b', '0.0.0.0:5100',
|
2019-11-02 05:05:08 +01:00
|
|
|
'--log-level', 'info',
|
2019-04-05 14:13:07 +02:00
|
|
|
'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')
|