install-as-systemd.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # Please note that this script expects `slskd-permission-monitor.sh` to be copied into `/usr/local/bin/`
  3. set -e
  4. SERVICE_NAME="slskd-permission-monitor"
  5. SERVICE_PATH="/etc/systemd/system/${SERVICE_NAME}.service"
  6. SCRIPT_PATH="/usr/local/bin/slskd-permission-monitor.sh"
  7. # Check if running as root
  8. if [ "$(id -u)" -ne 0 ]; then
  9. echo "This script must be run as root." >&2
  10. exit 1
  11. fi
  12. # Create the service file
  13. cat > "$SERVICE_PATH" <<EOF
  14. [Unit]
  15. Description=SLSKD Permissions Monitor
  16. After=network.target
  17. After=docker.service
  18. Wants=docker.service
  19. [Service]
  20. Type=simple
  21. ExecStart=$SCRIPT_PATH
  22. Restart=on-failure
  23. RestartSec=10s
  24. KillSignal=SIGINT
  25. TimeoutStopSec=20s
  26. StandardOutput=journal
  27. StandardError=journal
  28. # Security hardening (since we need to run as root)
  29. ProtectSystem=full
  30. PrivateTmp=true
  31. NoNewPrivileges=true
  32. [Install]
  33. WantedBy=multi-user.target
  34. EOF
  35. # Reload systemd, enable and start the service
  36. systemctl daemon-reexec
  37. systemctl daemon-reload
  38. systemctl enable --now "$SERVICE_NAME"
  39. echo "**Service '$SERVICE_NAME' installed and started successfully.**"