NAntService - Description
This utility allows NAnt build scripts to be run automatically once created. To do this a Windows Service monitors for a .build file to be created in a specifiedfolder. Once the build file has been executed by NAnt it (and any other files in the folder) can be either archived to a datetime stamped folder or deleted.
Once the service detects the .build has been created it will wait for 10 seconds(configurable) before trying to execute the script - this allows for any files the script depends upon to be copied to the folder. You can also schedule when NAnt actually executes the script once it has been copied to the folder. Instead of it being instantly executed you can set a time for NAnt to execute it.
You can download the source code from ProjectDistributor.NET
If you find a use for this utility it would be great to hear from you! Suggestions, bug reports etc are welcome via the ProjectDistributor feedback pages or comments on this blog
What problem does this solve?
In order to deploy builds to multiple servers we wanted a simple mechanism to do these repetitive tasks - NAnt and NAntContrib provide easily enough tasks to cover almost any deployment requirement - all we need was something to execute a build (ie deployment) script on each machine.
Our specific problem was updating IIS with a new build to a web application
The new code base sits in a version numbered folder, something like,
C:\inetpub\wwwroot\ourapplication_1.0.0.7
Our deployment NAnt script is used to...
1. Unzip the new code base (creates the new application folder)
2. Update the IIS application folder to point to the new code base folder
3. Email the devs that the script has run successfully
All we have to do is drop the deploy.build script and the build zip file into a folder on each server and it will be executed - bingo, one touch deployment :)
Application Design
The application uses "Triggers" and "Processors". Triggers detect the build file has been created and Processors process the build file once the trigger has been tripped.
At the moment the service can only use a single trigger and processor. The trigger and processor combination are configured in the app.config and they are dynamically loaded when the service starts. More triggers and processors can be created in a seperate assembly if required and loaded into the service as replacements - they just need to implement an interface (ITrigger & IFileProcessor respectively).
I have supplied 2 triggers and 1 processor.
NAntProcessor - launches NAnt.exe for the build file detected by the trigger.
FileTrigger - detects the build file and immediately invokes NAntProcessor.
ScheduledFileTrigger - detects the build file and invokes NAntProcessor at the time specified. If this time is in the past it will invoke it the next day at the time required.
To switch between the normal and scheduled filetrigger have a look in the app.config "Config" section - just uncomment/comment the one you want (remember to restart the service or console app though).
The service is designed to be fairly generic. The ITrigger interface specifies Setup(), Test(), Reset() and TearDown() methods. Setup() and TearDown() are called once when the service starts and stops respectively. Test() is called every 1 seconds and if it returns true (eg it did something and triggered) then Reset() is called to reset the trigger properties. By having the implementing Assemblies dynamically loaded when the service starts its possible for you to create your own Triggers and Processors - they don't have to have anything to do with NAnt!
Programs/Installation
NAntService - A windows service application. Install this using installutil on the .exe
InstallUtil can be found in the C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 folder
To install: installutil NAntService.exe
To un-install: installutil NAntService /u
Once installed it will show up in your service list as 'NAntService'.
NOTE: The user the service is running under will impact on some NAnt tasks - be sure the .build script tasks you want run are possible with the security permissions of NAntService account you have configured it with.
NAntServiceConsole - a console application. I used this to debug the application as it provides lots of Console.WriteLine diagnostic info. Once executed it will open a cmd window and sit there waiting for a .build file to be created. To terminate it just press Enter. This application does not require and special installation - just update the app.config (NAntServiceConsole.exe.config) with your values and then run the .exe
NOTE: Config file changes to NAntService.exe.config & NAntServiceConsole.exe.config will only be picked up once the service or console application have been restarted
** IMPORTANT ** You must have the NAnt bin folder in your system PATH otherwise NAnt will not execute correctly.
TODO
* Redirect the Console output to a log file when running as a Service to provide a history of events
* Enable multiple triggers to be configured
Disclaimer
This software is provided 'As is' and no warranty is implied by its use. By using this software or parts of the supplied software the user understands it is entirely at their own risk and the author shall not be liable in any way whatsoever.
Version History
02-Nov-05 v1.0.0.0 Initial Release
This utility allows NAnt build scripts to be run automatically once created. To do this a Windows Service monitors for a .build file to be created in a specifiedfolder. Once the build file has been executed by NAnt it (and any other files in the folder) can be either archived to a datetime stamped folder or deleted.
Once the service detects the .build has been created it will wait for 10 seconds(configurable) before trying to execute the script - this allows for any files the script depends upon to be copied to the folder. You can also schedule when NAnt actually executes the script once it has been copied to the folder. Instead of it being instantly executed you can set a time for NAnt to execute it.
You can download the source code from ProjectDistributor.NET
If you find a use for this utility it would be great to hear from you! Suggestions, bug reports etc are welcome via the ProjectDistributor feedback pages or comments on this blog
What problem does this solve?
In order to deploy builds to multiple servers we wanted a simple mechanism to do these repetitive tasks - NAnt and NAntContrib provide easily enough tasks to cover almost any deployment requirement - all we need was something to execute a build (ie deployment) script on each machine.
Our specific problem was updating IIS with a new build to a web application
The new code base sits in a version numbered folder, something like,
C:\inetpub\wwwroot\ourapplication_1.0.0.7
Our deployment NAnt script is used to...
1. Unzip the new code base (creates the new application folder)
2. Update the IIS application folder to point to the new code base folder
3. Email the devs that the script has run successfully
All we have to do is drop the deploy.build script and the build zip file into a folder on each server and it will be executed - bingo, one touch deployment :)
Application Design
The application uses "Triggers" and "Processors". Triggers detect the build file has been created and Processors process the build file once the trigger has been tripped.
At the moment the service can only use a single trigger and processor. The trigger and processor combination are configured in the app.config and they are dynamically loaded when the service starts. More triggers and processors can be created in a seperate assembly if required and loaded into the service as replacements - they just need to implement an interface (ITrigger & IFileProcessor respectively).
I have supplied 2 triggers and 1 processor.
NAntProcessor - launches NAnt.exe for the build file detected by the trigger.
FileTrigger - detects the build file and immediately invokes NAntProcessor.
ScheduledFileTrigger - detects the build file and invokes NAntProcessor at the time specified. If this time is in the past it will invoke it the next day at the time required.
To switch between the normal and scheduled filetrigger have a look in the app.config "Config" section - just uncomment/comment the one you want (remember to restart the service or console app though).
The service is designed to be fairly generic. The ITrigger interface specifies Setup(), Test(), Reset() and TearDown() methods. Setup() and TearDown() are called once when the service starts and stops respectively. Test() is called every 1 seconds and if it returns true (eg it did something and triggered) then Reset() is called to reset the trigger properties. By having the implementing Assemblies dynamically loaded when the service starts its possible for you to create your own Triggers and Processors - they don't have to have anything to do with NAnt!
Programs/Installation
NAntService - A windows service application. Install this using installutil on the .exe
InstallUtil can be found in the C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 folder
To install: installutil NAntService.exe
To un-install: installutil NAntService /u
Once installed it will show up in your service list as 'NAntService'.
NOTE: The user the service is running under will impact on some NAnt tasks - be sure the .build script tasks you want run are possible with the security permissions of NAntService account you have configured it with.
NAntServiceConsole - a console application. I used this to debug the application as it provides lots of Console.WriteLine diagnostic info. Once executed it will open a cmd window and sit there waiting for a .build file to be created. To terminate it just press Enter. This application does not require and special installation - just update the app.config (NAntServiceConsole.exe.config) with your values and then run the .exe
NOTE: Config file changes to NAntService.exe.config & NAntServiceConsole.exe.config will only be picked up once the service or console application have been restarted
** IMPORTANT ** You must have the NAnt bin folder in your system PATH otherwise NAnt will not execute correctly.
TODO
* Redirect the Console output to a log file when running as a Service to provide a history of events
* Enable multiple triggers to be configured
Disclaimer
This software is provided 'As is' and no warranty is implied by its use. By using this software or parts of the supplied software the user understands it is entirely at their own risk and the author shall not be liable in any way whatsoever.
Version History
02-Nov-05 v1.0.0.0 Initial Release
Comments