Compare commits

...
Author SHA1 Message Date
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
3 changed files with 48 additions and 12 deletions

No files matched your search

+5 -3
View File
@@ -55,7 +55,8 @@ and 4 below first — prerequisites and what `.env` controls.
## 1. Prerequisites ## 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) - Redis (Celery's broker)
- **Postgres only**: a PostgreSQL server (12+) and its client headers if you're not - **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, using the bundled `psycopg[binary]` wheel (most platforms are covered by the wheel,
@@ -63,10 +64,11 @@ and 4 below first — prerequisites and what `.env` controls.
- nginx (or another reverse proxy) - nginx (or another reverse proxy)
- A domain name pointed at the host, if you want this reachable outside your LAN - A domain name pointed at the host, 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 ```bash
sudo apt install redis-server nginx sudo apt install redis-server nginx python3.13-venv
# Postgres only: # Postgres only:
sudo apt install postgresql sudo apt install postgresql
``` ```
+29 -5
View File
@@ -26,6 +26,13 @@ VENV_DIR="$EVECTION_HOME/venv"
EVECTION_USER="${EVECTION_USER:-evection}" EVECTION_USER="${EVECTION_USER:-evection}"
PYTHON_BIN="${PYTHON_BIN:-python3}" 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 "==> Installing Evection"
echo " App directory: $APP_DIR" echo " App directory: $APP_DIR"
echo " Service user: $EVECTION_USER" echo " Service user: $EVECTION_USER"
@@ -45,6 +52,11 @@ 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 echo "Python $PY_VERSION found, but Evection needs 3.11 or newer." >&2
exit 1 exit 1
fi fi
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
for bin in redis-cli nginx; do for bin in redis-cli nginx; do
if ! command -v "$bin" >/dev/null 2>&1; then if ! command -v "$bin" >/dev/null 2>&1; then
@@ -61,23 +73,35 @@ if ! id -u "$EVECTION_USER" >/dev/null 2>&1; then
else else
echo "==> System user '$EVECTION_USER' already exists" echo "==> System user '$EVECTION_USER' already exists"
fi fi
chown -R "$EVECTION_USER:$EVECTION_USER" "$APP_DIR"
# --- 2b. Pin to the latest release tag (if any exist) ---------------- # --- 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 if [ -d "$APP_DIR/.git" ]; then
sudo -u "$EVECTION_USER" -H git -C "$APP_DIR" fetch --tags --force || true GIT_TERMINAL_PROMPT=0 git -C "$APP_DIR" fetch --tags --force || true
LATEST_TAG="$(sudo -u "$EVECTION_USER" -H git -C "$APP_DIR" tag --sort=-creatordate | head -n1)" LATEST_TAG="$(git -C "$APP_DIR" tag --sort=-creatordate | head -n1)"
if [ -n "$LATEST_TAG" ]; then if [ -n "$LATEST_TAG" ]; then
echo "==> Checking out latest release: $LATEST_TAG" echo "==> Checking out latest release: $LATEST_TAG"
# Detached HEAD, not a branch checkout — matches scripts/upgrade.sh, # Detached HEAD, not a branch checkout — matches scripts/upgrade.sh,
# which only ever deploys a tagged release, never a branch tip. # 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 else
echo "==> No release tags found yet — staying on whatever's currently checked out." echo "==> No release tags found yet — staying on whatever's currently checked out."
fi fi
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 --------------------------------------------- # --- 3. Virtualenv + install ---------------------------------------------
if [ ! -d "$VENV_DIR" ]; then if [ ! -d "$VENV_DIR" ]; then
+14 -4
View File
@@ -28,6 +28,11 @@ VENV_DIR="$EVECTION_HOME/venv"
EVECTION_USER="${EVECTION_USER:-evection}" EVECTION_USER="${EVECTION_USER:-evection}"
SOCKET="/run/evection/gunicorn.sock" 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 if ! id -u "$EVECTION_USER" >/dev/null 2>&1; then
echo "System user '$EVECTION_USER' doesn't exist — is Evection installed?" \ echo "System user '$EVECTION_USER' doesn't exist — is Evection installed?" \
"Run scripts/install.sh first." >&2 "Run scripts/install.sh first." >&2
@@ -46,14 +51,18 @@ fi
echo "==> Fetching latest release" echo "==> Fetching latest release"
cd "$APP_DIR" cd "$APP_DIR"
sudo -u "$EVECTION_USER" -H git fetch --tags --force # Run git as root (this script already requires it), not as $EVECTION_USER:
LATEST_TAG="$(sudo -u "$EVECTION_USER" -H git tag --sort=-creatordate | head -n1)" # 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 if [ -z "$LATEST_TAG" ]; then
echo "No tags found in this repo — nothing to deploy." \ 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 "Cut and push a release tag first (e.g. git tag v$(date +%Y.%m.%d) && git push --tags)." >&2
exit 1 exit 1
fi 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 if [ "$CURRENT_REF" = "$LATEST_TAG" ]; then
echo "Already on the latest tag ($LATEST_TAG) — nothing to do." echo "Already on the latest tag ($LATEST_TAG) — nothing to do."
exit 0 exit 0
@@ -61,7 +70,8 @@ fi
echo "Deploying $LATEST_TAG (currently on: $CURRENT_REF)" echo "Deploying $LATEST_TAG (currently on: $CURRENT_REF)"
# Detached HEAD, not a branch checkout — this directory only ever runs a # Detached HEAD, not a branch checkout — this directory only ever runs a
# tagged release, never whatever the default branch's tip happens to be. # 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"
echo "==> Installing updated dependencies" echo "==> Installing updated dependencies"
sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --upgrade "$APP_DIR" sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --upgrade "$APP_DIR"