Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This problem happen quite frequently while uploading a .war or .ear, that are just little more than .zip file, to a remote server, and have it deployed by the application server.

Usually, at development stage, an application server is on 'hot deploy', which means that the application server itself is listening for change on a specific directory, if it recognize that a valid application file (.ear or .war) has been dropped in it, then it is unpacked and deployed as java application.

It happens that while the upload is in progress, and this is usually done with tools like ant or maven directly from the development environment, the application server start deploy, to discover later than it is a corrupted zip file because the upload wasn't finished yet.

The workaround I found is to upload to an external directory, then connect to ssh and mv the file to the 'hot deploy' location.

Do you have any suggestion on how to deal with this ? I am not a system administrator, but what I would like to have is a kind of shell script (maybe run under cron) that listen to a directory and when an upload is incoming (via scp), wait until it is finished then do a mv to the server directory.

What variables do I have to take into account for building this script ?

share|improve this question

If you want to automate it on the deployment server, you can have a file let's say "src.upload.complete.txt" to be uploaded as the last file after uploading your .war.

setup a crontab checking the "src.upload.complete.txt" file every minute, once it finds it, it moves the .war file to the deployment directory. Then it removes the "src.upload.complete.txt" file as well.

I didn't have time to test this, but it could be something like this:

To setup a crontab to check every minute, add this line to /etc/crontab

* * * * * /path/to/bash/

your should look something like this.


FILE_PATH = '/path/to/your/file'
if [ -f $FILE_PATH ]; 
         mv /path/to/src.war /path/to/deploy.war    
         rm /path/to/src.upload.complete.txt 
share|improve this answer

What about something like:

scp my.war user@remote:/tmp && ssh user@remote 'mv /tmp/my.war /production/directory'
share|improve this answer

If you use rsync instead of scp to update the file, it should create a temp file with a different name, then when the integrity is checked move it to the correct name. I think that is more or less the behavior you need. Default options should do it. Just replace scp with rsync if you aren't using any particular options (see man rsync for details). rsync sourcefile user@dest:/dest/directory/

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .