2019-01-23 15:13:29 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2024-01-13 01:24:32 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-08-27 16:45:16 +02:00
|
|
|
import logging
|
2022-11-23 15:54:22 +01:00
|
|
|
import logging.config
|
2023-04-05 16:23:46 +02:00
|
|
|
|
2019-01-23 15:13:29 +01:00
|
|
|
from subprocess import Popen
|
2021-08-27 16:45:16 +02:00
|
|
|
|
2021-10-18 13:06:43 +02:00
|
|
|
from lookyloo.default import get_config, get_homedir, AbstractManager
|
2021-08-27 16:45:16 +02:00
|
|
|
|
2022-11-23 15:54:22 +01:00
|
|
|
logging.config.dictConfig(get_config('logging'))
|
2021-08-27 16:45:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Website(AbstractManager):
|
|
|
|
|
2024-01-13 01:24:32 +01:00
|
|
|
def __init__(self, loglevel: int | None=None) -> None:
|
2021-08-27 16:45:16 +02:00
|
|
|
super().__init__(loglevel)
|
|
|
|
self.script_name = 'website'
|
2024-01-12 17:15:41 +01:00
|
|
|
self.process: Popen = self._launch_website() # type: ignore[type-arg]
|
2021-08-27 17:28:26 +02:00
|
|
|
self.set_running()
|
2021-08-27 16:45:16 +02:00
|
|
|
|
2024-01-12 17:15:41 +01:00
|
|
|
def _launch_website(self) -> Popen: # type: ignore[type-arg]
|
2021-08-27 16:45:16 +02:00
|
|
|
website_dir = get_homedir() / 'website'
|
|
|
|
ip = get_config('generic', 'website_listen_ip')
|
|
|
|
port = get_config('generic', 'website_listen_port')
|
|
|
|
return Popen(['gunicorn', '-w', '10',
|
|
|
|
'--graceful-timeout', '2', '--timeout', '300',
|
|
|
|
'-b', f'{ip}:{port}',
|
|
|
|
'--log-level', 'info',
|
2024-06-13 12:43:47 +02:00
|
|
|
'--max-requests', '2000',
|
|
|
|
'--max-requests-jitter', '100',
|
2024-06-13 14:24:53 +02:00
|
|
|
'--name', 'website_lookyloo',
|
2021-08-27 16:45:16 +02:00
|
|
|
'web:app'],
|
|
|
|
cwd=website_dir)
|
2019-04-05 15:07:22 +02:00
|
|
|
|
2019-01-23 15:13:29 +01:00
|
|
|
|
2024-01-12 17:15:41 +01:00
|
|
|
def main() -> None:
|
2021-08-27 16:45:16 +02:00
|
|
|
w = Website()
|
|
|
|
w.run(sleep_in_sec=10)
|
2020-10-03 21:19:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|