systemd management scripts
This commit is contained in:
13
scripts/edit.sh
Executable file
13
scripts/edit.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
# Open the alarm config in an editor, then restart the service.
|
||||
set -euo pipefail
|
||||
|
||||
PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
CONFIG="${PROJECT_DIR}/config/alarms.json"
|
||||
|
||||
${EDITOR:-nano} "${CONFIG}"
|
||||
|
||||
echo "==> Restarting pi-dashboard service..."
|
||||
sudo systemctl restart pi-dashboard
|
||||
|
||||
echo "==> Done. Check status with: systemctl status pi-dashboard"
|
||||
20
scripts/remove.sh
Executable file
20
scripts/remove.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# Stop, disable, and remove the pi-dashboard systemd service.
|
||||
set -euo pipefail
|
||||
|
||||
SERVICE_NAME="pi-dashboard"
|
||||
UNIT_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
|
||||
|
||||
echo "==> Stopping ${SERVICE_NAME}..."
|
||||
sudo systemctl stop "${SERVICE_NAME}" || true
|
||||
|
||||
echo "==> Disabling ${SERVICE_NAME}..."
|
||||
sudo systemctl disable "${SERVICE_NAME}" || true
|
||||
|
||||
echo "==> Removing unit file..."
|
||||
sudo rm -f "${UNIT_FILE}"
|
||||
|
||||
echo "==> Reloading systemd..."
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
echo "==> Done. Service removed."
|
||||
40
scripts/setup.sh
Executable file
40
scripts/setup.sh
Executable 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}"
|
||||
Reference in New Issue
Block a user