From 1f7c9d511f408fb44075928ebbd21fb4129ef487 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sat, 2 Jun 2018 10:54:49 +0200 Subject: [PATCH] Improve the readme with update and deployment tips --- README.md | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dd9625c..6d0bd11 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ git clone https://git.khaganat.net/Tycho/khaganat-web.git khaganat-web cd khaganat-web vim .env -pipenv --three --update +PIPENV_VENV_IN_PROJECT=1 pipenv --three update pipenv run ./manage.py migrate pipenv run ./manage.py collectstatic pipenv run ./manage.py compilemessages @@ -57,3 +57,106 @@ You can set the following variables in the `.env` file: * `KHAGANAT_HTTPS_HEADER_VALUE`: Header value for `SECURE_PROXY_SSL_HEADER`, default is `https`. * `KHAGANAT_NSFW_TAGS`: Coma-separated list of words that triggers the content warning in logs, default is `\#nsfw`. * `KHAGANAT_NSFW_NAME`: Name of the cookie holding the NSFW allowance, default is `nsfw_allowed`. + + +## Quick update + +``` +cd khaganat-web +git pull +pipenv --three update +pipenv run ./manage.py migrate +pipenv run ./manage.py collectstatic +pipenv run ./manage.py compilemessages +``` + +Then restart the WSGI server. + + +## Nginx + uWSGI on ArchLinux + +Install `nginx-mainline`, `uwsgi` and `uwsgi-plugin-python`. + +``` +# mkdir -p /srv/http/khaganat/static +# cd /srv/http/khaganat +# git clone https://git.khaganat.net/Tycho/khaganat-web.git app +# cd app +# PIPENV_VENV_IN_PROJECT=1 pipenv --three update +``` + +Create `/etc/uwsgi/khaganat.ini` with the appropriate environment variables: + +``` +[uwsgi] +chdir = /srv/http/khaganat/app +home = /srv/http/khaganat/app/.venv +module = khaganat.wsgi:application +plugins = python +socket = /srv/http/khaganat/uwsgi.sock +uid = http +gid = http +threads = 2 +vacuum = True +env = KHAGANAT_SECRET_KEY="generate a new one" +env = KHAGANAT_DEBUG=False +env = KHAGANAT_STATIC_ROOT=/srv/http/khaganat/static +env = KHAGANAT_HOSTNAMES=khaganat.local +``` + +Create `/etc/systemd/system/multi-user.target.wants/uwsgi@khaganat.service` : + +``` +[Unit] +Description=uWSGI service unit +After=syslog.target + +[Service] +ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/%I.ini +ExecReload=/bin/kill -HUP $MAINPID +ExecStop=/bin/kill -INT $MAINPID +Restart=always +Type=notify +StandardError=syslog +NotifyAccess=all +KillSignal=SIGQUIT + +[Install] +WantedBy=multi-user.target +``` + +Configure nginx : + +``` +server { + listen 80; + listen [::]:80; + server_name "khaganat.local"; + + include custom/headers.conf; + + location /static { + root /srv/http/khaganat/; + } + + location / { + uwsgi_pass unix:///srv/http/khaganat/uwsgi.sock; + include uwsgi_params; + } +} +``` + +Finish the installation: + +``` +# cd /srv/http/khaganat/app +# pipenv run ./manage.py migrate +# pipenv run ./manage.py collectstatic +# pipenv run ./manage.py compilemessages +# pipenv run ./manage.py createsuperuser +# chown -R http:http /srv/http/khaganat/ +# systemctl enable uwsgi@khaganat.service +# systemctl start uwsgi@khaganat.service +# systemctl enable nginx.service +# systemctl start nginx.service +```