At my workplace, we use
Fitnesse as our wiki and acceptance testing framework. We installed it about a month ago, and since then, we have taken advantage of the wiki aspect more than acceptance testing. We will get to the automated AT's in time. For an organization with a customized flavor of agile, the wiki is a perfect medium to provide visibility to all our players.
What I dislike about Fitnesse is running it from a bat file. In our situation, we have multiple administrators logging on to the server where Fitnesse resides. You get the point. When administrators log off, Fitnesse shuts down. While this post is geared towards using Fitnesse, we can apply similar procedures in order to make any bat file run as a windows service.
This post shows the steps I took recently to allow Fitnesse to run as a windows service. Our installation is running on Windows Server 2003. We need to install Windows Server 2003 Resource Kit Tools for this tutorial to work, as well as Fitnesse. Windows Server 2003 Resource Kit Tools can be used on XP as well. Search for other articles on its compatibility.
While reading articles on how to run a bat file as a service, I ran accross this one, Installing Fitnesse as a Service. It could not be any clearer than that. This solved my troubling issue. I do not want to reproduce this article, but I do want to add to it. Read this article first, and then mine. Many developers prefer screen shots to reading instructions. I will attempt to provide screen shots to improve points.
Originally, I started trying to get sample bat file to run as a service. I found a few articles helping me understand this, but they all lacked clarity. This is where I feel screen shots help. Eventually, I stumbled across the Fitnesse article I mentioned earlier, and success followed shortly thereafter.
Step One, install Windows Server 2003 Resource Kit Tools. We are going to create a user-defined service using two executables, Instsrv.exe and Svrany.exe. Instsrv.exe installs and removes services, and Svrany.exe allows any application to run as a service. Install the kit tools to their default. Keep track of where you installed them.
Step Two, register Fitnesse as a service. instsrv Fitnesse "C:\Program Files\Windows Resource Kits\Tools\srvany.exe" At this point, the service is now added.
Step Three, modify the registry. Do not modify the registry if you do not know what you are doing. Find the Fitnesse key in the registry. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Fitnesse. Modify the "ImagePath" string value to be the location of your SRVANY.exe. Mine is located here "C:\Program Files\Windows Resource Kits\Tools\srvany.exe".
Next we need to add a new key, and three string values. We need to add the Parameters key (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Fitnesse\Parameters), and the three string values, AppDirectory, Application, and AppParameters. AppDirectory is the root directory of our service, in this case, where our Fitnesse bat file resides. Application is the java.exe executable needed to run our service. AppParameters is the value of the parameters passed into our bat file used by the java.exe to start our Fitnesse service.
Step Four, now we need to start our service with a user account that has networking privileges. In my case, I use the Administrator account.
At this point, we can start our service, and access our URL to Fitnesse via a web browser. The console application is no longer visible on the desktop, and users can log in and out of our server without interrupting the Fitnesse service.
If we need to remove the service, we need to stop the service first.
Then we need to remove the service using Instsrv.exe, "instsrv Fitnesse remove".
At this point, our Fitnesse service is stopped, and removed from the registry as well.
These same principles can be applied to running a bat file as a windows service. My situation was specific to Fitnesse, but the same technique will apply to other applications.