Running Selenium server as a CentOS systemd service

… is very easy to do.

You need two things.  1) Xvfb for the virtual screen, 2) systemd.  (And the Selenium Server binary, of course)

First Xvfb

Description=X Virtual Frame Buffer Service

ExecStart=/usr/bin/Xvfb :99 -screen 0 1024x768x24


This will start up the virtual framebuffer so Selenium has a virtual screen to run the browser on.  Next up is the Selenium service itself.


[Service] Type=simple User=magiumlib PIDFile=/var/spool/selenium/pid/ EnvironmentFile=-/etc/sysconfig/network Environment=DISPLAY=:99 Environment=DBUS_SESSION_BUS_ADDRESS=/dev/null ExecStart=/bin/java -Dselenium.LOGGER=/home/magiumlib/selenium.log -jar /var/www/magiumlib/bin/selenium-server-standalone-2.53.0.jar ExecStop=kill `cat /var/spool/selenium/pid/` [Install]

Voila!  Automated Selenium.