167 lines
5.5 KiB
Bash
Executable file
167 lines
5.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# =============================================================================
|
|
# Upgrade auto-commit-service and restart services
|
|
# =============================================================================
|
|
# This script:
|
|
# 1. Stops the commits service
|
|
# 2. Upgrades Python dependencies
|
|
# 3. Ensures config files exist
|
|
# 4. Reloads systemd and restarts services
|
|
# 5. Records deployment for tracking
|
|
# =============================================================================
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
echo "==> Stopping commits service..."
|
|
systemctl --user stop commits.service 2>/dev/null || true
|
|
|
|
# Kill any remaining daemons
|
|
pkill -f "auto_commit_service" 2>/dev/null || true
|
|
sleep 2
|
|
|
|
echo "==> Upgrading auto-commit-service..."
|
|
pip install -e . --quiet --upgrade
|
|
|
|
echo "==> Ensuring model-boss coordinator is set up..."
|
|
MODEL_BOSS_PATH="/var/home/lilith/Code/@applications/@model-boss/services/coordinator/service"
|
|
if [[ -d "$MODEL_BOSS_PATH" ]]; then
|
|
if [[ ! -d "$MODEL_BOSS_PATH/.venv" ]]; then
|
|
echo " Creating model-boss-coordinator venv..."
|
|
python -m venv "$MODEL_BOSS_PATH/.venv"
|
|
fi
|
|
echo " Installing model-boss-coordinator dependencies..."
|
|
"$MODEL_BOSS_PATH/.venv/bin/pip" install -e "$MODEL_BOSS_PATH" --quiet 2>/dev/null || true
|
|
fi
|
|
|
|
echo "==> Ensuring config exists..."
|
|
mkdir -p ~/.config/commits
|
|
|
|
# Create startup-config.json if it doesn't exist
|
|
if [[ ! -f ~/.config/commits/startup-config.json ]]; then
|
|
echo " Creating startup-config.json..."
|
|
cat > ~/.config/commits/startup-config.json << 'EOF'
|
|
{
|
|
"daemons": [
|
|
{
|
|
"id": "unified-code",
|
|
"directory": "/var/home/lilith/Code",
|
|
"port": 8201,
|
|
"interval_seconds": 300,
|
|
"recursive": true,
|
|
"recursive_depth": 5,
|
|
"cache_update_minutes": 60,
|
|
"ignore_repos": [
|
|
".archive",
|
|
"_archive",
|
|
"egirl-platform",
|
|
".deprecated"
|
|
],
|
|
"exclude_patterns": [
|
|
"node_modules",
|
|
"pyvenv",
|
|
".venv",
|
|
"venv",
|
|
"dist",
|
|
"build",
|
|
"__pycache__"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
EOF
|
|
fi
|
|
|
|
echo "==> Ensuring systemd service is config-based..."
|
|
# Update commits.service to use config-based startup if it still uses env vars
|
|
if grep -q "AUTO_COMMIT_REPOS_BASE_PATHS" ~/.config/systemd/user/commits.service 2>/dev/null; then
|
|
echo " Updating commits.service to config-based..."
|
|
cat > ~/.config/systemd/user/commits.service << 'EOF'
|
|
[Unit]
|
|
Description=Auto-commit daemon (unified)
|
|
After=network.target llama-http.service model-boss-coordinator.service
|
|
Wants=llama-http.service model-boss-coordinator.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
WorkingDirectory=/var/home/lilith/Code
|
|
ExecStart=/var/home/lilith/Code/@applications/@ml/auto-commit-service/.venv/bin/python -m auto_commit_service
|
|
ExecStop=/var/home/lilith/.local/bin/commits stop
|
|
Restart=on-failure
|
|
RestartSec=30
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
# Minimal env - config loaded from ~/.config/commits/startup-config.json
|
|
Environment="PATH=/home/linuxbrew/.linuxbrew/bin:/var/home/lilith/.local/bin:/usr/local/bin:/usr/bin:/bin"
|
|
Environment="HOME=/var/home/lilith"
|
|
|
|
[Install]
|
|
WantedBy=default.target
|
|
EOF
|
|
fi
|
|
|
|
echo "==> Reloading systemd..."
|
|
systemctl --user daemon-reload
|
|
|
|
echo "==> Starting service chain..."
|
|
# Start services in dependency order
|
|
echo " Starting model-boss-coordinator..."
|
|
systemctl --user start model-boss-coordinator.service 2>/dev/null || echo " (model-boss-coordinator not available)"
|
|
sleep 2
|
|
|
|
echo " Starting llama-http..."
|
|
systemctl --user start llama-http.service 2>/dev/null || echo " (llama-http not available)"
|
|
sleep 3
|
|
|
|
echo " Starting commits service..."
|
|
systemctl --user start commits.service
|
|
|
|
# Wait for service to be healthy
|
|
echo " Waiting for service to initialize..."
|
|
sleep 5
|
|
|
|
# Get version info for deployment tracking
|
|
VERSION=$(grep -oP 'version\s*=\s*"\K[^"]+' pyproject.toml 2>/dev/null || echo "")
|
|
COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "")
|
|
|
|
# Get port from config
|
|
DAEMON_PORT=$(jq -r '.daemons[0].port // 8201' ~/.config/commits/startup-config.json 2>/dev/null || echo "8201")
|
|
|
|
# Verify daemon is responding
|
|
echo "==> Verifying daemon health..."
|
|
for i in {1..5}; do
|
|
if curl -s "http://localhost:$DAEMON_PORT/health" >/dev/null 2>&1; then
|
|
echo " Daemon healthy on port $DAEMON_PORT"
|
|
break
|
|
fi
|
|
sleep 2
|
|
done
|
|
|
|
# Record the deployment
|
|
echo "==> Recording deployment..."
|
|
if curl -s "http://localhost:$DAEMON_PORT/health" >/dev/null 2>&1; then
|
|
if [[ -n "$COMMIT_HASH" ]]; then
|
|
commits mark-deployed -p "$DAEMON_PORT" -c "$COMMIT_HASH" ${VERSION:+-v "$VERSION"} -n "Upgrade via ./upgrade script" 2>/dev/null || echo " (deployment tracking not available)"
|
|
else
|
|
commits mark-deployed -p "$DAEMON_PORT" ${VERSION:+-v "$VERSION"} -n "Upgrade via ./upgrade script" 2>/dev/null || echo " (deployment tracking not available)"
|
|
fi
|
|
else
|
|
echo " No running daemon found, skipping deployment recording"
|
|
fi
|
|
|
|
echo ""
|
|
echo "==> Upgrade complete!"
|
|
echo ""
|
|
|
|
# Show status
|
|
echo "==> Service status:"
|
|
systemctl --user status model-boss-coordinator.service --no-pager 2>/dev/null | head -5 || true
|
|
systemctl --user status llama-http.service --no-pager 2>/dev/null | head -5 || true
|
|
systemctl --user status commits.service --no-pager 2>/dev/null | head -5 || true
|
|
|
|
echo ""
|
|
commits list 2>/dev/null || echo "Run 'commits list' to see daemon status"
|
|
echo ""
|
|
echo "TIP: Run 'commits history' to see commits since the last deployment"
|