Reset Your Application – wget and Ant
Monday 11 June 2007 - Filed under Code
I'm using Ant now to do all my deployment to our servers. Today I decided to see if I could use wget to reset my application after a build. I like to do this just to make sure after I deploy a new build - that everything is reset in case I added something that needs to be set/reset in the application scope.
First I downloaded wget for Windows. There seem to be a lot of versions of wget floating around but I picked this version because it has SSL/HTTPS support compiled in and I need to run this against a secure server.
Simply copy the wget.exe executable into your C:\WINNT dir (on Windows XP) so that you can execute wget from any location.
In my application I have a bit of code which will reset my application if I pass a query string in the URL:
http://localhost/index.cfm?reset=true
And in my Application.cfc I have:
So I initially tried to run the same thing using wget:
C:\>wget http://localhost/survey/?reset --spider -d
A few notes on the command line switches: --spider prevents wget from downloading anything, -d - enables debug which is useful during initial testing, and -- help will display all available options.
This worked on my localhost - but when I tried it on the live server I received "ERROR 500: Internal Server Error".
After a bit of trial and error the culprit turned out to be the cflocation after the reset. When I removed that - everything worked!
So in order to work around that I added another parameter to wget - a user-agent string:
C:\>wget https://my.secure.url/index.cfm?reset --http-user=MyUsername --http-passwd=${my.password} --spider --no-check-certificate --user-agent=wgetreset --no-verbose
I'm passing in my authentication using --http-user and --http-passwd. I'm setting the value of the 'my.password' property earlier when I checkout my code from SVN - see this post for more information. I also set the user-agent string using --user-agent=wgetreset.
Now I simply modified my application.cfc to prevent the cflocation from firing if the request was made via wget:
-
<!--- need to lock this call to prevent any race conditions -->
-
-
<!--- restart the application -->
And finally in my build.xml file I added a new target to perform the reset:
-
<!-- Check the status of the reset operation -->
-
-
-
-
-
-
-
-
-
------------------------------------------------
-
Files moved to ${project.build.final} successfully!
-
------------------------------------------------
-
Application reset: ${status}
-
------------------------------------------------
This runs at the end of my build. It executes wget and dumps the results of the command into a property ${wget.output} which I then check to see if it ran OK or if there was an error.
2007-06-11 » Jim Priest
11 June 2007 @ 12:32 pm
(Had to redo this with no start and end brackets) Just FYI you can do this without the need for any special download:
exec executable=”C:/Program Files/Mozilla Firefox/firefox.exe”
arg value=”http://mysite.com/myapp/index.cfm?reload=true”
/exec
11 June 2007 @ 12:51 pm
Brian – I did see that in the Ant docs but there is no way to pass the HTTPS info using that method unless I missed something?
11 June 2007 @ 1:05 pm
Ahh, I never tried it with https, but I would think that just using https in the URL you give Firefox would work? If not, then yep, the wget is probably the way to go.
12 June 2007 @ 8:47 am
Sorry – I had a case of protocol confusion yesterday!
Yes – that would work for HTTPS – I also had to authenticate on our server hence the username/password and wget…