[Work-In-Progress post]
This morning, I crafted a few systemd unit files to help me manage running a Selenium Hub. As an extra benefit, I have some stuff ready for whenever I move to using CoreOS. 🙂
I'll keep the files here:
https://github.com/PortNumber53/systemd-stuffs/tree/master/selenium-hub
So if you're familiar with git, systemd and docker, go have fun, otherwise stick around and I'll do my best to guide you through this.
How to take advantage of these scripts:
First of all, those are heavily base on documentation from https://github.com/SeleniumHQ/docker-selenium ( credits to them )
I assume you have decent knowledge of your Linux distribuition. I like ArchLinux so commands will be targetted to it. Feel free to contribute in the comments for other distros and I'll keep the post updated.
1. Install tools you'll need.
[sample@samplearch ~]$ sudo pacman -S git docker [sudo] password for sample: resolving dependencies... looking for conflicting packages... Packages (6) bridge-utils-1.5-2 containerd-0.2.2-1 perl-error-0.17024-1 runc-0.1.1-1 docker-1:1.11.2-2 git-2.9.0-1 Total Download Size: 16.53 MiB Total Installed Size: 88.46 MiB :: Proceed with installation? [Y/n] y :: Retrieving packages... bridge-utils-1.5-2-x86_64 13.4 KiB 0.00B/s 00:00 [#############################################] 100% perl-error-0.17024-1-any 18.4 KiB 0.00B/s 00:00 [#############################################] 100% git-2.9.0-1-x86_64 4.5 MiB 2.62M/s 00:02 [#############################################] 100% runc-0.1.1-1-x86_64 1389.0 KiB 6.25M/s 00:00 [#############################################] 100% containerd-0.2.2-1-x86_64 3.9 MiB 4.07M/s 00:01 [#############################################] 100% docker-1:1.11.2-2-x86_64 6.7 MiB 4.28M/s 00:02 [#############################################] 100% (6/6) checking keys in keyring [#############################################] 100% (6/6) checking package integrity [#############################################] 100% (6/6) loading package files [#############################################] 100% (6/6) checking for file conflicts [#############################################] 100% (6/6) checking available disk space [#############################################] 100% :: Processing package changes... (1/6) installing perl-error [#############################################] 100% (2/6) installing git [#############################################] 100% Optional dependencies for git tk: gitk and git gui perl-libwww: git svn perl-term-readkey: git svn perl-mime-tools: git send-email perl-net-smtp-ssl: git send-email TLS support perl-authen-sasl: git send-email TLS support python2: various helper scripts subversion: git svn cvsps2: git cvsimport gnome-keyring: GNOME keyring credential helper (3/6) installing runc [#############################################] 100% (4/6) installing containerd [#############################################] 100% (5/6) installing bridge-utils [#############################################] 100% (6/6) installing docker [#############################################] 100% Optional dependencies for docker btrfs-progs: btrfs backend support lxc: lxc backend support :: Running post-transaction hooks... (1/1) Updating manpage index... [sample@samplearch ~]$
2. Clone the repo to any folder you'd like
[sample@samplearch ~]$ git clone https://github.com/PortNumber53/systemd-stuffs Cloning into 'systemd-stuffs'... remote: Counting objects: 37, done. remote: Total 37 (delta 0), reused 0 (delta 0), pack-reused 37 Unpacking objects: 100% (37/37), done. Checking connectivity... done. [sample@samplearch ~]$ cd systemd-stuffs/ [sample@samplearch systemd-stuffs]$
3. Create a symlink to the hub unit and start it
[root@samplearch system]# cd /usr/lib/systemd/system [root@samplearch system]# ln -s /home/sample/systemd-stuffs/selenium-hub/selenium-grid-hub.service [root@samplearch system]# systemctl start selenium-grid-hub.service [root@samplearch system]#
After the docker pulls the image and starts the contaner, you can check the status for the service:
[root@samplearch system]# systemctl status selenium-grid-hub.service * selenium-grid-hub.service - Selenium Grid Hub Loaded: loaded (/home/sample/systemd-stuffs/selenium-hub/selenium-grid-hub.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2016-07-05 14:09:34 PDT; 18s ago Process: 8516 ExecStop=/usr/bin/docker stop selenium-hub (code=exited, status=0/SUCCESS) Process: 8629 ExecStartPre=/usr/bin/docker pull selenium/hub:latest (code=exited, status=0/SUCCESS) Process: 8589 ExecStartPre=/usr/bin/docker rm selenium-hub (code=exited, status=0/SUCCESS) Process: 8577 ExecStartPre=/usr/bin/docker kill selenium-hub (code=exited, status=1/FAILURE) Main PID: 8637 (docker) Tasks: 6 (limit: 512) Memory: 4.5M CPU: 66ms CGroup: /system.slice/selenium-grid-hub.service `-8637 /usr/bin/docker run -p 4444:4444 --name selenium-hub selenium/hub:latest Jul 05 14:09:35 samplearch docker[8637]: 21:09:35.343 INFO - Launching Selenium Grid hub Jul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.050:INFO::main: Logging initialized @887ms Jul 05 14:09:36 samplearch docker[8637]: 21:09:36.077 INFO - Will listen on 4444 Jul 05 14:09:36 samplearch docker[8637]: 21:09:36.129 INFO - Will listen on 4444 Jul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.137:INFO:osjs.Server:main: jetty-9.2.z-SNAPSHOT Jul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.201:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandl Jul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.224:INFO:osjs.ServerConnector:main: Started ServerConnector@dc1556d{HTT Jul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.224:INFO:osjs.Server:main: Started @1061ms Jul 05 14:09:36 samplearch docker[8637]: 21:09:36.225 INFO - Nodes should register to http://172.17.0.2:4444/grid/register/ Jul 05 14:09:36 samplearch docker[8637]: 21:09:36.225 INFO - Selenium Grid hub is up and running
If you want to start the hub on boot, do this:
[root@samplearch system]# systemctl enable selenium-grid-hub.service
4. Create a symlink and start the chrome node service:
[root@samplearch system]# ln -s /home/sample/systemd-stuffs/selenium-hub/selenium-chrome-node\@.service [root@samplearch system]# systemctl start [email protected] [root@samplearch system]#
Because this unit is a template, you will see that it has an "@" in its name. Also note that when starting the service, you can tell which port should be exposed on the VNC server (you can connect to the node using a VNC client). For this sample I am using port 12000.
This allows you to run multiple chome nodes if you need.
5. Do the same for a Firefox node service:
[root@samplearch system]# ln -s /home/sample/systemd-stuffs/selenium-hub/selenium-firefox-node\@.service [root@samplearch system]# systemctl start [email protected] [root@samplearch system]#
For this example, I am exposing port 30000.
Happy times using Selenium