Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(install/update/uninstall): robust lifecycle + masthead + schedule_card guard

Juan Denisd951a2026476
diff --git a/frontend/src/components/backups/ScheduleCard.jsx b/frontend/src/components/backups/ScheduleCard.jsx
index bfb6c3be..5d73c04c 100644
--- a/frontend/src/components/backups/ScheduleCard.jsx
+++ b/frontend/src/components/backups/ScheduleCard.jsx
@@ -81,6 +81,20 @@ function buildCron(frequency, time, days) {
}
const ScheduleCard = ({ policy, remoteConfigured, onSave, saving }) => {
+ if (!policy) {
+ return (
+ <div className="app-panel schedule-card">
+ <div className="app-panel-header">
+ <Calendar size={16} />
+ <span>Schedule</span>
+ </div>
+ <div className="app-panel-body">
+ <p className="app-panel-hint">Loading backup schedule...</p>
+ </div>
+ </div>
+ );
+ }
+
const initial = deriveFromCron(policy.schedule_cron);
const [frequency, setFrequency] = useState(initial.frequency);
diff --git a/install.sh b/install.sh
index ec1c4291..499ee8bb 100644
--- a/install.sh
+++ b/install.sh
@@ -428,6 +428,22 @@ fetch_release() {
mkdir -p "$(dirname "$INSTALL_DIR")"
tar xzf "$tarball" -C "$(dirname "$INSTALL_DIR")"
rm -f "$tarball"
+
+ # Normalize tarball layout: older archives have serverkit/ at root,
+ # newer ones have opt/serverkit/.
+ UNPACKED_DIR="$(dirname "$INSTALL_DIR")/serverkit"
+ if [ ! -d "$UNPACKED_DIR" ]; then
+ UNPACKED_DIR="$(dirname "$INSTALL_DIR")/opt/serverkit"
+ fi
+ if [ ! -d "$UNPACKED_DIR" ]; then
+ UNPACKED_DIR=$(find "$(dirname "$INSTALL_DIR")" -maxdepth 2 -type d -name serverkit | head -n1)
+ fi
+ [ -d "$UNPACKED_DIR" ] || halt "Release tarball layout is unrecognized (expected serverkit/ or opt/serverkit/)."
+ if [ "$UNPACKED_DIR" != "$INSTALL_DIR" ]; then
+ mv "$UNPACKED_DIR" "$INSTALL_DIR"
+ fi
+ chmod +x "$INSTALL_DIR/serverkit"
+ chmod +x "$INSTALL_DIR/scripts/"*.sh 2>/dev/null || true
good "Release unpacked into $INSTALL_DIR"
}
diff --git a/scripts/update.sh b/scripts/update.sh
index 944d73dc..170f5bf3 100644
--- a/scripts/update.sh
+++ b/scripts/update.sh
@@ -12,6 +12,24 @@
#
set -euo pipefail
+# ---------------------------------------------------------------------------
+# Automatic rollback on release swap failure
+# ---------------------------------------------------------------------------
+cleanup_on_failure() {
+ local rc=$?
+ [ "$rc" -eq 0 ] && return 0
+ if [ ! -d "$INSTALL_DIR" ] && [ -d "$INSTALL_DIR.old" ]; then
+ warn "Update failed (exit $rc) — restoring previous installation..."
+ mv "$INSTALL_DIR.old" "$INSTALL_DIR"
+ systemctl daemon-reload 2>/dev/null || true
+ systemctl start "$BACKEND_SERVICE" 2>/dev/null || true
+ systemctl start nginx 2>/dev/null || true
+ warn "Rollback complete. Inspect logs: journalctl -u serverkit -n 50"
+ fi
+ return "$rc"
+}
+trap cleanup_on_failure EXIT
+
# ---------------------------------------------------------------------------
# Terminal styling (violet ServerKit identity, degrades to plain text)
# ---------------------------------------------------------------------------
@@ -69,12 +87,29 @@ BACKEND_SERVICE="serverkit"
# ---------------------------------------------------------------------------
# Pick install mode: release tarball vs. source tree
# ---------------------------------------------------------------------------
-if [ "$INSTALL_FROM_RELEASE" != "1" ] && [ ! -d "$INSTALL_DIR/backend/src" ]; then
- step "No source tree found — switching to release download."
- INSTALL_FROM_RELEASE=1
-fi
+# Default workflow: dev branch -> PR to main -> `serverkit update` on server.
+# So unless the operator explicitly asks for a release tarball, we always pull
+# the latest main source and rebuild. If the install came from a release
+# tarball (no .git), we convert it to a shallow git checkout so future updates
+# track main directly.
[ "$BUILD_FROM_SOURCE" = "1" ] && INSTALL_FROM_RELEASE=0
+if [ "$INSTALL_FROM_RELEASE" != "1" ] && [ ! -d "$INSTALL_DIR/.git" ]; then
+ step "No source tree found — converting install to a git checkout from main..."
+ tmp_env=$(mktemp)
+ tmp_db=$(mktemp)
+ cp "$INSTALL_DIR/.env" "$tmp_env" 2>/dev/null || true
+ cp "$INSTALL_DIR/backend/instance/serverkit.db" "$tmp_db" 2>/dev/null || true
+ rm -rf "$INSTALL_DIR"
+ git clone --depth 1 --branch main "https://github.com/${GITHUB_REPO}.git" "$INSTALL_DIR" \
+ || halt "Failed to clone ${GITHUB_REPO}.git"
+ cp "$tmp_env" "$INSTALL_DIR/.env" 2>/dev/null || true
+ mkdir -p "$INSTALL_DIR/backend/instance"
+ cp "$tmp_db" "$INSTALL_DIR/backend/instance/serverkit.db" 2>/dev/null || true
+ rm -f "$tmp_env" "$tmp_db"
+ step "Source tree cloned from main."
+fi
+
# ---------------------------------------------------------------------------
# Self-refresh: replace this script with the release copy and re-exec, so an
# old updater can't drive a new release. Runs once (guarded by SELF_REFRESHED)
@@ -247,23 +282,60 @@ if [ "$INSTALL_FROM_RELEASE" = "1" ]; then
tar xzf "$TARBALL" -C "$STAGE"
rm -f "$TARBALL"
+ # Locate the unpacked tree. Older tarballs have a top-level `serverkit/`
+ # directory; newer ones use `opt/serverkit/` (matches the archive prefix).
+ UNPACKED_DIR="$STAGE/serverkit"
+ if [ ! -d "$UNPACKED_DIR" ]; then
+ UNPACKED_DIR="$STAGE/opt/serverkit"
+ fi
+ if [ ! -d "$UNPACKED_DIR" ]; then
+ UNPACKED_DIR=$(find "$STAGE" -maxdepth 2 -type d -name serverkit | head -n1)
+ fi
+ [ -d "$UNPACKED_DIR" ] || halt "Release tarball layout is unrecognized (expected serverkit/ or opt/serverkit/)."
+
+ # Ensure the instance directory exists before copying the live database.
+ mkdir -p "$UNPACKED_DIR/backend/instance"
+
# Carry the live .env and database across.
- cp "$INSTALL_DIR/.env" "$STAGE/serverkit/.env" 2>/dev/null || true
+ cp "$INSTALL_DIR/.env" "$UNPACKED_DIR/.env" 2>/dev/null || true
cp "$INSTALL_DIR/backend/instance/serverkit.db" \
- "$STAGE/serverkit/backend/instance/serverkit.db" 2>/dev/null || true
+ "$UNPACKED_DIR/backend/instance/serverkit.db" 2>/dev/null || true
+
+ # Remove any stale backup from a previous failed/interrupted update so
+ # mv doesn't try to overwrite a file/non-directory with a directory.
+ if [ -e "$INSTALL_DIR.old" ]; then
+ rm -rf "$INSTALL_DIR.old"
+ fi
mv "$INSTALL_DIR" "$INSTALL_DIR.old"
- mv "$STAGE/serverkit" "$INSTALL_DIR"
+ mv "$UNPACKED_DIR" "$INSTALL_DIR"
rm -rf "$STAGE"
+
+ # Release tarballs don't always preserve executable bits.
+ chmod +x "$INSTALL_DIR/serverkit"
+ chmod +x "$INSTALL_DIR/scripts/"*.sh 2>/dev/null || true
good "Release deployed."
# Release tarballs no longer include a pre-built venv (the absolute paths
# break on the target). Rebuild it locally from requirements.txt.
rebuild_virtualenv
+
+ # Release tarballs also don't ship pre-built frontend assets, and the
+ # docker-compose volume mount requires the dist/ tree on the host.
+ step "Rebuilding the frontend..."
+ cd "$INSTALL_DIR/frontend"
+ npm ci --prefer-offline 2>&1 | tail -3
+ NODE_OPTIONS="--max-old-space-size=1024" npm run build 2>&1 | tail -5
+ good "Frontend built."
else
phase "Updating Source"
cd "$INSTALL_DIR"
+ step "Pulling latest main from GitHub..."
+ git fetch origin
+ git reset --hard origin/main
+ good "Source updated to origin/main."
+
chmod +x "$INSTALL_DIR/serverkit"
chmod +x "$INSTALL_DIR/scripts/"*.sh 2>/dev/null || true
@@ -373,7 +445,10 @@ good "Configuration refreshed."
phase "Starting Services"
systemctl start "$BACKEND_SERVICE"
cd "$INSTALL_DIR"
-docker compose up -d 2>&1 | tail -5
+# Recreate the frontend container so its bind mount follows the current
+# frontend/dist inode (npm run build deletes and recreates the directory).
+docker compose up -d --force-recreate frontend 2>&1 | tail -5
+docker compose up -d backend 2>&1 | tail -5
systemctl start nginx
good "Services started."
diff --git a/serverkit b/serverkit
index db00100b..d3e3fe4e 100644
--- a/serverkit
+++ b/serverkit
@@ -18,6 +18,21 @@ YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
+# Truecolor ServerKit identity (degrades to plain text when not supported)
+if [ -t 1 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-dumb}" != "dumb" ]; then
+ ESC=$'\033'
+ RST_TC="${ESC}[0m"; BLD_TC="${ESC}[1m"
+ paint() { printf '%s[38;2;%d;%d;%dm' "$ESC" "$1" "$2" "$3"; }
+else
+ RST_TC=''; BLD_TC=''
+ paint() { :; }
+fi
+
+V1="$(paint 196 181 253)"; V2="$(paint 167 139 250)"; V3="$(paint 139 92 246)"
+V4="$(paint 124 58 237)"; V5="$(paint 109 40 217)"
+PAPER_TC="$(paint 237 233 254)"; ASH_TC="$(paint 165 160 190)"; FOG_TC="$(paint 113 108 140)"
+HUE_OK_TC="$(paint 52 211 153)"; HUE_WARN_TC="$(paint 250 204 21)"; HUE_ERR_TC="$(paint 248 113 113)"; HUE_LINK_TC="$(paint 103 232 249)"
+
# Configuration
INSTALL_DIR="${SERVERKIT_DIR:-/opt/serverkit}"
VENV_DIR="$INSTALL_DIR/venv"
@@ -26,9 +41,19 @@ FRONTEND_CONTAINER="serverkit-frontend"
# Helper functions
print_header() {
- echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
- echo -e "${BLUE} ServerKit CLI${NC}"
- echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
+ local ver
+ ver=$(get_local_version 2>/dev/null || echo "unknown")
+ printf '\n'
+ printf ' %s%s▖▌▌%s %s%sServerKit%s %sv%s%s %s•%s %s%s%s\n' \
+ "${BLD_TC}" "${V2}" "${RST_TC}" "${BLD_TC}" "${PAPER_TC}" "${RST_TC}" "${FOG_TC}" "$ver" "${RST_TC}" \
+ "${HUE_OK_TC}" "${RST_TC}" "${ASH_TC}" "Stable" "${RST_TC}"
+ printf ' %s%s▌▖▌%s %sSelf-hosted infrastructure, made simple.%s\n' \
+ "${BLD_TC}" "${V3}" "${RST_TC}" "${ASH_TC}" "${RST_TC}"
+ printf ' %s%s▌▌▖%s %sWeb apps · Databases · Docker · Email · DNS · Security%s\n' \
+ "${BLD_TC}" "${V4}" "${RST_TC}" "${FOG_TC}" "${RST_TC}"
+ printf ' %s%s▘▘▘%s %sPython + React, one command · serverkit.ai%s\n' \
+ "${BLD_TC}" "${V5}" "${RST_TC}" "${FOG_TC}" "${RST_TC}"
+ printf '\n'
}
print_success() { echo -e "${GREEN}✓ $1${NC}"; }
diff --git a/uninstall.sh b/uninstall.sh
index c2440d2b..1bb9104c 100644
--- a/uninstall.sh
+++ b/uninstall.sh
@@ -23,16 +23,39 @@ YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
+# Truecolor ServerKit identity (degrades to plain text when not supported)
+if [ -t 1 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-dumb}" != "dumb" ]; then
+ ESC=$'\033'
+ RST_TC="${ESC}[0m"; BLD_TC="${ESC}[1m"
+ paint() { printf '%s[38;2;%d;%d;%dm' "$ESC" "$1" "$2" "$3"; }
+else
+ RST_TC=''; BLD_TC=''
+ paint() { :; }
+fi
+
+V1="$(paint 196 181 253)"; V2="$(paint 167 139 250)"; V3="$(paint 139 92 246)"
+V4="$(paint 124 58 237)"; V5="$(paint 109 40 217)"
+PAPER_TC="$(paint 237 233 254)"; ASH_TC="$(paint 165 160 190)"; FOG_TC="$(paint 113 108 140)"
+HUE_OK_TC="$(paint 52 211 153)"; HUE_WARN_TC="$(paint 250 204 21)"; HUE_ERR_TC="$(paint 248 113 113)"; HUE_LINK_TC="$(paint 103 232 249)"
+
########################################
# UI helpers
########################################
print_header() {
- echo -e "${BLUE}"
- echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- echo " ServerKit Uninstaller"
- echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- echo -e "${NC}"
+ local ver="unknown"
+ [ -f "${INSTALL_DIR}/VERSION" ] && ver=$(tr -d '\r\n ' < "${INSTALL_DIR}/VERSION")
+ printf '\n'
+ printf ' %s%s▖▌▌%s %s%sServerKit%s %sv%s%s %s•%s %sUninstaller%s\n' \
+ "${BLD_TC}" "${V2}" "${RST_TC}" "${BLD_TC}" "${PAPER_TC}" "${RST_TC}" "${FOG_TC}" "$ver" "${RST_TC}" \
+ "${HUE_WARN_TC}" "${RST_TC}" "${ASH_TC}" "${RST_TC}"
+ printf ' %s%s▌▖▌%s %sSelf-hosted infrastructure, made simple.%s\n' \
+ "${BLD_TC}" "${V3}" "${RST_TC}" "${ASH_TC}" "${RST_TC}"
+ printf ' %s%s▌▌▖%s %sWeb apps · Databases · Docker · Email · DNS · Security%s\n' \
+ "${BLD_TC}" "${V4}" "${RST_TC}" "${FOG_TC}" "${RST_TC}"
+ printf ' %s%s▘▘▘%s %sPython + React, one command · serverkit.ai%s\n' \
+ "${BLD_TC}" "${V5}" "${RST_TC}" "${FOG_TC}" "${RST_TC}"
+ printf '\n'
}
print_success() { echo -e "${GREEN}✓ $1${NC}"; }