fix(update): wipe DB on update, bootstrap from Authelia, don't touch Authelia service
This commit is contained in:
parent
583e1a5eea
commit
cb4eb38289
1 changed files with 12 additions and 6 deletions
18
update.sh
18
update.sh
|
|
@ -1,19 +1,22 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# NextWks — Production Update Script
|
# NextWks — Production Update Script
|
||||||
# Pulls latest code, rebuilds, restarts services
|
# Pulls latest code, rebuilds, restarts NextWks only.
|
||||||
|
# Users & auth are managed by Authelia (untouched).
|
||||||
# Run: cd /opt/nextwks && sudo bash update.sh
|
# Run: cd /opt/nextwks && sudo bash update.sh
|
||||||
# ============================================================
|
# ============================================================
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
GREEN='\033[0;32m'; BLUE='\033[0;34m'; NC='\033[0m'
|
GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[1;33m'; NC='\033[0m'
|
||||||
info() { echo -e "${BLUE}$1${NC}"; }
|
info() { echo -e "${BLUE}$1${NC}"; }
|
||||||
ok() { echo -e "${GREEN}$1${NC}"; }
|
ok() { echo -e "${GREEN}$1${NC}"; }
|
||||||
|
warn() { echo -e "${YELLOW}$1${NC}"; }
|
||||||
|
|
||||||
REPO_URL="https://git.lohmar.co.uk/lexton-it/NextWks.git"
|
REPO_URL="https://git.lohmar.co.uk/lexton-it/NextWks.git"
|
||||||
REPO_DIR="/tmp/nextwks-update"
|
REPO_DIR="/tmp/nextwks-update"
|
||||||
INSTALL_DIR="/opt/nextwks"
|
INSTALL_DIR="/opt/nextwks"
|
||||||
BIN_DIR="${INSTALL_DIR}/bin"
|
BIN_DIR="${INSTALL_DIR}/bin"
|
||||||
|
DATA_DIR="${INSTALL_DIR}/data"
|
||||||
|
|
||||||
info "Updating NextWks..."
|
info "Updating NextWks..."
|
||||||
|
|
||||||
|
|
@ -21,7 +24,6 @@ info "Updating NextWks..."
|
||||||
rm -rf "$REPO_DIR" 2>/dev/null
|
rm -rf "$REPO_DIR" 2>/dev/null
|
||||||
git clone --depth 1 "$REPO_URL" "$REPO_DIR" --quiet
|
git clone --depth 1 "$REPO_URL" "$REPO_DIR" --quiet
|
||||||
|
|
||||||
# Read new version
|
|
||||||
VERSION=$(cat "$REPO_DIR/VERSION" 2>/dev/null || echo "dev")
|
VERSION=$(cat "$REPO_DIR/VERSION" 2>/dev/null || echo "dev")
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
|
|
@ -32,19 +34,23 @@ go build -ldflags="-s -w \
|
||||||
-X git.lohmar.co.uk/lexton-it/NextWks/core/version.CommitSHA=$(git rev-parse --short HEAD)" \
|
-X git.lohmar.co.uk/lexton-it/NextWks/core/version.CommitSHA=$(git rev-parse --short HEAD)" \
|
||||||
-o /tmp/nextwks-core .
|
-o /tmp/nextwks-core .
|
||||||
|
|
||||||
# Replace
|
# Stop, wipe data, replace, restart
|
||||||
systemctl stop nextwks
|
systemctl stop nextwks
|
||||||
|
warn "Wiping NextWks database (users restored from Authelia on boot)"
|
||||||
|
find "$DATA_DIR" -name "*.db*" -delete 2>/dev/null || true
|
||||||
cp /tmp/nextwks-core "$BIN_DIR/core"
|
cp /tmp/nextwks-core "$BIN_DIR/core"
|
||||||
chmod 755 "$BIN_DIR/core"
|
chmod 755 "$BIN_DIR/core"
|
||||||
chown nextwks:nextwks "$BIN_DIR/core"
|
chown nextwks:nextwks "$BIN_DIR/core"
|
||||||
|
chown -R nextwks:nextwks "$DATA_DIR" 2>/dev/null || true
|
||||||
systemctl start nextwks
|
systemctl start nextwks
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
# Verify
|
# Verify
|
||||||
if curl -s --max-time 3 http://localhost:8080/api/health | grep -q ok; then
|
if curl -s --max-time 3 http://localhost:8080/api/health | grep -q ok; then
|
||||||
ok "Updated to v${VERSION}"
|
ok "NextWks updated to v${VERSION}"
|
||||||
|
info "Users bootstrapped from Authelia"
|
||||||
else
|
else
|
||||||
echo "Health check failed — check journalctl -u nextwks"
|
echo "Health check failed — check: sudo journalctl -u nextwks -n 20"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue