{"id":1064,"date":"2016-07-05T13:21:46","date_gmt":"2016-07-05T21:21:46","guid":{"rendered":"http:\/\/blog.portnumber53.com\/?p=1064"},"modified":"2016-07-05T13:21:46","modified_gmt":"2016-07-05T21:21:46","slug":"systemd-a-few-sample-scripts-to-run-selenium-hub","status":"publish","type":"post","link":"https:\/\/blog.portnumber53.com\/index.php\/2016\/07\/05\/systemd-a-few-sample-scripts-to-run-selenium-hub\/","title":{"rendered":"SystemD: a few sample scripts to run Selenium Hub"},"content":{"rendered":"<p>\n\t[Work-In-Progress post]\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\tThis 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. \ud83d\ude42\n<\/p>\n<p>\n\tI&#39;ll keep the files here:\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\thttps:\/\/github.com\/PortNumber53\/systemd-stuffs\/tree\/master\/selenium-hub\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\tSo if you&#39;re familiar with git, systemd and docker, go have fun, otherwise stick around and I&#39;ll do my best to guide you through this.\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\tHow to take advantage of these scripts:\n<\/p>\n<p>\n\tFirst of all, those are heavily base on documentation from&nbsp;https:\/\/github.com\/SeleniumHQ\/docker-selenium ( credits to them )\n<\/p>\n<p>\n\tI 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&#39;ll keep the post updated.\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t1. Install&nbsp;tools you&#39;ll need.\n<\/p>\n<pre>\n<span style=\"font-family:courier new,courier,monospace;\">[sample@samplearch ~]$ sudo pacman -S git docker\n[sudo] password for sample:\nresolving dependencies...\nlooking for conflicting packages...<\/span>\n\n<span style=\"font-family:courier new,courier,monospace;\">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<\/span>\n\n<span style=\"font-family:courier new,courier,monospace;\">Total Download Size:   16.53 MiB\nTotal Installed Size:  88.46 MiB<\/span>\n\n<span style=\"font-family:courier new,courier,monospace;\">:: Proceed with installation? [Y\/n] y\n:: Retrieving packages...\n bridge-utils-1.5-2-x86_64                              13.4 KiB  0.00B\/s 00:00 [#############################################] 100%\n perl-error-0.17024-1-any                               18.4 KiB  0.00B\/s 00:00 [#############################################] 100%\n git-2.9.0-1-x86_64                                      4.5 MiB  2.62M\/s 00:02 [#############################################] 100%\n runc-0.1.1-1-x86_64                                  1389.0 KiB  6.25M\/s 00:00 [#############################################] 100%\n containerd-0.2.2-1-x86_64                               3.9 MiB  4.07M\/s 00:01 [#############################################] 100%\n docker-1:1.11.2-2-x86_64                                6.7 MiB  4.28M\/s 00:02 [#############################################] 100%\n(6\/6) checking keys in keyring                                                  [#############################################] 100%\n(6\/6) checking package integrity                                                [#############################################] 100%\n(6\/6) loading package files                                                     [#############################################] 100%\n(6\/6) checking for file conflicts                                               [#############################################] 100%\n(6\/6) checking available disk space                                             [#############################################] 100%\n:: Processing package changes...\n(1\/6) installing perl-error                                                     [#############################################] 100%\n(2\/6) installing git                                                            [#############################################] 100%\nOptional dependencies for git\n    tk: gitk and git gui\n    perl-libwww: git svn\n    perl-term-readkey: git svn\n    perl-mime-tools: git send-email\n    perl-net-smtp-ssl: git send-email TLS support\n    perl-authen-sasl: git send-email TLS support\n    python2: various helper scripts\n    subversion: git svn\n    cvsps2: git cvsimport\n    gnome-keyring: GNOME keyring credential helper\n(3\/6) installing runc                                                           [#############################################] 100%\n(4\/6) installing containerd                                                     [#############################################] 100%\n(5\/6) installing bridge-utils                                                   [#############################################] 100%\n(6\/6) installing docker                                                         [#############################################] 100%\nOptional dependencies for docker\n    btrfs-progs: btrfs backend support\n    lxc: lxc backend support\n:: Running post-transaction hooks...\n(1\/1) Updating manpage index...\n[sample@samplearch ~]$<\/span>\n<\/pre>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t2. Clone the repo to any folder you&#39;d like\n<\/p>\n<pre>\n[sample@samplearch ~]$ git clone https:\/\/github.com\/PortNumber53\/systemd-stuffs\nCloning into &#39;systemd-stuffs&#39;...\nremote: Counting objects: 37, done.\nremote: Total 37 (delta 0), reused 0 (delta 0), pack-reused 37\nUnpacking objects: 100% (37\/37), done.\nChecking connectivity... done.\n[sample@samplearch ~]$ cd systemd-stuffs\/\n[sample@samplearch systemd-stuffs]$<\/pre>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t3. Create a symlink to the hub unit and start it\n<\/p>\n<pre>\n[root@samplearch system]# cd \/usr\/lib\/systemd\/system\n[root@samplearch system]# ln -s \/home\/sample\/systemd-stuffs\/selenium-hub\/selenium-grid-hub.service\n[root@samplearch system]# systemctl start selenium-grid-hub.service\n[root@samplearch system]#<\/pre>\n<p>\n\tAfter the docker pulls the image and starts the contaner, you can check the status for the service:\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<pre>\n[root@samplearch system]# systemctl status selenium-grid-hub.service\n* selenium-grid-hub.service - Selenium Grid Hub\n   Loaded: loaded (\/home\/sample\/systemd-stuffs\/selenium-hub\/selenium-grid-hub.service; disabled; vendor preset: disabled)\n   Active: active (running) since Tue 2016-07-05 14:09:34 PDT; 18s ago\n  Process: 8516 ExecStop=\/usr\/bin\/docker stop selenium-hub (code=exited, status=0\/SUCCESS)\n  Process: 8629 ExecStartPre=\/usr\/bin\/docker pull selenium\/hub:latest (code=exited, status=0\/SUCCESS)\n  Process: 8589 ExecStartPre=\/usr\/bin\/docker rm selenium-hub (code=exited, status=0\/SUCCESS)\n  Process: 8577 ExecStartPre=\/usr\/bin\/docker kill selenium-hub (code=exited, status=1\/FAILURE)\n Main PID: 8637 (docker)\n    Tasks: 6 (limit: 512)\n   Memory: 4.5M\n      CPU: 66ms\n   CGroup: \/system.slice\/selenium-grid-hub.service\n           `-8637 \/usr\/bin\/docker run -p 4444:4444 --name selenium-hub selenium\/hub:latest\n\nJul 05 14:09:35 samplearch docker[8637]: 21:09:35.343 INFO - Launching Selenium Grid hub\nJul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.050:INFO::main: Logging initialized @887ms\nJul 05 14:09:36 samplearch docker[8637]: 21:09:36.077 INFO - Will listen on 4444\nJul 05 14:09:36 samplearch docker[8637]: 21:09:36.129 INFO - Will listen on 4444\nJul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.137:INFO:osjs.Server:main: jetty-9.2.z-SNAPSHOT\nJul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.201:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandl\nJul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.224:INFO:osjs.ServerConnector:main: Started ServerConnector@dc1556d{HTT\nJul 05 14:09:36 samplearch docker[8637]: 2016-07-05 21:09:36.224:INFO:osjs.Server:main: Started @1061ms\nJul 05 14:09:36 samplearch docker[8637]: 21:09:36.225 INFO - Nodes should register to http:\/\/172.17.0.2:4444\/grid\/register\/\nJul 05 14:09:36 samplearch docker[8637]: 21:09:36.225 INFO - Selenium Grid hub is up and running\n<\/pre>\n<p>\n\tIf you want to start the hub on boot, do this:\n<\/p>\n<pre>\n[root@samplearch system]# systemctl enable selenium-grid-hub.service<\/pre>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t4. Create a symlink and start the chrome node service:\n<\/p>\n<pre>\n[root@samplearch system]# ln -s \/home\/sample\/systemd-stuffs\/selenium-hub\/selenium-chrome-node\\@.service\n[root@samplearch system]# systemctl start selenium-chrome-node@12000.service\n[root@samplearch system]#<\/pre>\n<p>\n\tBecause this unit is a template, you will see that it has an &quot;@&quot; 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.\n<\/p>\n<p>\n\tThis allows you to run multiple chome nodes if you need.\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t5. Do the same for a Firefox node service:\n<\/p>\n<pre>\n[root@samplearch system]# ln -s \/home\/sample\/systemd-stuffs\/selenium-hub\/selenium-firefox-node\\@.service\n[root@samplearch system]# systemctl start selenium-firefox-node@30000.service\n[root@samplearch system]#\n<\/pre>\n<p>\n\tFor this example, I am exposing port 30000.\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\tHappy times using Selenium\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t<br \/>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Work-In-Progress post] &nbsp; 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. \ud83d\ude42 I&#39;ll keep the files here: &nbsp; https:\/\/github.com\/PortNumber53\/systemd-stuffs\/tree\/master\/selenium-hub &nbsp; So if you&#39;re familiar with&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/blog.portnumber53.com\/index.php\/2016\/07\/05\/systemd-a-few-sample-scripts-to-run-selenium-hub\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[115,302,331],"class_list":["post-1064","post","type-post","status-publish","format-standard","hentry","category-linux","tag-docker","tag-selenium","tag-systemd"],"_links":{"self":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/1064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/comments?post=1064"}],"version-history":[{"count":0,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/1064\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/media?parent=1064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/categories?post=1064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/tags?post=1064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}