Installing a Buildbot service on Windows
From ASCEND
Update: revised and re-checked for Python 2.5, Twisted 2.5.0, and Buildbot 0.7.6, on 15 Nov 2007.
This page contains instructions for how to set up Buildbot on Windows as a 'service' (equivalent of a linux/unix 'daemon'). If you can offer any clarifications or corrections, please edit this page, or add comments on the 'discussion' page if you prefer. I have this page on my watchlist -- JP.
Contents |
[edit] Install Buildbot
First install Python (get the latest version 2.5.x Windows installer) and Twisted (get the current version for Python 2.5, I used version 2.5.0-py2.5).
Next install pywin32 (chose the Python 2.5 version; I used release 210).
Next install Buildbot. You can use our pre-build installer buildbot-0.7.6.win32.exe which is built from unmodified buildbot sources from buildbot.sf.net (but if you are cautious I recommend you build your own). This installer isn't tied to a specific version of Python, although it does need to patched as described below.
Next, open the file c:\Python25\scripts\buildbot.bat and edit it so that it points unambiguously to c:\Python25:
@C:\Python25\python.exe C:\Python25\Scripts\buildbot %*
Next, you need to edit the last few lines of the Buildbot c:\Python25\Lib\site-packages\buildbot\scripts\startup.py script so that it corrects an incompatibility arising from current version of Twisted: modify as shown:
if platformType == "win32": try: from twisted.scripts._twistw import run except ImportError: # from twisted.scripts.twistw import run from twisted.scripts.twistd import run else: from twisted.scripts.twistd import run run()
[edit] Set up your Buildbot slave
Next, you will probably want to install the subversion command-line client so that you Buildbot can get access to your source code repository (assuming it lives in Subversion). I installed svn-1.4.5-setup.exe from subversion.tigris.org.
Create a folder for the buildslave. In our case, we added a new account the user 'buildbot', and used the folder c:\Documents and Settings\buildbot as the build slave directory (it would probably be better to use a directory like c:\Documents and Settings\buildbot\slave\projectname).
You will probably also want to install whatever your particular build tools are. For ASCEND we use MinGW and MSYS on Windows, so run the following using your MSYS prompt:
c:\Python25\Scripts\buildbot create-slave "c:\Documents and Settings\buildbot" master.example.com:8888 username password
[edit] Test your Buildbot Slave
Make sure that your slave is connecting correctly. Make sure you have svn, python, c:\Python25\Scripts and your build tools (gcc etc) in your $PATH (by setting it on-the-fly).
Then, from the MSYS prompt, type:
buildbot start .
If you have configured the build slave with the correct username and password etc, you should see it in your master's 'waterfall' page, and you should be able to trigger builds on it if you have configured the master accordingly.
Once you can run the buildbot slave successfully, proceed with the next step.
[edit] Configure a Windows Service
[edit] Create the service launcher script
In the MSYS /home/buildbot directory, create a file buildbotstart.py script as follows:
#!c:\\Python25\\python import os homepath = "\\" slavepath = "c:\\Documents and Settings\\buildbot" # ...slave file location as above os.environ['HOMEDRIVE'] = "C:" os.environ['HOMEPATH'] = homepath os.environ['MSYSTEM'] = 'MINGW32' os.environ['PATH'] = ";".join([ r"C:\MinGW\bin" ,r"C:\msys\1.0\bin" ,r"C:\Program Files\GnuWin32\bin" ,r"C:\Python25" ,r"C:\Python25\Scripts" ,r"C:\GTK\bin" ,r"C:\Tcl\bin" ,r"C:\Program Files\Subversion\bin" ,r"C:\msys\1.0\home\john\swigwin-1.3.28" ]) from buildbot.scripts import runner from twisted.python import usage config = runner.Options() config.parseOptions(['start',slavepath]) command = config.subCommand so = config.subOptions #-----8<---- #Ignore signal on user logout # -- thanks to Matthieu Brucher import win32api def sighandler(sig): print "received signal %s" % (sig,) return True win32api.SetConsoleCtrlHandler(sighandler, True) #-----8<---- from buildbot.scripts.startup import start start(so)
You should be able to run that script using your cmd prompt. Try it.
[edit] Create a new Windows Service
First you need to get hold of srvany.exe and instsrv.exe and put them in a safe directory somewhere on your system. Get these from the 'Windows Server 2003 Resource Kit Tools' package, available from microsoft.com.
You'll only run instsrv.exe once, so you can leave it in its default location. But perhaps it's a good idea to put srvany.exe into c:\MinGW\bin.
Then run the latter from a 'cmd' prompt and install a service named BuildbotSlave that runs the srvany.exe executable. No mention of where Buildbot lives just yet:
instsrv BuildbotSlave c:\MinGW\bin\srvany.exe
On success you get a messaging saying "The service was successfully added!". For some more explanation about this, take a look at the following for details on how to install as a service: http://www.stolennotebook.com/anthony/2006/07/03/running-buildbot-as-a-windows-xp-service/
[edit] Link the service launcher script to the registered service
Next using the Windows XP control panel, Administrative tools, Services, you can see the BuildbotSlave service in the list. Edit the service so that it's run by a user of choice -- perhaps a special buildbot user.
Next, Go to regedit and add a new 'Key' named 'Parameters' under the key named HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BuildbotSlave.
Then, in the 'Parameters' key, add new 'string' values as shown in the following image.
Please be aware that srvany.exe is a little limited concerning argument strings which are passed in. If spaces are included in the paths, it will silently not work. Such arguments need to be enclosed in "double quotes"!
(remark: the picture here needs to be updated for this.)
Go back to the Services control panel, and start the service. You should see pythonw.exe in your task list (ctrl-alt-del) together wirn anysrv.exe nder the same user, and your slave should show up as connected in the Buildbot Waterfall plot (ie using your web browser to connect to the Build Master). If you see anysrv.exe only, check if the string with spaces problem from above applies.
[edit] Testing
To test that your Buildbot Windows Service is running ok, try the following:
- reboot your machine and check on the Buildbot master that the slave has appeared
- log in as user 'buildbot' on your Windows system, then log out again (to test the 'user logout' problem described below)
- manually stop and start the service using the Services control panel
- kill the pythonw.exe process and see what happens (not sure about this last one)
[edit] Notes
[edit] Problems with users logging out
It seems that in some cases, users logging in and out on Windows causes the 'srvany' service to stop. A solution was given by Matthieu Brucher, and has been incorporated into the above script (tested with Windows XP under kvm, see below).
[edit] Running on Virtual Windows
You don't necessarily need to run your Windows Buildbot on its own separate machine. If you have a sufficiently beefy linux machine, try reading the instructions for Remote Virtual Windows. Once you have that running, you can easily install a Buildbot service on your virtual Windows system.
[edit] Detection of MinGW environment
The line containing 'MSYSTEM' in the buildbotstart.py script is used to tell SCons to use the MinGW/MSYS build environment when building ASCEND. It's not required for any other reason. Without this, SCons attempts to build using MSVC++ by default.
[edit] Crashing Python?
Windows has the ability to re-launch a service if it fails. You might want to play around with that if you experience any strange occasional crashes with the service. I haven't seen any problems though.




