Files
Enigma-Synology-Monitor/deploy.sh

57 lines
2.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# deploy.sh Install & start the Synology Monitor on a Linux/VPS server
# Usage: sudo bash deploy.sh
# ─────────────────────────────────────────────────────────────────────────────
set -euo pipefail
INSTALL_DIR="/opt/synology-monitor"
SERVICE_USER="monitor"
SERVICE_FILE="synology-monitor.service"
echo "=== Synology Monitor Deployment ==="
# 1. Create a dedicated system user (no login shell)
if ! id "$SERVICE_USER" &>/dev/null; then
echo "[+] Creating system user: $SERVICE_USER"
sudo useradd --system --no-create-home --shell /usr/sbin/nologin "$SERVICE_USER"
fi
# 2. Copy files to install directory
echo "[+] Installing files to $INSTALL_DIR"
sudo mkdir -p "$INSTALL_DIR"
sudo cp monitor.py requirements.txt "$INSTALL_DIR/"
# 3. Create .env from example (if not already present)
if [ ! -f "$INSTALL_DIR/.env" ]; then
echo "[+] Copying .env.example → $INSTALL_DIR/.env"
sudo cp .env.example "$INSTALL_DIR/.env"
echo " ⚠️ Edit $INSTALL_DIR/.env before starting the service!"
fi
# 4. Set up Python virtual environment
echo "[+] Creating Python virtual environment"
sudo python3 -m venv "$INSTALL_DIR/venv"
sudo "$INSTALL_DIR/venv/bin/pip" install --quiet --upgrade pip
sudo "$INSTALL_DIR/venv/bin/pip" install --quiet -r "$INSTALL_DIR/requirements.txt"
# 5. Fix permissions
sudo chown -R "$SERVICE_USER":"$SERVICE_USER" "$INSTALL_DIR"
sudo chmod 600 "$INSTALL_DIR/.env"
# 6. Install and enable systemd service
echo "[+] Installing systemd service"
sudo cp "$SERVICE_FILE" /etc/systemd/system/
sudo systemd-analyze verify /etc/systemd/system/"$SERVICE_FILE" || true
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_FILE"
echo ""
echo "=== Deployment complete ==="
echo ""
echo "NEXT STEPS:"
echo " 1. Edit credentials: sudo nano $INSTALL_DIR/.env"
echo " 2. Start the service: sudo systemctl start synology-monitor"
echo " 3. View logs: sudo journalctl -u synology-monitor -f"
echo ""