penta 1 mese fa
parent
commit
5ebdfafed1
1 ha cambiato i file con 63 aggiunte e 8 eliminazioni
  1. 63 8
      sunshine-entrypoint.sh

+ 63 - 8
sunshine-entrypoint.sh

@@ -65,24 +65,35 @@ EOF
 echo "Sunshine configuration:"
 cat "${HOME}/.config/sunshine/sunshine.conf"
 
-echo "Triggering input hotplug..."
-udevadm trigger --subsystem-match=input
-
 echo
 echo "Starting Sunshine..."
 /usr/bin/sunshine &
 SUNSHINE_PID=$!
 
+cleanup() {
+    echo "Stopping Sunshine..."
+    kill "${SUNSHINE_PID}" 2>/dev/null || true
+    wait "${SUNSHINE_PID}" 2>/dev/null || true
+
+    echo "Stopping supervisor..."
+    kill "${SUPERVISOR_PID}" 2>/dev/null || true
+    wait "${SUPERVISOR_PID}" 2>/dev/null || true
+}
+
+trap cleanup EXIT TERM INT
+
+echo
 echo "Waiting for Sunshine virtual input devices..."
 
 for i in $(seq 1 30); do
-    if grep -q 'Name="Mouse passthrough"' /proc/bus/input/devices; then
-        echo "Sunshine virtual input devices detected."
+    if grep -q 'Name="Mouse passthrough"' /proc/bus/input/devices \
+       && grep -q 'Name="Keyboard passthrough"' /proc/bus/input/devices; then
+        echo "Sunshine virtual mouse and keyboard detected."
         break
     fi
 
     if ! kill -0 "${SUNSHINE_PID}" 2>/dev/null; then
-        echo "ERROR: Sunshine exited."
+        echo "ERROR: Sunshine exited before creating input devices."
         wait "${SUNSHINE_PID}"
         exit $?
     fi
@@ -90,7 +101,51 @@ for i in $(seq 1 30); do
     sleep 1
 done
 
-echo "Triggering input hotplug..."
-udevadm trigger --subsystem-match=input
+echo
+echo "Restarting Xorg so it picks up Sunshine virtual input devices..."
+
+supervisorctl stop entrypoint || true
+
+pkill -TERM -x Xorg || true
+
+for i in $(seq 1 20); do
+    if ! pgrep -x Xorg >/dev/null; then
+        break
+    fi
+
+    sleep 0.5
+done
+
+if pgrep -x Xorg >/dev/null; then
+    echo "Xorg did not stop cleanly, sending SIGKILL..."
+    pkill -KILL -x Xorg || true
+    sleep 1
+fi
+
+echo "Starting desktop/Xorg again..."
+supervisorctl start entrypoint
+
+echo "Waiting for restarted Xorg..."
+
+for i in $(seq 1 60); do
+    if xdpyinfo -display "${DISPLAY}" >/dev/null 2>&1; then
+        echo "Restarted Xorg is ready."
+        break
+    fi
+
+    sleep 1
+done
+
+echo
+echo "Checking Sunshine input devices in Xorg log..."
+
+grep -Ei \
+    'Mouse passthrough|Keyboard passthrough|libinput' \
+    /home/ubuntu/.local/share/xorg/Xorg.20.log \
+    | tail -30 \
+    || true
+
+echo
+echo "Sunshine Gaming Desktop ready."
 
 wait "${SUNSHINE_PID}"