I have a build machine that runs a build script every day, but it runs on a headless server. That’s not really a problem except that I get a lot of GTK warnings because there’s no display. To get around having these useless warnings in my build log, I start a vnc server so i’ll have a display available on this machine.
Start a VNC server and grab the display number.
# su headless -c "vncserver &> $TEMP" \
VNC_DISP=`grep -o "desktop is.*" $TEMP" | awk '{print $3}'`
The VNC_DISP variable captures the hostname and display number so it knows which one to kill after you’re done.
New 'headless.host.com:1 (root)' desktop is headless.host.com:1 Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/headless.host.com:1.log
Start your build script or do whatever it is you needed a display for on this headless server.
# su headless -c "export DISPLAY=$VNC_DISP && ~/build.sh
Kill the VNC server since it’s no longer needed.
# su headless -c "vncserver -kill $VNC_DISP &> /dev/null"
Voila, no more warnings on the build server! I call this in a script that runs daily as a cron. So at four in the morning, or whenever my cron script gets called, the system has a display available, does it’s business, and kills the display to clean up after itself.