WAR File Auto Deployer

Ok, here its scripts for auto deploying war file, so i don't have to wait all the employees logged out before i can bring down the server ;)

1) create a file with name '/erp/scripts/war-deployer.sh'

#!/bin/bash
#
# WAR File Deployer Script
# description: Its simply stop service, backup file, replace file, and start the service again.
#

WAR_FILE="erp.war"
DIST_DIR="/erp/readyToDeploy"
DEPLOY_DIR="/usr/jboss/server/default/deploy"

# stop jboss server
/sbin/service jbossd stop

# backup
BACKUP_FILE="/erp/backup/$WAR_FILE-"`date +%F_%H-%M`".bak"
echo "Creating backup file $BACKUP_FILE ..."
/bin/cp "$DEPLOY_DIR/$WAR_FILE" "$BACKUP_FILE"

# replace
echo "Replacing $DIST_DIR/$WAR_FILE with $DEPLOY_DIR/$WAR_FILE"
/bin/cp "$DIST_DIR/$WAR_FILE" "$DEPLOY_DIR/$WAR_FILE"

# start jboss server
/sbin/service jbossd start


2) Then assign it in crontab:
run command crontab -e to insert job to be executed tonight into crontab. Then add following line:

05 22 7 3 * /erp/scripts/war-deployer.sh

It will execute script /erp/scripts/war-deployer.sh on 07 March 2011 22:05

3) Done! and let see if it will do the job :p

By given method above, all i need to do is put new erp.war file on distribution directory and change Day-of-month and Month field on crontab every time i need to update the application.
Btw, it will work great too if i have fixed schedule to update the app. consider this cycle: develop/bug fix > test > distribute it by put war file on dist directory and forget the 'deploy' part... ;)


read more about cron on : http://en.wikipedia.org/wiki/Cron.

update[March 26, 2011]
- fixed script (variable $DIST_FILE -> $DIST_DIR).
- crontab entry (year removed, and change ? with *).

No comments:

Post a Comment