Files
pi-dashboard-server/scripts/setup.sh
2026-02-17 12:18:13 +09:00

41 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Install dependencies, generate a systemd unit, and enable the pi-dashboard service.
set -euo pipefail
SERVICE_NAME="pi-dashboard"
PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
UNIT_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
RUN_USER="$(whoami)"
echo "==> Syncing Python dependencies..."
uv sync --project "${PROJECT_DIR}"
echo "==> Generating systemd unit file..."
cat > "/tmp/${SERVICE_NAME}.service" <<EOF
[Unit]
Description=Pi Dashboard WebSocket Servers
After=network-online.target docker.service
Wants=network-online.target docker.service
[Service]
Type=simple
User=${RUN_USER}
WorkingDirectory=${PROJECT_DIR}
ExecStart=$(command -v uv) run python run_all.py
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
echo "==> Installing unit file to ${UNIT_FILE}..."
sudo cp "/tmp/${SERVICE_NAME}.service" "${UNIT_FILE}"
rm "/tmp/${SERVICE_NAME}.service"
echo "==> Reloading systemd and enabling service..."
sudo systemctl daemon-reload
sudo systemctl enable --now "${SERVICE_NAME}"
echo "==> Done. Check status with: systemctl status ${SERVICE_NAME}"