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
|
2020-09-21 16:41:30 +02:00
|
|
|
from lookyloo.helpers import get_homedir, shutdown_requested, set_running, unset_running, get_socket_path, get_config
|
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
|
|
|
|
2020-10-03 21:19:43 +02:00
|
|
|
def 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'
|
2020-09-21 16:41:30 +02:00
|
|
|
ip = get_config('generic', 'website_listen_ip')
|
|
|
|
port = get_config('generic', 'website_listen_port')
|
2019-01-23 15:13:29 +01:00
|
|
|
try:
|
2020-09-21 16:41:30 +02:00
|
|
|
p = Popen(['gunicorn', '-w', '10',
|
2020-01-21 17:39:18 +01:00
|
|
|
'--graceful-timeout', '2', '--timeout', '300',
|
2020-09-21 16:41:30 +02:00
|
|
|
'-b', f'{ip}:{port}',
|
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')
|
2020-10-03 21:19:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|