XServer forward from Linux text mode for Headless purposes.

Hello, this post is about XServer forward from Linux text mode, not ssh forward, anything related to VNC or things like that.

Recently I was working on an AdoptOpenJDK tests bug that was preventing AWT and Swing tests to be executed properly in text mode, they need X to draw windows and simulate interactions.

My first assumption was that was necessary to have a whole Desktop or Window manager to make it work properly but no, just the XServer is enough.

Let’s take a look at this Ansible snippet.

At the first block “Install X11” we’re installing the necessary packages but in this case xserver-xorg-legacy was the most important one, this package enable you to give permission to any user start an XServer, this is important because jenkins user is the one who kicks off  the tests what makes mandatory to him start the XServer as well to avoid permissions problems when tests try to forward anything to the XServer.

Another alternative was giving him sudo powers but I think it would be more intrusive.

With xserver-xorg-legacy in place, we need to configure the Xwrapper.config file. Here the important part to mind is the following line.

It says that anyone has permissions to start an XServer.

Now “Start X11”, here you can see that we’re starting the XServer passing a parameter “:1 this is the address that we’re going to use to get connected to XServer.

Just in case you’re wondering what are the lines below doing, they are suppressing any output, is sort of annoying but when XServer starts it outputs some messages that in this case, prevents ansible to go forward so, we’re ignoring it.

With everything configured and XServer started, the only thing that we need is pointing to that address, eg:

I couldn’t find anything related to this scenario, most of the content that I’ve found was related to SSH or VNC stuff so, enjoy.

Leave a Reply