Interceptors:Deploy
<< Back to Dashboard | << Interceptors Viewer
|
Deploy Interceptor
Introduction
This interceptor reads and stores a_deploy.tag file to check for new deployments to a server or server cluster. If the tag has been udpated, the interceptor tells the application (ColdBox) to reinitialize itself. So basically, you don't have to worry about restarting applications or cleaning stuff out or removing files. Just worry about getting another cup of coffee.
- Download: http://coldbox.org/forgebox/view/deploy
How it works?
Once the application starts up, it reads the date/time stamp on the tag file and saves it on memory as a setting. This deploy interceptor will save you countless pains and mishaps when deploying new builds to a production server or cluster of servers. As each server receives a new request, the deploy tag is compared, if changes are detected, the framework re-initializes the entire application on that specific server and then processing continues with all the new code initialized. What else do you do? Well, maybe get more sleep when doing deploys.
Making Life Easy: ANT
You can use the included ANT script to touch the file with a new timestamp when doing new deploys to your production server or server cluster. Then just make sure you include the file in your deploy.
<?xml version="1.0"?> <-- <====================================================================== ******************************************************************************** Copyright 2005-2008 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.coldbox.org | www.luismajano.com | www.ortussolutions.com ******************************************************************************** Deploy tag stamper by Luis Majano ====================================================================== --> <project name="deploytag" default="do.deploytag" basedir="."> <description> Creates a new deploy tag timestamp </description> <property name="deploytag.path" value="_deploy.tag" /> <target name="init"> <-- <Init TimeStamp --> <tstamp> <format pattern="MMM-dd-yyyy HH:mm:ss" property="TODAY"/> </tstamp> <available file="${deploytag.path}" property="isFileAvail" /> </target> <target name="do.delete.tag" if="isFileAvail"> <delete file="${deploytag.path}" /> </target> <target name="do.deploytag" depends="init, do.delete.tag"> <-- <echo tag --> <echo file="${deploytag.path}">DEPLOYING ON:${TODAY}</echo> </target> </project>
How to set it up?
- Download the interceptor from ForgeBox: http://coldbox.org/forgebox/view/deploy and install in your preferred folder.
- Place the _deploy.tag and deploy.xml ANT task in your /config directory of your application.
- Add the Deploy interceptor declaration:
interceptors = [
{ class="mypath.interceptors.Deploy",
properties={
tagFile = "config/_deploy.tag", deployCommandModel="DeployCommand"
}
];
Interceptor Properties
The interceptor can be configured with the following properties:
- tagFile : config/_deploy.tag [required] The location of the tag file.
- deployCommandObject : The class path of the deploy command object to use [optional].
- deployCommandModel : The name of the model class to use for the command object. This is requested from WireBox.
Deploy Command Object
The deploy command object is a CFC that must implement the following interface if WireBox will not be creating it:
public function init(controller){}; public function execute(){};
If you are using WireBox then you have much more control of the constructor, dependencies, etc. So you only have to implement the following:
public function execute(){};
In the execute() method you will put your own custom code that executes once a new deploy is detected. This can be from file cleanup, to cache cleanup, to announcements, etc. Here is a sample:
component{
// DI
property name="log" inject="logbox:logger:{this}";
function execute(){
log.info(" Your application has detected a new deploy, cleanup files now");
cleanupFiles();
}
}
Overview
Maintaining deploys in a production environment of one or more servers can be a drag. You don't want to re-initialize the servers or reboot them if necessary. With this nifty interceptor, all you do is deploy with a tag file and the interceptor does the rest. Now you can have more time to play Warcraft (Shhh don't tell the boss)

SideBar
User Login 




Comments (