Compare commits

...
Author SHA1 Message Date
ksmithandClaude Sonnet 5 f2ee793cf8 upgrade.sh: auto-bump EVECTION_PWA_CACHE_VERSION on every deploy
The release-notes reminder to manually bump this and restart gunicorn
was easy to miss or forget, leaving installed PWAs on a stale cached
shell/pages after an upgrade that changed static assets. upgrade.sh
now sets it to the deployed tag itself before restarting services, so
there's no manual step and no cache-invalidation window to miss.
install.sh does the same on first install for consistency.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 12:08:05 -06:00
ksmithandClaude Sonnet 5 b7d9ee672c Add an atomic per-feed claim to poll_due_feeds (T1)
poll_due_feeds scanned for due feeds and dispatched fetch_feed without
marking them claimed, so overlapping beat ticks or a slow-running
fetch could dispatch the same feed twice, racing on ETag/status/error-
count writes. Feed.claimed_at is now set via an UPDATE ... WHERE
claimed_at IS NULL OR claimed_at < stale-cutoff, so only one caller's
UPDATE can ever match a given row; fetch_feed clears it when done.
A claim older than CLAIM_STALE_MINUTES is treated as abandoned so a
worker dying mid-fetch doesn't wedge the feed forever.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 12:03:18 -06:00
ksmithandClaude Sonnet 5 d7b433e580 Purge the service worker's authenticated-page cache on logout (S3)
PAGES_CACHE held every cached navigation response (including
authenticated article pages) with no logout-time purge, so a later
offline navigation on a shared or account-switched device could still
serve another user's cached pages. Logout is a plain POST, so the
fetch handler now special-cases that request: it deletes PAGES_CACHE
and lets the real logout request through, with no race against the
navigation that follows since it's synchronous with the same request.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 12:03:10 -06:00
ksmithandClaude Sonnet 5 b52ba2be8a Make first-run setup race-safe with an atomic SetupLock claim (S4)
The setup view's User.objects.exists() check and the admin account's
save() weren't in the same transaction, so two concurrent requests
during first deployment could both pass the check and both create an
admin account. SetupLock is a singleton row (pk=1); claiming it and
creating the admin now happen in one atomic block, so only the first
of any racing requests can succeed — the rest hit IntegrityError and
are sent to the login page instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 12:03:05 -06:00
ksmithandClaude Sonnet 5 56eb2bc498 Fail closed in production if SECRET_KEY is missing or the placeholder default (S2)
base.py's env.str() fallback is a publicly known string in this repo's
history. Running prod settings with it (an unset or forgotten .env
value) would sign sessions/CSRF tokens with a key anyone can read.
install.sh already generates a real random key for fresh installs, so
this only blocks the broken case.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 12:02:58 -06:00
ksmithandClaude Sonnet 5 9d91da6fc6 Fix /health/ 400ing when hit directly over loopback (as upgrade.sh does)
scripts/upgrade.sh's health check connects straight to gunicorn's bind
address, bypassing the reverse proxy entirely, so the request's Host
header is "127.0.0.1:<port>" and it has no X-Forwarded-Proto header.
Against prod settings that's exactly a DisallowedHost (ALLOWED_HOSTS only
has the public domain) — which Django turns into a 400 — and would have
then hit a redirect-to-HTTPS loop from SECURE_SSL_REDIRECT right after,
since there's no TLS listener on that port to redirect to. Allow the
loopback addresses in ALLOWED_HOSTS (harmless: gunicorn's bind address is
never reachable from outside this host per docs/install.md) and exempt
/health/ from the HTTPS redirect specifically.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 09:19:27 -06:00
ksmithandClaude Sonnet 5 c316f411f8 Make the active-tag sidebar highlight as visible as the active-feed one
.sidebar-tag-link.active only changed text color, which is easy to miss
next to .sidebar-feed-link.active's background pill + bold weight. Give
the tag link the same background-pill treatment (padding/margin offset
so the box doesn't shift layout when inactive).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 09:17:45 -06:00
ksmithandClaude Sonnet 5 e1907ff587 install.sh: fail hard (or auto-install) when Redis isn't actually reachable
The old check only looked for redis-cli on PATH and printed a warning if
missing — it never tested an actual connection, so a host with no Redis
installed at all still sailed through the entire install looking
successful. The real failure only showed up later as every feed stuck on
"pending" forever, with the worker/beat units quietly retrying their
connection in the background rather than surfacing anything to whoever
ran the script. Actually connect to the REDIS_URL that will end up in
.env; on Debian/Ubuntu with the default local address, install and start
redis-server automatically; otherwise fail the install outright with a
clear message instead of a warning that's easy to miss.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 09:12:41 -06:00
ksmithandClaude Sonnet 5 b0d62c91f8 upgrade.sh: use the venv's Python for the health check, not curl
curl isn't installed by default on this install's host, and nothing else
in install.sh/upgrade.sh actually requires it — the venv's own Python
(which obviously exists by the time this check runs) can make the same
HTTP request via urllib, so drop the curl dependency entirely rather than
adding it to the prerequisites.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 09:08:48 -06:00
ksmithandClaude Sonnet 5 2068df471f install.sh: actually restart services when their unit files change
systemctl enable --now only starts a service if it's stopped — on a
re-run where a unit file's ExecStart changed (e.g. picking up a new
EVECTION_GUNICORN_BIND), the already-running process just kept running
on its old command line indefinitely. This is exactly what happened
switching gunicorn from a Unix socket to TCP: the new unit file was
written and daemon-reload'd, but gunicorn itself never restarted, so it
kept listening on the old socket. Restart explicitly instead of relying
on --now.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 09:05:46 -06:00
ksmithandClaude Sonnet 5 21c33e8188 Make the reverse proxy a required, pluggable part of every deployment
gunicorn previously only ever bound to a Unix socket, which assumes the
reverse proxy is nginx running on this same host — it can't be reached by
a proxy on a different machine at all (e.g. Nginx Proxy Manager on its own
box), which is this project's actual deployment target. Switch gunicorn to
listening on a plain TCP address instead, controlled by a new
EVECTION_GUNICORN_BIND setting in .env.

install.sh now asks whether the proxy is local or remote and picks a
sensible bind default either way (127.0.0.1:8000 vs 0.0.0.0:8000, with a
reminder to firewall the port in the remote case), and no longer tries to
automate nginx/certbot itself — docs/install.md's new "Reverse proxy"
section covers both shapes instead, since which proxy and where it runs is
the operator's choice, not something this script should assume or set up.
upgrade.sh's health check now curls the TCP bind instead of the old socket
path.

Also add WhiteNoise so gunicorn serves /static/ itself: the old approach
(nginx aliasing the staticfiles directory on disk) silently breaks the
moment the proxy isn't on this host and can't see this filesystem.
nginx.conf.example's own /static/ alias becomes an optional same-host perf
optimization rather than a requirement.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 09:01:46 -06:00
ksmithandClaude Sonnet 5 62702e13e3 Detect and recreate a half-created venv, not just a missing one
The idempotency check only looked for the venv directory's existence, so
a venv left behind by an earlier failed run (e.g. missing ensurepip, as
just hit) — present but with no bin/pip — made every later re-run skip
venv creation entirely and then fail on a pip that was never created.
Check for bin/pip specifically and wipe+recreate if it's missing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 08:52:36 -06:00
ksmithandClaude Sonnet 5 78611c0eae Check for a working venv module before install.sh does anything else
On Debian/Ubuntu, python3-venv (ensurepip support) is a separate package
from python3 itself, and apt installing just python3 leaves venv creation
failing partway through install.sh — after the system user, chown, and
git checkout have all already happened. Check for it up front alongside
the Python version check, and document the apt package in install.md's
prerequisites.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 08:51:28 -06:00
ksmithandClaude Sonnet 5 50d2ba9404 Mark the app checkout as a safe.directory for root's git commands
install.sh chowns $APP_DIR to the service user, but its own (and
upgrade.sh's) git fetch/checkout steps run as root per the previous fix —
git refuses that combination by default ("detected dubious ownership"),
which is exactly what happens re-running install.sh after an earlier run
got far enough to chown the checkout. Add the directory to root's
safe.directory list before touching it with git.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 08:49:37 -06:00
ksmithandClaude Sonnet 5 8c23cc631c Fix install.sh failing with permission denied creating the venv
EVECTION_HOME (the venv's parent directory, e.g. /opt/evection) was never
chowned to the service user — only the app checkout inside it was — so
venv creation failed with Permission denied whenever EVECTION_HOME was
created by root before running the script (the documented quick-install
steps do exactly that: mkdir + git clone as root, then run install.sh).

Also run the release-tag git fetch/checkout as root instead of
sudo -u $EVECTION_USER in both install.sh and upgrade.sh: the service
user has no reason to have its own git credentials configured, so running
as it just means the private repo's auth prompt hangs the script (as seen
on this install) or silently fails. Root already has working credentials
from the initial clone. Added GIT_TERMINAL_PROMPT=0 so a credential
problem fails fast instead of hanging on a prompt either way.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 08:39:09 -06:00
18 changed files with 509 additions and 120 deletions

No files matched your search

@@ -0,0 +1,22 @@
# Generated by Django 5.2.18 on 2026-10-31 18:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("accounts", "0001_initial"),
]
operations = [
migrations.CreateModel(
name="SetupLock",
fields=[
(
"id",
models.PositiveSmallIntegerField(default=1, primary_key=True, serialize=False),
),
],
),
]
+12
View File
@@ -5,3 +5,15 @@ from django.db import models
class User(AbstractUser):
timezone = models.CharField(max_length=64, default="UTC")
created_at = models.DateTimeField(auto_now_add=True)
class SetupLock(models.Model):
"""Singleton row that gates first-run setup against a race between
concurrent requests. The setup view always tries to INSERT the row
with pk=1 in the same transaction as creating the first admin user:
the database's primary-key uniqueness makes exactly one of those
INSERTs win even under concurrent requests, so only one admin account
can ever be created this way, instead of the User.objects.exists()
check alone (which has a window between the check and the save)."""
id = models.PositiveSmallIntegerField(primary_key=True, default=1)
+23 -1
View File
@@ -1,7 +1,7 @@
import pytest
from django.urls import reverse
from .models import User
from .models import SetupLock, User
# SetupWizardMiddleware's cache is reset around every test by the autouse
# fixture in the top-level conftest.py, not just here.
@@ -43,6 +43,28 @@ def test_setup_creates_admin_and_logs_in(client):
assert stream_response.status_code == 200
@pytest.mark.django_db
def test_setup_refuses_a_second_concurrent_submission(client):
# Simulates two requests racing the setup form: the first claims the
# SetupLock row directly (standing in for a request that's already
# past the User.objects.exists() check), so a second submission's
# INSERT must lose instead of also creating an admin account.
SetupLock.objects.create()
response = client.post(
reverse("accounts:setup"),
{
"username": "raced",
"email": "raced@example.com",
"password": "correct-horse-battery",
"password_confirm": "correct-horse-battery",
},
)
assert response.status_code == 302
assert response.url == reverse("accounts:login")
assert not User.objects.filter(username="raced").exists()
@pytest.mark.django_db
def test_setup_is_unreachable_once_a_user_exists(client):
User.objects.create_user("existing", password="irrelevant")
+12 -1
View File
@@ -1,11 +1,12 @@
from django.contrib import messages
from django.contrib.auth import login
from django.contrib.auth.decorators import user_passes_test
from django.db import IntegrityError, transaction
from django.shortcuts import redirect, render
from .forms import CreateUserForm, SetupForm
from .middleware import SetupWizardMiddleware
from .models import User
from .models import SetupLock, User
is_admin = user_passes_test(lambda u: u.is_authenticated and u.is_staff)
@@ -16,11 +17,21 @@ def setup(request):
form = SetupForm(request.POST or None)
if request.method == "POST" and form.is_valid():
try:
with transaction.atomic():
# Claims the one-time setup slot: the first of any
# concurrent requests to reach this INSERT wins it, and
# every other one raises IntegrityError instead of also
# creating an admin account. See SetupLock's docstring.
SetupLock.objects.create()
user = form.save(commit=False)
user.set_password(form.cleaned_data["password"])
user.is_staff = True
user.is_superuser = True
user.save()
except IntegrityError:
messages.info(request, "Setup was already completed. Log in with that account.")
return redirect("accounts:login")
SetupWizardMiddleware._a_user_exists = True
login(request, user)
messages.success(request, "Welcome to Evection! Your admin account is ready.")
@@ -0,0 +1,18 @@
# Generated by Django 5.2.18 on 2026-10-31 18:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("feeds", "0002_remove_folder"),
]
operations = [
migrations.AddField(
model_name="feed",
name="claimed_at",
field=models.DateTimeField(blank=True, null=True),
),
]
+9
View File
@@ -40,6 +40,15 @@ class Feed(models.Model):
fetch_error_count = models.PositiveIntegerField(default=0)
is_active = models.BooleanField(default=True)
# Set by poll_due_feeds' atomic claim (an UPDATE ... WHERE clause, not
# select_for_update — Celery Beat and fetch_feed run in separate
# transactions) and cleared once fetch_feed finishes, so overlapping
# beat ticks or a fetch that runs long can't both dispatch the same
# feed. A claim older than CLAIM_STALE_MINUTES (tasks.py) is treated as
# abandoned and can be reclaimed, so a worker dying mid-fetch doesn't
# wedge the feed forever.
claimed_at = models.DateTimeField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
+29 -4
View File
@@ -4,6 +4,7 @@ from io import BytesIO
from celery import shared_task
from django.contrib.auth import get_user_model
from django.db.models import Q
from django.utils import timezone
from apps.articles.tasks import apply_filter_rules_for_feed
@@ -14,13 +15,23 @@ from .services.fetcher import effective_interval_minutes, fetch_and_ingest
logger = logging.getLogger(__name__)
# How long a claimed-but-unfinished fetch blocks the same feed from being
# claimed again — must comfortably exceed FETCH_TIMEOUT_SECONDS plus parse/
# ingest time, so a slow-but-healthy fetch is never raced by the next tick,
# while a worker that died mid-fetch doesn't wedge the feed forever.
CLAIM_STALE_MINUTES = 10
@shared_task
def poll_due_feeds():
"""Find every active Feed whose polling interval has elapsed and
dispatch a fetch_feed task for each — fan-out happens here, not via one
Celery Beat entry per feed.
"""Find every active Feed whose polling interval has elapsed, atomically
claim it (so overlapping beat ticks or a slow-running previous fetch
can't dispatch the same feed twice), and dispatch a fetch_feed task for
each claimed feed — fan-out happens here, not via one Celery Beat entry
per feed.
"""
now = timezone.now()
claim_stale_before = now - timedelta(minutes=CLAIM_STALE_MINUTES)
due_feed_ids = [
feed.id
for feed in Feed.objects.filter(is_active=True).only(
@@ -28,9 +39,22 @@ def poll_due_feeds():
)
if _is_due(feed)
]
claimed_ids = []
for feed_id in due_feed_ids:
# The UPDATE's WHERE clause re-checks staleness at the database
# level: it only claims rows nobody else has already claimed more
# recently than CLAIM_STALE_MINUTES ago, so two workers racing this
# same loop can't both get rowcount=1 for the same feed.
claimed = (
Feed.objects.filter(id=feed_id, is_active=True)
.filter(Q(claimed_at__isnull=True) | Q(claimed_at__lt=claim_stale_before))
.update(claimed_at=now)
)
if claimed:
claimed_ids.append(feed_id)
for feed_id in claimed_ids:
fetch_feed.delay(feed_id)
return len(due_feed_ids)
return len(claimed_ids)
def _is_due(feed: Feed) -> bool:
@@ -48,6 +72,7 @@ def fetch_feed(feed_id: int):
return None
result = fetch_and_ingest(feed)
feed.claimed_at = None
feed.save()
changed_article_ids = result.new_article_ids + result.updated_article_ids
+52
View File
@@ -40,6 +40,58 @@ def test_poll_due_feeds_dispatches_only_due_feeds():
assert inactive_but_overdue.id not in dispatched_ids
@pytest.mark.django_db
def test_poll_due_feeds_does_not_reclaim_a_feed_it_just_claimed():
# Models a second beat tick (or an overlapping worker) running
# poll_due_feeds before the first claimed fetch_feed has finished —
# the feed must only be dispatched once.
overdue = Feed.objects.create(
feed_url="https://c.example.com/feed.xml",
last_fetched_at=timezone.now() - timedelta(hours=2),
fetch_interval_minutes=60,
)
with patch("apps.feeds.tasks.fetch_feed.delay") as mock_delay:
first_count = poll_due_feeds()
second_count = poll_due_feeds()
assert first_count == 1
assert second_count == 0
assert mock_delay.call_count == 1
overdue.refresh_from_db()
assert overdue.claimed_at is not None
@pytest.mark.django_db
def test_poll_due_feeds_reclaims_a_stale_claim():
from apps.feeds.tasks import CLAIM_STALE_MINUTES
overdue = Feed.objects.create(
feed_url="https://c.example.com/feed.xml",
last_fetched_at=timezone.now() - timedelta(hours=2),
fetch_interval_minutes=60,
claimed_at=timezone.now() - timedelta(minutes=CLAIM_STALE_MINUTES + 1),
)
with patch("apps.feeds.tasks.fetch_feed.delay") as mock_delay:
dispatched_count = poll_due_feeds()
assert dispatched_count == 1
assert mock_delay.call_args.args[0] == overdue.id
@pytest.mark.django_db
@responses.activate
def test_fetch_feed_task_clears_its_claim():
feed = Feed.objects.create(feed_url="https://example.com/feed.xml", claimed_at=timezone.now())
responses.add(responses.GET, feed.feed_url, body=GOOD_FEED_XML, status=200)
fetch_feed(feed.id)
feed.refresh_from_db()
assert feed.claimed_at is None
GOOD_FEED_XML = """<?xml version="1.0"?>
<rss version="2.0"><channel>
<title>Example Blog</title>
+5
View File
@@ -32,6 +32,11 @@ def test_service_worker_is_served_at_root_with_correct_type_and_scope(client):
assert 'self.addEventListener("fetch"' in body
# Mutations must stay network-only, never intercepted.
assert 'request.method !== "GET"' in body
# Logging out must purge PAGES_CACHE so a later offline navigation on
# a shared/account-switched device can't serve another user's
# previously cached authenticated pages.
assert "caches.delete(PAGES_CACHE)" in body
assert reverse("accounts:logout") in body
@pytest.mark.django_db
+49 -4
View File
@@ -1,13 +1,58 @@
from django.core.exceptions import ImproperlyConfigured
from .base import * # noqa: F403
from .base import env
from .base import SECRET_KEY, env
DEBUG = False
# nginx terminates TLS and proxies to gunicorn over a Unix socket (see
# docs/install.md) — this tells Django's request.is_secure() to trust the
# header nginx sets, and the redirect/cookie/HSTS settings below assume it.
# base.py falls back to a publicly known placeholder if SECRET_KEY isn't
# set — fine for a throwaway dev DB, but production must never sign
# sessions/CSRF tokens with a key anyone can read in this repo's history.
# Fail startup rather than quietly running with a known key.
if not SECRET_KEY or SECRET_KEY == "django-insecure-change-me-in-production":
raise ImproperlyConfigured(
"SECRET_KEY is missing or still the placeholder default. Set a unique, "
"random SECRET_KEY in .env before running with prod settings — generate "
'one with: python -c "from django.core.management.utils import '
'get_random_secret_key; print(get_random_secret_key())"'
)
# Health checks (scripts/upgrade.sh, an external uptime monitor, ...) hit
# gunicorn directly over loopback, bypassing the reverse proxy entirely —
# that request's Host header is "127.0.0.1:<port>", not the public domain
# in ALLOWED_HOSTS, so without this Django 400s it. Harmless to always
# allow: gunicorn's bind address is never reachable from outside this host
# in the first place (see docs/install.md's "Reverse proxy" section).
ALLOWED_HOSTS = [*ALLOWED_HOSTS, "localhost", "127.0.0.1", "::1"] # noqa: F405
# A reverse proxy (nginx, Caddy, Traefik, Nginx Proxy Manager on another
# host, ...) is required in front of gunicorn in every deployment — see
# docs/install.md — and it's always the one terminating TLS. This tells
# Django's request.is_secure() to trust the X-Forwarded-Proto header it
# sets, and the redirect/cookie/HSTS settings below assume it's set.
SECURE_SSL_REDIRECT = env.bool("SECURE_SSL_REDIRECT", default=True)
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
# /health/ is also exempted from the HTTPS redirect above: hit directly
# over loopback (see ALLOWED_HOSTS above) it has no X-Forwarded-Proto
# header to prove it's "secure", and there's no TLS listener on gunicorn's
# own port to redirect to anyway.
SECURE_REDIRECT_EXEMPT = [r"^health/$"]
# WhiteNoise serves /static/ directly from gunicorn instead of relying on
# the reverse proxy to alias the staticfiles directory on disk — the proxy
# may not even be on this host (see docs/install.md), so it can't be
# trusted to have filesystem access to $APP_DIR/staticfiles.
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
*MIDDLEWARE[1:], # noqa: F405
]
STORAGES = {
"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
+6 -5
View File
@@ -9,11 +9,12 @@ Group=evection
WorkingDirectory=/opt/evection/app
EnvironmentFile=/opt/evection/app/.env
Environment=DJANGO_SETTINGS_MODULE=config.settings.prod
RuntimeDirectory=evection
ExecStart=/opt/evection/venv/bin/gunicorn \
--workers 3 \
--bind unix:/run/evection/gunicorn.sock \
config.wsgi:application
# Evection is always meant to sit behind a reverse proxy (see
# docs/install.md) — it listens on a plain TCP address, never a Unix
# socket, so that proxy can be on this host or a different one.
# EVECTION_GUNICORN_BIND (set in .env by scripts/install.sh) controls
# what address:port that is.
ExecStart=/bin/sh -c 'exec /opt/evection/venv/bin/gunicorn --workers 3 --bind "$EVECTION_GUNICORN_BIND" config.wsgi:application'
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
+15 -4
View File
@@ -1,6 +1,12 @@
# Reverse proxy for Evection. Copy to /etc/nginx/sites-available/evection,
# adjust server_name and the certificate paths (certbot will fill those in
# for you if you use `certbot --nginx`), then symlink into sites-enabled.
# Reverse proxy for Evection, for the case where nginx runs on the SAME host
# as Evection (see docs/install.md's "Reverse proxy" section — if your proxy
# is on a different host/VM instead, e.g. Nginx Proxy Manager, this file
# doesn't apply to you directly, but the proxy_set_header lines below still
# show what any proxy needs to forward). Copy to
# /etc/nginx/sites-available/evection, adjust server_name, the certificate
# paths (certbot will fill those in for you if you use `certbot --nginx`),
# and the port in proxy_pass if you didn't use EVECTION_GUNICORN_BIND's
# default of 127.0.0.1:8000, then symlink into sites-enabled.
server {
listen 80;
@@ -24,6 +30,11 @@ server {
client_max_body_size 10M; # OPML uploads are small, but leave headroom
# Optional: gunicorn already serves /static/ itself via WhiteNoise (with
# its own far-future cache headers, since filenames are content-hashed),
# so this block is purely a same-host perf optimization that skips
# gunicorn for static assets — not required, and not an option at all
# once the proxy is on a different host than $APP_DIR/staticfiles.
location /static/ {
alias /opt/evection/app/staticfiles/;
expires 30d;
@@ -36,7 +47,7 @@ server {
# else below, so no special-casing is needed here.
location / {
proxy_pass http://unix:/run/evection/gunicorn.sock;
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+70 -32
View File
@@ -1,9 +1,16 @@
# Installing Evection
Evection is a traditional Python/Django application: `pip install`, a WSGI server
(gunicorn), a Celery worker + beat scheduler for background feed polling, and an
nginx reverse proxy in front of it. There's no Docker image for v1 — everything
below runs directly on the host.
(gunicorn), and a Celery worker + beat scheduler for background feed polling.
There's no Docker image for v1 — everything below runs directly on the host.
**A reverse proxy in front of gunicorn is required, always** — Evection has no
TLS support of its own and assumes one is terminating HTTPS for it (see "Reverse
proxy" below). It can be nginx/Caddy/Traefik running on the same host, or
something like Nginx Proxy Manager running on an entirely different host/VM —
`scripts/install.sh` doesn't set one up for you, since which one and where it
runs is up to you; it just leaves gunicorn listening on a TCP address for that
proxy to reach.
Both SQLite and PostgreSQL are fully supported. Steps that differ are marked
**SQLite** / **Postgres**; everything else applies to both.
@@ -32,9 +39,11 @@ run at all until a tag exists.
## Quick install
Once the prerequisites below are in place, `scripts/install.sh` automates
everything from "create a system user" through "systemd units are running" —
and optionally nginx + a Let's Encrypt certificate too. It's interactive
(asks for your domain and database choice) and safe to re-run.
everything from "create a system user" through "systemd units are running",
including asking where your reverse proxy will run so it can set up gunicorn's
listen address accordingly. It's interactive (asks for your domain, database
choice, and proxy location) and safe to re-run. It does **not** set up the
proxy itself — see "Reverse proxy" below for that, once this finishes.
```bash
sudo mkdir -p /opt/evection
@@ -55,18 +64,22 @@ and 4 below first — prerequisites and what `.env` controls.
## 1. Prerequisites
- Python 3.11 or 3.12
- Python 3.11 or 3.12, with its `venv` module (Debian/Ubuntu split this into a
separate `python3.X-venv` package — see below)
- Redis (Celery's broker)
- **Postgres only**: a PostgreSQL server (12+) and its client headers if you're not
using the bundled `psycopg[binary]` wheel (most platforms are covered by the wheel,
so this is rarely needed)
- nginx (or another reverse proxy)
- A domain name pointed at the host, if you want this reachable outside your LAN
- A reverse proxy, already running or that you're about to set up — on this
host or a different one (see "Reverse proxy" below)
- A domain name pointed at wherever that proxy terminates TLS, if you want
this reachable outside your LAN
Debian/Ubuntu example for the non-Python pieces:
Debian/Ubuntu example for the non-Python pieces (swap `python3.13-venv` for
whatever `python3 --version` reports on your system):
```bash
sudo apt install redis-server nginx
sudo apt install redis-server python3.13-venv
# Postgres only:
sudo apt install postgresql
```
@@ -127,11 +140,15 @@ At minimum, set the following in `.env`:
sudo -u postgres createdb evection -O evection
```
- `REDIS_URL` — `redis://localhost:6379/0` is fine for a single-host install
- `EVECTION_GUNICORN_BIND` — the `address:port` gunicorn listens on; see
"Reverse proxy" below for how to pick this
Evection reads `config.settings.prod` when run via the commands below (see each
systemd unit's `DJANGO_SETTINGS_MODULE`). That module turns on HTTPS-only cookies,
HSTS, and a Content-Security-Policy header on top of the base settings — see
`config/settings/prod.py` if you need to adjust it for your proxy setup.
HSTS, and a Content-Security-Policy header on top of the base settings, and
serves static files itself via WhiteNoise rather than relying on the proxy to
have filesystem access to this host — see `config/settings/prod.py` if you need
to adjust any of that.
## 5. Initialize the database and static files
@@ -190,28 +207,47 @@ sudo systemctl status evection-gunicorn evection-celery-worker evection-celery-b
sudo journalctl -u evection-gunicorn -f
```
## 7. nginx
## 7. Reverse proxy
Copy `docs/deploy/nginx.conf.example` to `/etc/nginx/sites-available/evection`,
adjust `server_name` and the certificate paths, then enable it:
gunicorn only ever listens on plain HTTP, on the `EVECTION_GUNICORN_BIND`
address you set in step 4 — it never terminates TLS itself. A reverse proxy
in front of it is not optional: it's what the setup wizard, login, and every
other page actually get reached through. Two shapes this takes:
**Proxy on the same host as Evection.** Set `EVECTION_GUNICORN_BIND=127.0.0.1:8000`
(install.sh's default when you say the proxy is local) so gunicorn isn't
reachable from outside this machine at all — only the proxy, listening on
80/443, is. `docs/deploy/nginx.conf.example` is a working nginx config for
this case; copy it into place and get a certificate the usual way:
```bash
sudo cp docs/deploy/nginx.conf.example /etc/nginx/sites-available/evection
# edit it: server_name, and the proxy_pass port if you didn't use 8000
sudo ln -s /etc/nginx/sites-available/evection /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
```
Get a TLS certificate (Let's Encrypt via certbot is the easiest path):
```bash
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.example
```
Evection's `prod` settings enable `SECURE_SSL_REDIRECT` and HSTS by default, so
plan to have TLS working before your first real visit — see
`config/settings/prod.py` to disable the redirect temporarily if you need to debug
over plain HTTP first.
**Proxy on a different host or VM** (Nginx Proxy Manager, a Caddy box, a
container host, etc.). Set `EVECTION_GUNICORN_BIND=0.0.0.0:8000` (or to this
host's specific IP) so the proxy can actually reach gunicorn over the
network, then **firewall that port to only accept connections from the
proxy's host** — gunicorn itself has no auth in front of it, so it must
never be reachable from the open internet directly. Point the proxy's
upstream/forward target at `this-host:8000`, and make sure it forwards
`X-Forwarded-Proto` (whatever sets up TLS passthrough/termination normally
handles this, but double-check — see the next paragraph for why it matters).
Whichever proxy you use, `docs/deploy/nginx.conf.example`'s `location /`
block shows the three headers that need forwarding either way.
Either way, the proxy must set `X-Forwarded-Proto: https` on requests it
forwards once it's terminating TLS — Evection's `prod` settings
(`SECURE_PROXY_SSL_HEADER` in `config/settings/prod.py`) trust that header to
know the original request was HTTPS, which is what keeps `SECURE_SSL_REDIRECT`
from causing a redirect loop. Plan to have TLS working end-to-end before your
first real visit; see `config/settings/prod.py` to disable the redirect
temporarily if you need to debug over plain HTTP first.
## 8. Visit the site
@@ -255,9 +291,11 @@ Equivalent by hand:
```bash
cd /opt/evection/app
sudo -u evection -H git fetch --tags --force
LATEST_TAG="$(sudo -u evection -H git tag --sort=-creatordate | head -n1)"
sudo -u evection -H git checkout --detach "$LATEST_TAG"
git fetch --tags --force
LATEST_TAG="$(git tag --sort=-creatordate | head -n1)"
git checkout --detach "$LATEST_TAG"
chown -R evection:evection /opt/evection/app
sed -i "s/^EVECTION_PWA_CACHE_VERSION=.*/EVECTION_PWA_CACHE_VERSION=$LATEST_TAG/" .env
sudo -u evection -H /opt/evection/venv/bin/pip install .
sudo -u evection -H env DJANGO_SETTINGS_MODULE=config.settings.prod \
/opt/evection/venv/bin/python manage.py migrate
@@ -274,7 +312,7 @@ git tag v$(date +%Y.%m.%d)
git push --tags
```
Bump `EVECTION_PWA_CACHE_VERSION` in `.env` whenever a release changes cached
static assets (CSS/JS/icons) — it's baked into the service worker's cache name, so
changing it forces every installed PWA to drop its old cache instead of serving
stale assets after the upgrade.
`upgrade.sh` sets `EVECTION_PWA_CACHE_VERSION` in `.env` to the deployed tag on every
run — it's baked into the service worker's cache name, so this forces every installed
PWA to drop its old cache instead of serving stale assets after the upgrade. You don't
need to bump it by hand.
+1
View File
@@ -22,6 +22,7 @@ dependencies = [
"psycopg[binary]>=3.1,<4",
"gunicorn>=21,<24",
"django-csp>=4.0,<5",
"whitenoise>=6.6,<7",
]
[project.optional-dependencies]
+114 -58
View File
@@ -1,6 +1,11 @@
#!/usr/bin/env bash
# Automates docs/install.md's manual steps: system user, virtualenv, .env,
# migrate/collectstatic, systemd units, and (optionally) nginx + TLS.
# migrate/collectstatic, systemd units. Does NOT set up a reverse proxy —
# Evection always requires one in front of gunicorn (see docs/install.md),
# but which one (local nginx/Caddy/Traefik, or something like Nginx Proxy
# Manager on a different host entirely) is up to you, so this script just
# leaves gunicorn listening on EVECTION_GUNICORN_BIND for you to point it
# at.
#
# Run as root, from inside the checkout you want to serve:
# sudo ./scripts/install.sh
@@ -11,7 +16,7 @@
# Non-interactive use (e.g. scripted provisioning) — set these before
# running, and the script won't prompt:
# EVECTION_ALLOWED_HOSTS, EVECTION_DATABASE_URL, EVECTION_REDIS_URL,
# EVECTION_USER (defaults to "evection")
# EVECTION_GUNICORN_BIND, EVECTION_USER (defaults to "evection")
set -euo pipefail
@@ -26,6 +31,13 @@ VENV_DIR="$EVECTION_HOME/venv"
EVECTION_USER="${EVECTION_USER:-evection}"
PYTHON_BIN="${PYTHON_BIN:-python3}"
# $APP_DIR ends up owned by $EVECTION_USER (see below), but the git steps
# in this script run as root — without this, git refuses to touch a repo
# it doesn't own ("detected dubious ownership"), which is exactly what
# happens re-running this script after a previous run got far enough to
# chown the checkout.
git config --global --add safe.directory "$APP_DIR"
echo "==> Installing Evection"
echo " App directory: $APP_DIR"
echo " Service user: $EVECTION_USER"
@@ -45,13 +57,52 @@ if [ "$PY_MAJOR" -lt 3 ] || { [ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -lt 11 ]; }
echo "Python $PY_VERSION found, but Evection needs 3.11 or newer." >&2
exit 1
fi
for bin in redis-cli nginx; do
if ! command -v "$bin" >/dev/null 2>&1; then
echo "Warning: '$bin' not found on PATH. Install it before going live" \
"(see docs/install.md's prerequisites section: apt install redis-server nginx)." >&2
if ! "$PYTHON_BIN" -c 'import ensurepip' >/dev/null 2>&1; then
echo "'$PYTHON_BIN' can't create virtualenvs (no ensurepip) — on" \
"Debian/Ubuntu, install it with: apt install python${PY_VERSION}-venv" >&2
exit 1
fi
# Celery (and therefore all feed fetching) is entirely dependent on Redis
# being reachable — it fails silently from the installer's point of view
# (the worker/beat processes just retry forever in the background), so this
# has to be a hard failure here, not a warning that's easy to miss while
# every later step "succeeds" at installing an app that can never fetch a
# single feed. Check the actual REDIS_URL that will end up in .env (an
# explicit EVECTION_REDIS_URL override, if set — the default local Redis
# otherwise), not just whether some redis-cli happens to be on PATH.
REDIS_URL_TO_CHECK="${EVECTION_REDIS_URL:-redis://localhost:6379/0}"
check_redis() {
"$PYTHON_BIN" -c "
import sys, socket, urllib.parse
u = urllib.parse.urlparse('$REDIS_URL_TO_CHECK')
try:
with socket.create_connection((u.hostname or 'localhost', u.port or 6379), timeout=3):
pass
except OSError as e:
print(e, file=sys.stderr)
sys.exit(1)
"
}
REDIS_HOST="$("$PYTHON_BIN" -c "import urllib.parse; print(urllib.parse.urlparse('$REDIS_URL_TO_CHECK').hostname or 'localhost')")"
if ! check_redis; then
if [[ "$REDIS_HOST" =~ ^(localhost|127\.0\.0\.1|::1)$ ]] && command -v apt-get >/dev/null 2>&1; then
echo "==> Redis isn't reachable at $REDIS_URL_TO_CHECK — installing redis-server"
apt-get install -y redis-server
systemctl enable --now redis-server
if ! check_redis; then
echo "Redis still isn't reachable after installing redis-server —" \
"check: systemctl status redis-server" >&2
exit 1
fi
else
echo "Redis isn't reachable at $REDIS_URL_TO_CHECK. Evection's background" \
"feed-fetching depends on it entirely, so this has to be fixed before" \
"continuing — either start/install Redis there, or set" \
"EVECTION_REDIS_URL to point at wherever it actually runs." >&2
exit 1
fi
fi
done
# --- 2. System user -----------------------------------------------------
@@ -61,25 +112,41 @@ if ! id -u "$EVECTION_USER" >/dev/null 2>&1; then
else
echo "==> System user '$EVECTION_USER' already exists"
fi
chown -R "$EVECTION_USER:$EVECTION_USER" "$APP_DIR"
# --- 2b. Pin to the latest release tag (if any exist) ----------------
#
# Run as root (this script already requires it), not as $EVECTION_USER:
# this repo was typically cloned by root (or whoever has git credentials
# configured), and the service user has no reason to have its own git
# auth set up. GIT_TERMINAL_PROMPT=0 means a credential problem fails
# fast instead of hanging the install on a silent username/password
# prompt.
if [ -d "$APP_DIR/.git" ]; then
sudo -u "$EVECTION_USER" -H git -C "$APP_DIR" fetch --tags --force || true
LATEST_TAG="$(sudo -u "$EVECTION_USER" -H git -C "$APP_DIR" tag --sort=-creatordate | head -n1)"
GIT_TERMINAL_PROMPT=0 git -C "$APP_DIR" fetch --tags --force || true
LATEST_TAG="$(git -C "$APP_DIR" tag --sort=-creatordate | head -n1)"
if [ -n "$LATEST_TAG" ]; then
echo "==> Checking out latest release: $LATEST_TAG"
# Detached HEAD, not a branch checkout — matches scripts/upgrade.sh,
# which only ever deploys a tagged release, never a branch tip.
sudo -u "$EVECTION_USER" -H git -C "$APP_DIR" checkout --quiet --detach "$LATEST_TAG"
git -C "$APP_DIR" checkout --quiet --detach "$LATEST_TAG"
else
echo "==> No release tags found yet — staying on whatever's currently checked out."
fi
fi
# Everything under $EVECTION_HOME (not just $APP_DIR — the venv created
# below lives next to it, not inside it) needs to belong to the service
# user, whether $EVECTION_HOME already existed (e.g. you mkdir'd it
# yourself before cloning) or adduser just created it.
chown "$EVECTION_USER:$EVECTION_USER" "$EVECTION_HOME"
chown -R "$EVECTION_USER:$EVECTION_USER" "$APP_DIR"
# --- 3. Virtualenv + install ---------------------------------------------
if [ -d "$VENV_DIR" ] && [ ! -x "$VENV_DIR/bin/pip" ]; then
echo "==> $VENV_DIR exists but looks incomplete (no bin/pip) — recreating it"
rm -rf "$VENV_DIR"
fi
if [ ! -d "$VENV_DIR" ]; then
echo "==> Creating virtualenv at $VENV_DIR"
sudo -u "$EVECTION_USER" -H "$PYTHON_BIN" -m venv "$VENV_DIR"
@@ -110,15 +177,34 @@ if [ ! -f "$ENV_FILE" ]; then
fi
DATABASE_URL="${DATABASE_URL:-sqlite:///$APP_DIR/db.sqlite3}"
GUNICORN_BIND="${EVECTION_GUNICORN_BIND:-}"
if [ -z "$GUNICORN_BIND" ] && [ -t 0 ]; then
echo
echo "Evection must run behind a reverse proxy — gunicorn needs an" \
"address:port that proxy can reach."
read -rp "Is the reverse proxy on this same machine, or a different one? [same/different] [same]: " PROXY_LOCATION
if [[ "${PROXY_LOCATION:-}" =~ ^[Dd] ]]; then
read -rp "Address:port for gunicorn to listen on (e.g. 0.0.0.0:8000, or this host's own IP:8000) [0.0.0.0:8000]: " GUNICORN_BIND
GUNICORN_BIND="${GUNICORN_BIND:-0.0.0.0:8000}"
echo " Remember to firewall this port to only accept connections" \
"from the reverse proxy's host."
else
read -rp "Address:port for gunicorn to listen on [127.0.0.1:8000]: " GUNICORN_BIND
GUNICORN_BIND="${GUNICORN_BIND:-127.0.0.1:8000}"
fi
fi
GUNICORN_BIND="${GUNICORN_BIND:-127.0.0.1:8000}"
cat > "$ENV_FILE" <<EOF
SECRET_KEY=$SECRET_KEY
DEBUG=False
ALLOWED_HOSTS=$ALLOWED_HOSTS
DATABASE_URL=$DATABASE_URL
REDIS_URL=${EVECTION_REDIS_URL:-redis://localhost:6379/0}
EVECTION_GUNICORN_BIND=$GUNICORN_BIND
EVECTION_SIGNUP_ENABLED=False
EVECTION_MIN_FETCH_INTERVAL_MINUTES=15
EVECTION_PWA_CACHE_VERSION=v1
EVECTION_PWA_CACHE_VERSION=${LATEST_TAG:-v1}
EOF
chown "$EVECTION_USER:$EVECTION_USER" "$ENV_FILE"
chmod 600 "$ENV_FILE"
@@ -126,6 +212,11 @@ else
echo "==> $ENV_FILE already exists — leaving it alone"
fi
# Needed below for the final "gunicorn is listening on..." message even
# when $ENV_FILE already existed and the block above was skipped.
GUNICORN_BIND="$(grep -m1 '^EVECTION_GUNICORN_BIND=' "$ENV_FILE" | cut -d= -f2-)"
GUNICORN_BIND="${GUNICORN_BIND:-127.0.0.1:8000}"
# --- 5. Migrate + static files --------------------------------------------
echo "==> Running migrations"
@@ -146,56 +237,21 @@ for unit in evection-gunicorn evection-celery-worker evection-celery-beat; do
"$APP_DIR/docs/deploy/${unit}.service" > "/etc/systemd/system/${unit}.service"
done
systemctl daemon-reload
systemctl enable --now evection-gunicorn evection-celery-worker evection-celery-beat
systemctl enable evection-gunicorn evection-celery-worker evection-celery-beat
# Not "enable --now": that only starts a service if it's stopped, so a
# re-run after a unit file changed (e.g. a new EVECTION_GUNICORN_BIND)
# would reload the daemon but leave the already-running process on its
# stale old ExecStart indefinitely. Always restart explicitly instead.
systemctl restart evection-gunicorn evection-celery-worker evection-celery-beat
echo
echo "==> Services installed. Checking status..."
systemctl --no-pager status evection-gunicorn evection-celery-worker evection-celery-beat \
|| echo "One or more services didn't start cleanly — see 'journalctl -u evection-gunicorn' etc." >&2
# --- 7. nginx (optional) ---------------------------------------------------
SET_UP_NGINX="${EVECTION_SETUP_NGINX:-}"
if [ -z "$SET_UP_NGINX" ] && [ -t 0 ]; then
echo
read -rp "Set up nginx and an HTTPS certificate now? [y/N]: " SET_UP_NGINX
fi
if [[ "${SET_UP_NGINX:-}" =~ ^[Yy]$ ]]; then
if ! command -v nginx >/dev/null 2>&1; then
echo "nginx isn't installed — install it first (apt install nginx), then" \
"run docs/install.md's nginx section manually." >&2
else
DOMAIN="${EVECTION_DOMAIN:-}"
if [ -z "$DOMAIN" ] && [ -t 0 ]; then
read -rp "Domain name for nginx/TLS (must match a hostname in ALLOWED_HOSTS): " DOMAIN
fi
if [ -z "$DOMAIN" ]; then
echo "No domain given — skipping nginx setup. Run docs/install.md's nginx section manually." >&2
else
sed -e "s/your-domain.example/$DOMAIN/g" \
-e "s#/opt/evection#$EVECTION_HOME#g" \
"$APP_DIR/docs/deploy/nginx.conf.example" > "/etc/nginx/sites-available/evection"
ln -sf /etc/nginx/sites-available/evection /etc/nginx/sites-enabled/evection
if nginx -t; then
systemctl reload nginx
echo "==> nginx configured for $DOMAIN (HTTP only so far)"
if command -v certbot >/dev/null 2>&1; then
certbot --nginx -d "$DOMAIN" || echo "certbot failed — run it manually: certbot --nginx -d $DOMAIN" >&2
else
echo "certbot isn't installed. Install it and run:" \
"apt install certbot python3-certbot-nginx && certbot --nginx -d $DOMAIN" >&2
fi
else
echo "nginx config test failed — not enabling it. Check /etc/nginx/sites-available/evection." >&2
fi
fi
fi
else
echo "==> Skipping nginx — see docs/install.md step 7 to set it up yourself."
fi
echo
echo "==> Done."
echo " Visit the site (once nginx/TLS is in place) — the setup wizard creates your admin account."
echo " gunicorn is listening on $GUNICORN_BIND — point your reverse proxy at it"
echo " (see docs/install.md's \"Reverse proxy\" section) before visiting the site."
echo " Once that's in place, the setup wizard creates your admin account on first visit."
echo " To upgrade later: sudo ./scripts/upgrade.sh"
+50 -9
View File
@@ -26,7 +26,11 @@ APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
EVECTION_HOME="$(dirname "$APP_DIR")"
VENV_DIR="$EVECTION_HOME/venv"
EVECTION_USER="${EVECTION_USER:-evection}"
SOCKET="/run/evection/gunicorn.sock"
# $APP_DIR is owned by $EVECTION_USER, but the git steps below run as
# root — without this, git refuses to touch a repo it doesn't own
# ("detected dubious ownership").
git config --global --add safe.directory "$APP_DIR"
if ! id -u "$EVECTION_USER" >/dev/null 2>&1; then
echo "System user '$EVECTION_USER' doesn't exist — is Evection installed?" \
@@ -46,14 +50,18 @@ fi
echo "==> Fetching latest release"
cd "$APP_DIR"
sudo -u "$EVECTION_USER" -H git fetch --tags --force
LATEST_TAG="$(sudo -u "$EVECTION_USER" -H git tag --sort=-creatordate | head -n1)"
# Run git as root (this script already requires it), not as $EVECTION_USER:
# the service user has no reason to have its own git credentials set up,
# and GIT_TERMINAL_PROMPT=0 means a credential problem fails fast instead
# of hanging the upgrade on a silent username/password prompt.
GIT_TERMINAL_PROMPT=0 git fetch --tags --force
LATEST_TAG="$(git tag --sort=-creatordate | head -n1)"
if [ -z "$LATEST_TAG" ]; then
echo "No tags found in this repo — nothing to deploy." \
"Cut and push a release tag first (e.g. git tag v$(date +%Y.%m.%d) && git push --tags)." >&2
exit 1
fi
CURRENT_REF="$(sudo -u "$EVECTION_USER" -H git describe --tags --exact-match 2>/dev/null || echo "none")"
CURRENT_REF="$(git describe --tags --exact-match 2>/dev/null || echo "none")"
if [ "$CURRENT_REF" = "$LATEST_TAG" ]; then
echo "Already on the latest tag ($LATEST_TAG) — nothing to do."
exit 0
@@ -61,7 +69,20 @@ fi
echo "Deploying $LATEST_TAG (currently on: $CURRENT_REF)"
# Detached HEAD, not a branch checkout — this directory only ever runs a
# tagged release, never whatever the default branch's tip happens to be.
sudo -u "$EVECTION_USER" -H git checkout --quiet --detach "$LATEST_TAG"
git checkout --quiet --detach "$LATEST_TAG"
chown -R "$EVECTION_USER:$EVECTION_USER" "$APP_DIR"
# Bump the PWA's cache-busting version to this release's tag on every
# deploy, not just ones that happened to touch static assets — a missed
# manual bump otherwise leaves installed PWAs serving a stale cached
# shell/pages indefinitely. Cheap even when nothing cacheable changed:
# it just makes the service worker open a fresh cache name next time it
# activates.
if grep -q '^EVECTION_PWA_CACHE_VERSION=' "$APP_DIR/.env"; then
sed -i "s/^EVECTION_PWA_CACHE_VERSION=.*/EVECTION_PWA_CACHE_VERSION=$LATEST_TAG/" "$APP_DIR/.env"
else
echo "EVECTION_PWA_CACHE_VERSION=$LATEST_TAG" >> "$APP_DIR/.env"
fi
echo "==> Installing updated dependencies"
sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --upgrade "$APP_DIR"
@@ -89,7 +110,30 @@ fi
echo "==> Verifying"
sleep 2
if curl -sf --unix-socket "$SOCKET" http://localhost/health/ >/dev/null; then
# gunicorn always listens on a plain TCP address (EVECTION_GUNICORN_BIND in
# .env, set by scripts/install.sh) rather than a Unix socket, since the
# reverse proxy in front of it may be on a different host entirely — see
# docs/install.md. 0.0.0.0 isn't a valid address to connect *to*, so check
# against localhost in that case; this health check only needs to prove
# gunicorn itself is answering on this host, not reach it the way the
# proxy does.
HEALTH_BIND="$(grep -m1 '^EVECTION_GUNICORN_BIND=' "$APP_DIR/.env" | cut -d= -f2-)"
HEALTH_BIND="${HEALTH_BIND:-127.0.0.1:8000}"
HEALTH_HOST="${HEALTH_BIND%:*}"
HEALTH_PORT="${HEALTH_BIND##*:}"
if [ "$HEALTH_HOST" = "0.0.0.0" ]; then
HEALTH_HOST="127.0.0.1"
fi
# Use the venv's own Python rather than curl — curl isn't guaranteed to be
# installed on a minimal host, but the venv obviously already is.
if "$VENV_DIR/bin/python" -c "
import sys, urllib.request
try:
urllib.request.urlopen('http://$HEALTH_HOST:$HEALTH_PORT/health/', timeout=5)
except Exception as e:
print(e, file=sys.stderr)
sys.exit(1)
"; then
echo "Health check OK"
else
echo "Health check FAILED — check: journalctl -u evection-gunicorn -n 50" >&2
@@ -99,7 +143,4 @@ systemctl status evection-gunicorn --no-pager -l | head -10
echo
echo "==> Deployed $LATEST_TAG."
echo " If this release changed cached static assets (CSS/JS/icons), bump"
echo " EVECTION_PWA_CACHE_VERSION in $APP_DIR/.env and restart evection-gunicorn"
echo " again so installed PWAs drop their old cache instead of serving stale assets."
echo " journalctl -u evection-gunicorn -f to watch logs."
+7 -1
View File
@@ -300,12 +300,18 @@ form p {
}
.sidebar-tag-link {
display: inline-block;
padding: 0.15rem 0.4rem;
margin: -0.15rem -0.4rem;
border-radius: 0.375rem;
color: inherit;
text-decoration: none;
}
.sidebar-tag-link.active {
color: var(--accent);
background: var(--bg-row-selected);
color: var(--text);
font-weight: 600;
}
.sidebar-item-list {
+15 -1
View File
@@ -66,8 +66,23 @@ async function cacheFirstForAsset(request) {
return response;
}
const LOGOUT_PATH = "{% url 'accounts:logout' %}";
self.addEventListener("fetch", (event) => {
const { request } = event;
const url = new URL(request.url);
// Logging out ends this device's session, so any authenticated HTML
// sitting in PAGES_CACHE must not outlive it — otherwise a later
// offline navigation (shared device, different account logging in
// next) could still serve a previous user's cached article pages.
// Purging it synchronously with the logout request itself, rather
// than via a postMessage from the page, means there's no race with
// the navigation that follows.
if (request.method === "POST" && url.pathname === LOGOUT_PATH) {
event.respondWith(caches.delete(PAGES_CACHE).then(() => fetch(request)));
return;
}
// Mutations (mark-read, star, OPML upload, forms...) are always
// network-only — never intercept anything but GET.
@@ -78,7 +93,6 @@ self.addEventListener("fetch", (event) => {
return;
}
const url = new URL(request.url);
if (url.pathname.startsWith("/static/")) {
event.respondWith(cacheFirstForAsset(request));
}