systemd management scripts

This commit is contained in:
2026-02-17 12:13:39 +09:00
parent 60d99a993f
commit af7fb2beaf
4 changed files with 108 additions and 22 deletions

40
scripts/setup.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/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 "==> Installing Python dependencies..."
uv pip install -r "${PROJECT_DIR}/requirements.txt"
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}"