install-as-systemd.sh 975 B

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