Skip to content

Instantly share code, notes, and snippets.

@keyboardcrunch
Created January 29, 2023 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyboardcrunch/5fcdee3d2978d3bf6d1bbc57d4e3cff7 to your computer and use it in GitHub Desktop.
Save keyboardcrunch/5fcdee3d2978d3bf6d1bbc57d4e3cff7 to your computer and use it in GitHub Desktop.
Headless xvfb-run Apps

Headless Applications with xvfb and x11vnc

In the code block below we're going to launch two graphical applications on a headless server (no desktop environment) within their own virtual display, then launch an instance of x11vnc server connected to each virtual display. Generally if you have more than one application you might as well run a full desktop environment and vnc server, but this is more fun.

Requirements

  • x11vnc
  • the desktop apps you want (handbrake and firefox used in example)
  • (optional) fluxbox or other minimal DE

The Example

In our example script we'll go through the steps of:

  1. Creating a stored credential file for x11vnc server.
  2. Use xvfb-run to start handbrake-gtk on a virtual 1024x768 24bit display.
  3. Use xvfb-run to start firefox on a virtual 1024x768 24bit display.
  4. Start the x11vnc server for virtual display 1 (handbrake-gtk), first available TCP port will be used (5900). Display port will likely be :0.
  5. Start the x11vnc server for virtual display 2 (firefox), second available TCP port will be used (5901). Display port will likely be :1.
#!/bin/bash
# Setup x11vnc creds
x11vnc -storepasswd MyVNCPassword /home/frank/.vnc/passwd

# Setup apps with virtual displays
xvfb-run --listen-tcp --server-num 1 --auth-file /tmp/xvfb1.auth -s "-ac -screen 1 1024x768x24" handbrake-gtk &
xvfb-run --listen-tcp --server-num 2 --auth-file /tmp/xvfb2.auth -s "-ac -screen 2 1024x768x24" firefox &

# x11vnc startup
x11vnc -rfbauth /home/frank/.vnc/passwd -display :1 -forever -auth /tmp/xvfb1.auth &
x11vnc -rfbauth /home/frank/.vnc/passwd -display :2 -forever -auth /tmp/xvfb2.auth &

Final Notes

The resulting VNC app may look a bit ugly as without a desktop environment you won't have application title bars or window tiling, and without titlebars you can't move child windows around. So this works better on single-pane applications. If you were to install fluxbox you should add a line before the xvfb-run commands to start fluxbox, fluxbox &.

These commands need to be refined to specify the exact display port number and optionally the VNC server listening port.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment