Private
Public Access
Keeps the traditional pip+systemd+nginx deployment (no Docker, per the original decision) but automates the manual steps already in docs/install.md instead of leaving them as copy-paste instructions: - scripts/install.sh: creates the system user, virtualenv, generates .env (auto SECRET_KEY, prompts for domain/SQLite-vs-Postgres — non-interactive via EVECTION_ALLOWED_HOSTS/EVECTION_DATABASE_URL/etc for scripted provisioning), migrates, collects static files, installs the systemd units (sed-substituted for the actual install path/user rather than hardcoded to /opt/evection), and optionally sets up nginx + certbot. Safe to re-run — skips what's already done rather than redoing it, and never overwrites an existing .env. - scripts/upgrade.sh: git pull, reinstall, migrate, collectstatic, restart whichever of the three services are actually present (handles the combined worker+beat deployment variant too). docs/install.md now leads with the script as the recommended path, with the existing step-by-step instructions kept below for anyone who wants to understand or customize what it's doing. Verified: shellcheck clean on both scripts (via a throwaway shellcheck-py venv, since neither apt nor pip --user were available non-interactively); the systemd-unit and nginx-config sed substitutions produce correct output against the real template files; the generated .env format round-trips through `manage.py check` under config.settings.prod without error. Did not actually run install.sh against a real system — that creates a system user and installs systemd units, which needs the person deploying it to run (and review) themselves. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
70 lines
2.4 KiB
Bash
Executable File
70 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Automates docs/install.md's "Upgrading" section: pull the latest code,
|
|
# reinstall dependencies, migrate, collect static files, restart services.
|
|
#
|
|
# Run as root, from inside an existing install:
|
|
# sudo ./scripts/upgrade.sh
|
|
#
|
|
# Requires scripts/install.sh (or the equivalent manual steps) to have
|
|
# been run already, and the app directory to be a git checkout — if you
|
|
# deploy from release tarballs instead, extract the new one over this
|
|
# directory yourself before running this script.
|
|
|
|
set -euo pipefail
|
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
echo "Run this as root: sudo ./scripts/upgrade.sh" >&2
|
|
exit 1
|
|
fi
|
|
|
|
APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
EVECTION_HOME="$(dirname "$APP_DIR")"
|
|
VENV_DIR="$EVECTION_HOME/venv"
|
|
EVECTION_USER="${EVECTION_USER:-evection}"
|
|
|
|
if ! id -u "$EVECTION_USER" >/dev/null 2>&1; then
|
|
echo "System user '$EVECTION_USER' doesn't exist — is Evection installed?" \
|
|
"Run scripts/install.sh first." >&2
|
|
exit 1
|
|
fi
|
|
if [ ! -x "$VENV_DIR/bin/python" ]; then
|
|
echo "No virtualenv found at $VENV_DIR — is Evection installed?" \
|
|
"Run scripts/install.sh first." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "==> Upgrading Evection in $APP_DIR"
|
|
|
|
if [ -d "$APP_DIR/.git" ]; then
|
|
echo "==> Pulling latest code"
|
|
sudo -u "$EVECTION_USER" -H git -C "$APP_DIR" pull --ff-only
|
|
else
|
|
echo "$APP_DIR isn't a git checkout — extract the new release over it" \
|
|
"yourself, then re-run this script to finish the upgrade." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "==> Installing updated dependencies"
|
|
sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --upgrade "$APP_DIR"
|
|
|
|
echo "==> Running migrations"
|
|
sudo -u "$EVECTION_USER" -H env DJANGO_SETTINGS_MODULE=config.settings.prod \
|
|
"$VENV_DIR/bin/python" "$APP_DIR/manage.py" migrate --noinput
|
|
|
|
echo "==> Collecting static files"
|
|
sudo -u "$EVECTION_USER" -H env DJANGO_SETTINGS_MODULE=config.settings.prod \
|
|
"$VENV_DIR/bin/python" "$APP_DIR/manage.py" collectstatic --noinput
|
|
|
|
echo "==> Restarting services"
|
|
for unit in evection-gunicorn evection-celery-worker evection-celery-beat; do
|
|
if systemctl list-unit-files "${unit}.service" 2>/dev/null | grep -q "${unit}.service"; then
|
|
systemctl restart "$unit"
|
|
fi
|
|
done
|
|
|
|
echo
|
|
echo "==> Upgrade complete."
|
|
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."
|