#!/bin/bash # RustDesk + XFCE Desktop Auto-Start for VPS # Systemd runs this script; script waits for Xvfb to exit set -e # Kill old pkill -9 -f rustdesk 2>/dev/null || true pkill -9 -f xfce4-session 2>/dev/null || true pkill -9 Xvfb 2>/dev/null || true rm -f /tmp/.X11-unix/X99 /tmp/.X*-lock sleep 2 # Start Xvfb :99 Xvfb :99 -screen 0 1920x1080x24 -ac +extension RANDR +extension RENDER +extension GLX > /dev/null 2>&1 & XVFB_PID=$! sleep 3 # Wait for display ready export DISPLAY=:99 export XAUTHORITY=/root/.Xauthority for i in $(seq 1 30); do xrandr --listmonitors > /dev/null 2>&1 && break if ! kill -0 $XVFB_PID 2>/dev/null; then echo "ERROR: Xvfb died" exit 1 fi sleep 1 done xrandr --listmonitors > /dev/null 2>&1 || { echo "ERROR: Display :99 not ready"; exit 1; } # Start XFCE desktop in background nohup dbus-run-session -- xfce4-session > /tmp/xfce-session.log 2>&1 & echo "XFCE PID: $!" sleep 5 # Wait for window manager for i in $(seq 1 20); do ps aux | grep xfwm4 | grep -v grep > /dev/null 2>&1 && break sleep 1 done # Start RustDesk client in background nohup dbus-run-session -- /usr/share/rustdesk/rustdesk --server > /tmp/rustdesk-session.log 2>&1 & echo "RustDesk PID: $!" sleep 3 # Wait for Xvfb (main process) - systemd tracks this script # If Xvfb dies, systemd will restart the service wait $XVFB_PID