From ca5d07b8b8ac46c84668af73a2722a983edc4b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Sat, 12 Aug 2017 20:12:14 +0200 Subject: [PATCH] Add config to run as service behind nginx --- README.md | 35 ++++++++++++++++++++++++++++- __init__.py | 0 etc/nginx/sites-available/lookyloo | 9 ++++++++ etc/systemd/system/lookyloo.service | 16 +++++++++++++ lookyloo.ini | 11 +++++++++ lookyloo/__init__.py | 2 +- wsgi.py | 7 ++++++ 7 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 __init__.py create mode 100644 etc/nginx/sites-available/lookyloo create mode 100644 etc/systemd/system/lookyloo.service create mode 100644 lookyloo.ini create mode 100644 wsgi.py diff --git a/README.md b/README.md index 9cadd29..8f8b795 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,6 @@ And restart xdm: service xdm restart ``` - # Installation of scrapysplashwrapper You need a running splash instance, preferably on docker: https://splash.readthedocs.io/en/stable/install.html @@ -80,3 +79,37 @@ pew toggleglobalsitepackages # PyQt4 is not easily installable in a virtualenv pip install -r requirements.txt pip install -e . ``` +# Run the app locally + +```bash +export DISPLAY=:0 +export FLASK_APP=lookyloo +flask run +``` + +## With a reverse proxy (Nginx) + +```bash +pip install uwsgi +``` + +### Config files + +You have to configure the two following files: + +* `etc/nginxsites-available/lookyloo` +* `etc/systemd/system/lookyloo.service` + +And copy them to the appropriate directories and run the following command: +`sudo ln -s /etc/nginx/sites-available/lookyloo /etc/nginx/sites-enabled` + +Make sure everything is working: + +```bash +sudo systemctl start lookyloo +sudo systemctl enable lookyloo +sudo nginx -t +# If it is cool: +sudo service restart nginx +``` + diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/etc/nginx/sites-available/lookyloo b/etc/nginx/sites-available/lookyloo new file mode 100644 index 0000000..fc4a417 --- /dev/null +++ b/etc/nginx/sites-available/lookyloo @@ -0,0 +1,9 @@ +server { + listen 80; + server_name server_domain_or_IP; + + location / { + include uwsgi_params; + uwsgi_pass unix:/home//lookyloo/lookyloo.sock; + } +} diff --git a/etc/systemd/system/lookyloo.service b/etc/systemd/system/lookyloo.service new file mode 100644 index 0000000..c2bd9be --- /dev/null +++ b/etc/systemd/system/lookyloo.service @@ -0,0 +1,16 @@ +[Unit] +Description=uWSGI instance to serve lookyloo +After=network.target + +[Service] +User=www-data +Group=www-data +WorkingDirectory=/home//lookyloo +Environment="PATH=/home///bin" +ExecStart=/home///bin/uwsgi --ini lookyloo.ini +Environment=DISPLAY=:0 +Environment=FLASK_APP=lookyloo + +[Install] +WantedBy=multi-user.target + diff --git a/lookyloo.ini b/lookyloo.ini new file mode 100644 index 0000000..33457ec --- /dev/null +++ b/lookyloo.ini @@ -0,0 +1,11 @@ +[uwsgi] +module = wsgi:app + +master = true +processes = 5 + +socket = lookyloo.sock +chmod-socket = 660 +vacuum = true + +die-on-term = true diff --git a/lookyloo/__init__.py b/lookyloo/__init__.py index 0d3a366..0829c31 100644 --- a/lookyloo/__init__.py +++ b/lookyloo/__init__.py @@ -5,7 +5,7 @@ import json from har2tree import CrawledTree, hostname_treestyle from scrapysplashwrapper import crawl -from ete3_webserver import NodeActions, WebTreeHandler +from .ete3_webserver import NodeActions, WebTreeHandler from flask import Flask, render_template, request from flask_bootstrap import Bootstrap diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..2b6acbb --- /dev/null +++ b/wsgi.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from lookyloo import app + +if __name__ == "__main__": + app.run()