46 lines
1.2 KiB
Bash
Executable File
46 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Portable Systemd Service Installer for Chicken Counter Dashboard
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
CURRENT_USER="$(id -un)"
|
|
SERVICE_NAME="chicken-dashboard.service"
|
|
|
|
echo "=== Chicken Dashboard Service Installer ==="
|
|
echo "Target User: $CURRENT_USER"
|
|
echo "Project Dir: $SCRIPT_DIR"
|
|
|
|
# Check if user wants user-level systemd (no root required) or system-level systemd
|
|
USER_SERVICE_DIR="$HOME/.config/systemd/user"
|
|
mkdir -p "$USER_SERVICE_DIR"
|
|
|
|
cat <<EOF > "$USER_SERVICE_DIR/$SERVICE_NAME"
|
|
[Unit]
|
|
Description=Chicken Counter Live Dashboard
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
WorkingDirectory=$SCRIPT_DIR
|
|
ExecStart=$SCRIPT_DIR/start_dashboard.sh
|
|
Restart=always
|
|
RestartSec=5
|
|
Environment=PYTHONUNBUFFERED=1
|
|
Environment=PORT=8080
|
|
|
|
[Install]
|
|
WantedBy=default.target
|
|
EOF
|
|
|
|
echo ""
|
|
echo "✅ Installed user service to: $USER_SERVICE_DIR/$SERVICE_NAME"
|
|
echo ""
|
|
echo "To enable and start the dashboard service (runs on boot without sudo):"
|
|
echo " systemctl --user daemon-reload"
|
|
echo " systemctl --user enable --now $SERVICE_NAME"
|
|
echo " loginctl enable-linger $CURRENT_USER # Ensures service runs even if logged out"
|
|
echo ""
|
|
echo "To check status:"
|
|
echo " systemctl --user status $SERVICE_NAME"
|
|
echo ""
|