Skip to content

Running Buildbot as a Windows XP Service

This is an in progress tutorial on how to run buildbot as a Windows XP service. Most of the information comes from these three articles by Grig Gheorghiu:

continuous-integration-with-buildbot
running-buildbot-on-various-platforms
running-python-script-as-windows

At Stolen Notebook we use Buildbot for our automated testing. Buildbot is a system that automates project builds and tests. It helps our team quickly identify errors in our code before they become problems. Buildbot runs after every repository check-in and compiles the code with tests. If the build or tests fail our team receives an email indicating who checked in code last and why the build failed. This aids in catching small problems such as forgetting to add a new file to the repository. A missing file is a very simple problem which can hold up other developers in a big way. Buildbot can also immediately catch larger issues such as tests failing due to new code changes. If you are new to buildbot there is a nice article by Grig Gheorghiu on setting up buildbot at continuous-integration-with-buildbot. If you are setting up buildslaves on multiple platforms he also has a nice article at running-buildbot-on-various-platforms.

Once you get your buildbot farm going you might want to run your Windows NT/XP/2003 buildslaves as windows services. Our WindowsXP buildslave serves multiple purposes. Different users log in and out of it on a regular basis. Running buildbot from the command line doesn’t work very well in this situation. The easiest solution is to run buildbot as a Windows Service. This allows buildbot to start running when Windows begins. Buildbot then runs in the background despite which users log in or out of the machine. Some small issues may arise when turning buildbot into a service so it is best to make sure buildbot is working from the command line first.

Here is an article about running a python script as a windows service running-python-script-as-windows

I created a buildslave user and got my slave working on the command line under that user’s account. I then created a service called BuildSlave and set it to run under the buildslave user. You can do this by going to Control Panel-> Administrative Tools->Services. Right click on the Buildslave service and select Properites. Go to the “Log On” tab and under “Log on as:” select “This account:” Now type in the buildslave username (I named mine buildslave) and password. The service will now run as the buildslave user. Some environmental variables might not get set. See the Problem Solving section below for a more detailed description.

There are different methods for launching the python script. The one mentioned in the article uses a batch file.

UPDATE: A comment by jdpipe mentions a better way to launch buildbot by using a python script instead of a windows batch file. Check out his article at http://ascendwiki.cheme.cmu.edu/BuildBot.

For buildbot you would make a batch file with the contents:

C:\Python24\python C:\buildbot\bin\buildbot start c:\buildslave\game

Make sure to substitute the correct paths for python, buildbot, and the buildslave directory. I named my batch file startslave.bat.

It should be mentioned that if the batch file method is used then stopping the service might not kill the python.exe process. You will have to kill it manually.

Problem Solving:

Buildslave stays in ACTIVE state:
A problem I had was when a buildslave would do a build and then never return to the IDLE state. On the next build the buildmaster would go through the buildslaves looking for IDLE ones but the buildslave would still be in the ACTIVE state and get skipped. Since it would never return to the IDLE state it would never do another build. I believe this problem was caused by not calling a superclass’s __init__ function from a subclass in my master.cfg file. If you have a configuration where you are subclassing a buildbot class(Such as subclassing step.ShellCommand to change the name of a build step) make sure you call the superclass’s __init__ function from the subclass’s __init__ function. If you don’t the effects could be small and unnoticeable at first but cause the buildslaves or buildmaster to behave in very strange ways because certain classes were not initialized properly.

Buildslave hangs or doesn’t start a build when running as a service:
When buildbot is started as a service the windows environment may be different even if you run the service as the same user you ran buildbot as from the command line. Certain environment variables which are set and valid when you run your slave from the command line might be invalid or not even exists when the slave is run as a service. Two big variables are HOMEPATH and HOMEDRIVE. If your buildbot setup requires some programs which rely on config files in the buildslave user’s home directory they might use those environment variables to find where those files reside. If the variables don’t exist those programs might use default options which cause them to just sit there and do nothing. When buildbot receives a command it dumps the environment just before running the command. A good idea is you run the buildslave from the command line and take a look at the environment. Then run the buildslave as a service and compare the two environments. You can find all logged messages in the twistd.log file which resides in your buildslave’s configuration directory. After comparing environments I found the service environment was missing both the HOMEPATH and HOMEDRIVE variables. My ssh setup required config files in those directories and was unable to find them. I then set those variables in my startslave.bat(which is launched by the BuildSlave service) prior to launching buildbot. It now looks like this:

set HOMEDRIVE = "C:"
set HOMEPATH = "\Documents and Settings\buildslave"
C:\Python24\python C:\buildbot\bin\buildbot start c:\buildslave\game

5 Comments

  1. jdpipeNo Gravatar wrote:

    Here is an approach that runs Buildbot directly without the need for an additional batch file:
    https://pse.cheme.cmu.edu/wiki/view/Ascend/BuildBot

    It also gives you a place to set environment vars. By running python directly, you get around some nasty things that happen when attempting to stop/restart the Windows service.

    Tuesday, January 9, 2007 at 8:44 am | Permalink
  2. tonymagroNo Gravatar wrote:

    Thanks for the link and information. It was really helpful. I updated the article and made a new blog post mentioning it.

    Monday, January 15, 2007 at 1:15 pm | Permalink
  3. tonymagroNo Gravatar wrote:

    The article mentioned above which was posted by jdpipe now resides at http://ascendwiki.cheme.cmu.edu/BuildBot

    Thursday, July 26, 2007 at 4:02 pm | Permalink
  4. yalameshNo Gravatar wrote:

    I am new guy to buildbot i want to configure buildbot in my organization ,How can i configure this Right now we are using CVS server in on RHEL5 64 bit, Is it supports Buildbot ? ,I tried to configure in windows but i don’t know , How to give entries in master.cfg file Can anyone suggest to me how to give mail entries and cvs (project )entries in Buildbot ,What is the port number Where can i get this ? where i want to give this entries and How can i test it is working or not ?

    tell me please anyone mail to me

    I say thanks to every one advaced for

    Sunday, November 23, 2008 at 12:00 pm | Permalink
  5. yalameshNo Gravatar wrote:

    Above article this is my mail id yalamesh@gmail.com ,plz send me suggestions or help for me

    Thanks to all ……..Once again

    Sunday, November 23, 2008 at 12:03 pm | Permalink

One Trackback/Pingback

  1. Tony’s Blog » Buildbot as a Windows XP Service Part 2 on Monday, January 15, 2007 at 1:06 pm

    […] This is a quick update to my last article on Running Buildbot as a Windows XP Service. There was an interesting comment posted by jdpipe regarding the previous article . He offered a nice solution for some issues I was having with environment variables and stopping the Buildbot service. You can check out the article he wrote about it at https://pse.cheme.cmu.edu/wiki/view/Ascend/BuildBot. […]

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

Tony's Blog is using WP-Gravatar