computer-using-agent / start_vnc.sh
OsamaBinLikhon's picture
Enhancement: Add VNC desktop environment integration
8c9319a verified
#!/bin/bash
# VNC and Gradio Startup Script
# This script starts VNC server, web bridge, and Gradio interface
set -e
echo "πŸš€ Starting VNC Desktop Environment..."
# Start VNC server
echo "πŸ“Ί Starting VNC server on port $VNC_PORT..."
export VNC_PORT=${VNC_PORT:-5901}
export VNC_PASSWORD=${VNC_PASSWORD:-computer-agent}
# Set VNC display
export DISPLAY=:99
# Kill any existing VNC servers
pkill -f vnc || true
pkill -f websockify || true
# Start VNC server in background
echo "πŸ”§ Starting TigerVNC server..."
vncserver :99 -geometry 1920x1080 -depth 24 -PasswordFile=/root/.vnc/passwd &
VNC_PID=$!
echo "VNC server started with PID: $VNC_PID"
# Wait for VNC server to be ready
sleep 3
# Start websockify to bridge VNC to web
echo "🌐 Starting Websockify bridge..."
websockify --web /usr/share/novnc 0.0.0.0:$VNC_PORT &
WEBSOCKIFY_PID=$!
echo "Websockify started with PID: $WEBSOCKIFY_PID"
# Start XFCE4 desktop environment
echo "πŸ–₯️ Starting XFCE4 desktop..."
export XDG_RUNTIME_DIR=/tmp/runtime-root
export QT_X11_NO_MITSHM=1
# Wait a bit more for VNC to be fully ready
sleep 2
# Start desktop environment in background
startxfce4 &
DESKTOP_PID=$!
echo "Desktop environment started with PID: $DESKTOP_PID"
# Give desktop environment time to start
sleep 5
echo "βœ… VNC environment is ready!"
echo "πŸ”— VNC Port: $VNC_PORT"
echo "πŸ”— Web Interface: http://localhost:7860"
# Function to cleanup on exit
cleanup() {
echo "πŸ›‘ Shutting down services..."
kill $VNC_PID $WEBSOCKIFY_PID $DESKTOP_PID 2>/dev/null || true
pkill -f vnc || true
pkill -f websockify || true
pkill -f startxfce4 || true
exit 0
}
# Trap cleanup signals
trap cleanup SIGTERM SIGINT
# Start Gradio interface in foreground
echo "🌐 Starting Computer-Using Agent interface..."
python computer_agent.py