Install Hudson as a Windows service
Tuesday, May 4, 2010 by alexandrulTested with Hudson 1.356 on:
- Windows XP Professional
- Windows Server 2008 SP2 x86
- Windows Server 2008 R2
First, follow the Hudson wiki: Installing Hudson as a Windows service. The resulting service is named hudson, and is running under the Local system account.
Next, create a new local user named hudson-user (or any other name you like), which will be used in the next steps:
- alter the hudson service properties to log on as hudson-user
- grant Full control permissions for hudson-user on %HUDSON_HOME% folder
In order to be able to restart Hudson service from the web interface, SubInACL will be used to grant hudson-user the Start Service and Stop Service permission ACEs:
subinacl.exe /service hudson /grant=WORKSTATION\hudson-user=TO
where WORKSTATION is the computer name.
On some PCs, for various reasons, hudson.exe might crash due to IOExceptions, leaving you unable to restart Houdson from the web interface. In my case, the errors were:
The process cannot access the file 'hudson.out.log' because it is being used by another process. The process cannot access the file 'hudson.err.log' because it is being used by another process.
In order to avoid this situation, until a nicer workaround will be available, you can download the sources of Windows Service Wrapper, and alter the CopyStreamWithRotation function in the Main.cs file as:
private void CopyStreamWithRotation(Stream data, string baseName, string ext)
{
try
{
// move here the original function content
}
catch (Exception ex)
{
// swallow exception
}
}
If you are at this step, you could do the same with HandleLogfiles function, just in case.
After compiling the project, rename the executable to hudson.exe and replace the existing one in %HUDSON_HOME% folder.
Since Hudson is checking hudson.exe for modifications, one extra step would be to copy the new executable inside the %HUDSON_HOME%\war\WEB-INF\lib\hudson-core-1.356.jar file, replacing the existing windows-service\hudson.exe.