Question

I set up the latest version of Selenium Server, ChromeDriver and Chrome on a headless Debian 7 VM, running it manually through Screen with Chrome running inside Xvfb. This worked very well and I would now like to transfer this to a production Ubuntu 12.04 VM. In the interests of security, I'd like to run it as a locked-down user and as close to a daemon as possible so it can be left unattended.
I've written a Fabric script to handle the deployment but have fallen at the last hurdle - starting up Selenium and Xvfb. Selenium runs inside Screen using a custom .screenrc, which also launches Xvfb, but I suspect the DISPLAY variable is not being properly exported - I have VNC'd into the framebuffer and started my RemoteWebDriver project, which connects to Selenium and kicks off ChromeDriver and Chrome, but the Chrome window does not appear and the project times out after 60 seconds. I've added the following line to the .bashrc for the selenium-daemon user:

export DISPLAY=:10

and in the .screenrc:

screen -t 'Xvfb' 0 /usr/bin/Xvfb :10 -screen 0 1366x768x24 -ac
screen -t 'Selenium' 1 /bin/bash --rcfile /home/selenium-daemon/.bashrc -c '/usr/bin/java -jar /usr/local/bin/selenium-server-standalone-2.39.0.jar -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -port 4444 > /tmp/selenium.log'

Screen is being kicked off by Fabric with

sudo("screen -dmS selenium -c /home/selenium-darmon/.screenrc & sleep 5", user="selenium-daemon")

I tried explicitly setting the --rcfile as I wasn't sure it was being used, but this hasn't helped. I'm fairly sure this is the problem; on my test VM I had a similar problem and it was solved by ensuring the DISPLAY variable had been set properly. At present the selenium-daemon user is locked down so I can't connect to the Screen session.
I also discovered that calling Screen from Fabric returns immediately; this in turn somehow stops Screen firing up. I got around it with the sleep call above, which allows Screen enough time to create the session. Is this expected? Or could this have something to do with my problems?
Running the Fabric/Screen commands manually does not solve the problem, even though they are adapted from the commands I used on the test VM. Any pointers?
As an afterthought, I would also like to be able to kick off x11vnc server attached to Xvfb, but if I put a working call to it in the .screenrc, it completely fails to appear. Even calling sleep before it starts does not launch it:

screen -t VNC 2 /usr/bin/x11vnc -display :10 -bg -nopw -xkb -listen 127.0.0.1

EDIT: I think I fixed the VNC issue, copy-pasting commands is usually a poor idea! Went back in and changed some of the flags to:

screen -t VNC 2 /usr/bin/x11vnc -display WAIT:10 -nopw -xkb -forever -shared -listen 127.0.0.1 -logfile /tmp/x11vnc.log

to much more success. I've gotten ChromeDriver to start up manually, now investigating whether I can kick it off with Fabric.

Was it helpful?

Solution

Maybe you could look into using supervisord instead of screen to manage your long running processes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top