Forum Moderators: phranque

Message Too Old, No Replies

uploading site files without 500 server errors during upload

When my site is launched, I want to keep uploading the code

         

phoenix_fly

8:25 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



Hello my friends,

Just to hear what you guys do to avoid causing bad surfing to your clients during code updates. IŽve noticed that when the ftp program is overwritting the online script with the new copy we have just coded up (improvements, corrections etc, you know), if some user tries to use the online file, heŽll crash, as the file is incomplete or zero-lenght.

I wonder if there is some way to avoid that... Is there? Or we just have to hang out 'till 5:00 am to do this kind of maintenance?

Thanks a lot

phoenix_fly

physics

9:17 pm on Jul 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know if this can be completely avoided (simply anyway). You might instead upload the new files to a different directory and then move the directories. For example in *nix if your site files are in www you could do
cp -r www new-www
ftp new files to new-www
mv www old-www
mv new-www www
That way it would only be down for a second and you get a backup in old-www.

victor

10:11 pm on Jul 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use FTP and used to have the same problems.

My file uploader now uploads all files (not just CGIs, also HTML tempates etc) to temporary names -- eg my-script.php-temp.

Then an "enabling" cgi whizzes through the website folders deleting and renaming files, and, when needed, setting file permissions.

Total "exposure" time for any CGI to be unavailable is a fraction of a second.

(Actually, it's slightly more complicated than that as the uploader uploads a sort of "make" file to tell the enabler the order in which to do things. That way we do things usually in the "right" order -- eg the new index.php doesn't get renamed until all new pages it refers to are enabled. But that's additional protection over and above the immediate problem you have)

phoenix_fly

10:40 pm on Jul 5, 2005 (gmt 0)

10+ Year Member



Thanks guys,

Those are pretty good ideas, thanks a lot! I think physics moving-directories may be interessting when you have modifications in many scripts, and VictorŽs enabling-script when you want to target precisely the last changes, having the choice of setting the order of the modifications.

But now it comes to me that maybe I could blend both, uploading only the modified scripts to /cgi-bin2 and having the enabling-script to go seek there for the replacements to the old mates at /cgi-bin. This way I donŽt have to worry about renaming the new scripts to temporary names (as they wont share the same directory as the old ones).

Victor said about a cgi script, but isnŽt this simpler to do in shell scripting? The point is that I am not familiar to it, so I think IŽll go look into that...

Thanks a lot pals!

Take care

phoenix_fly

physics

10:58 pm on Jul 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem ;) I think that my way should be really fast though as on a linux system moving a directory to another directory name on the same physical device is very fast. You could write a shell script that you could execute once you've copied cgi-bin to cgi-bin2 and ftp'd the new stuff to cgi-bin2 like this


#!/bin/sh
mv cgi-bin cgi-bin-old
mv cgi-bin2 cgi-bin

I bet it would be so fast that it wouldn't be necessary to write a more complicated script... worth trying anyway.
Is your box at home a *nix box? If so you could write a push-button update script using rsync and ssh keys.

jomaxx

3:02 am on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've observed the same problem when updating my .htaccess file, and I use the same basic workaround: upload it as a different name and do an "mv" from the command line.

phoenix_fly

7:10 pm on Jul 6, 2005 (gmt 0)

10+ Year Member



Hey physics and everybody,

IŽll post the shell script I created to do the magic weŽve been talking. Place it in the temporary directory you want to act as a pivot to the update.

#!/bin/bash
# I called the file update.sh

for file in *cgi # only cgi files. And not the update.sh!
do
mv "$file" ../cgi-bin/"$file" # change cgi-bin to your official scripts directory
chmod 755 ../cgi-bin/"$file"
done

echo "Update: concluded"

exit 0

I believe that in fact the renaming-directory technique can be faster than this moving-file one. But, as I am wired via dial-up to the net, to make a all-script upload is too time-consuming. So I prefer to upload only the scripts where IŽve made modifications. And, anyway, the server performs this move like a lightning flash.

Hope you like the code!

phoenix_fly