Selenium Server as Windows Service via NSSM
In this blog post you will find a convenient batch-script to install (and update) Selenium WebDriver Server as Windows Service using NSSM – the Non-Sucking Service Manager, tested with Windows 7 64bit.
Actually searching through the internet you will find quite many postings on how to install Selenium Server as Windows Service. Most of them either refer to the Windows Server 2003 Resource Kit Tools and srvany.exe or to AlwaysUp from Core Technologies Consulting.
srvany.exe is quite obviously a hack – and from what I have read won’t work with 64bit systems. AlwaysUp seems to have a nice UI and feature like email alerts in case of problems. Nevertheless you have to purchase licenses to run AlwaysUp.
So we found a solution which uses a free tool: NSSM – the Non-Sucking Service Manager. And in order to have an easy update process for Selenium Server I wrote a Batch Script, which basically performs these steps:
- Stop any possibly still running Selenium Server Service (sc),
- remove the service (nssm),
- install the new Selenium Server as service (nssm),
- configure the service to interact with the Desktop (sc) and
- start the service (sc).
The interesting part are actually the version numbers you set at the top of the script. Having them it is a piece of cake to update to a new Selenium Server version – which is a good thing due to their frequent updates.
Below you will find the stripped version of the batch-file. The full version with some convenience checks can be downloaded as Gist from GitHub.
@echo off set SERVER_VERSION=2.32.0 set IESERVER_VERSION=2.32.3 set DOWNLOADS_FOLDER=%HOME%\Downloads set SERVICE_NAME=Selenium Server set NSSM=C:\nssm-2.16\nssm-2.16\win64\nssm.exe set JAVA=%ProgramFiles%\Java\jre7\bin\java.exe set SERVER_BASENAME=selenium-server-standalone set IESERVER_BASENAME=IEDriverServer_Win32 set SERVER_JAR=%DOWNLOADS_FOLDER%\%SERVER_BASENAME%-%SERVER_VERSION%.jar set IESERVER_EXEC=%DOWNLOADS_FOLDER%\%IESERVER_BASENAME%_%IESERVER_VERSION%\IEDriverServer.exe sc stop "%SERVICE_NAME%" >NUL 2>NUL "%NSSM%" remove "%SERVICE_NAME%" confirm > NUL 2>NUL "%NSSM%" install "%SERVICE_NAME%" "%JAVA%" -jar ""%SERVER_JAR%"" -Dwebdriver.ie.driver=""%IESERVER_EXEC%"" -timeout 120 -browserTimeout 120 if not errorlevel 1 ( sc config "%SERVICE_NAME%" type= own type= interact sc start "%SERVICE_NAME%" )
- Gist nssmSeleniumInstall.bat
- NSSM – the Non-Sucking Service Manager
- coretechnologies.com: How to Run Selenium Remote Control (RC) Server as a Windows Service with AlwaysUp
- coldfusion10.com: Adding selenium-rc as a Windows service