views:

29

answers:

2

Hi all,

I've searching for this for a while now online (Google, and StackOverflow), but haven't yet come across this question. Maybe my query is not correct (please redirect then!)

I've developed and set up a WebApp on TomCat 6 under Linux. Tomcat isn't running in a virtual host environment yet, I have full control over server. Therefore, .war file is saved to Tomcat's standard deploy dir. The app is a hotel booking service, using multiple sources to locate best price. The issue I have is with images. Different services offer different sized images, and I need to resize them to make them look uniform.

I download them and resize them without problems, but have to store a local copy of the image as this takes some time if done real-time, plus a lot of bandwidth waste. I don't save them under the .war's temp dir under Tomcat, due to case where a server shutdown would force me to reload all images.

I created a different directory under /home/username/images, which I then serve under a different subdomain through regular Apache, and the HTML code generated in the .jsp is simply a correct URL to the file. Works great if the image doesn't exist. However, due to permission issues, the Tomcat instance cannot remove or overwrite files already created, even though I've marked the folder where images are stored with 777 permissions. As an aside, I don't see need to give it 777 perms, but with 755 (for example), I had permission issues even when trying to save a new file.

So: is there a better solution (I considered DB, but the images dir is now 250mb, and I see no need to overload the db so much)?

Sorry for such a long question, but I saw no easy way to ask it :)

Thank you in advance!

+1  A: 

Don't store the images in the database. Your /home/user/www.example.com/resources approach is in the correct direction, just sort out the privileges issue. Make sure the path is in a group where the user who runs tomcat (tomcat?) belongs in and reduce the 777 because it's too broad.

cherouvim
Thank you cherouvim. I wasn't going to go for DB, I never liked that approach. :) I'll have to play around with Linux permissions, which is what I thought the issue lay in. So adding user tomcat (yep, correct) to the group of owner of /home/user/..../resources is the correct approach? Also, what is the minimum permissions necessary for this to work - 644? or 755? Thanks again!
mno2go
Yes because you want to it to have read/write access to the folder. Make sure the middle number (representing a group) has read/write access, so a 6 will do.
cherouvim
Storing files in the database is slower, but has huge advantage: database transactions (ACID properties). When you store it on the disk, you don't have transactions, for example when you save the data, and then something fails, the data will still exist on the disk (won't be rolled back), so you have to handle it manually or ignore if it's not important problem for you.
iirekm
Yes, that is very true. I weighed that option, but already Serialize and store some other objects in the DB (hotel details that are generally static), which takes up about 100mb, and didn't want to further load it up with reads (adding images would add A LOT of SELECT operations).
mno2go
A: 

What specifically is happening with the permissions? Tomcat will be running as some userid (say tomcat1) and will be creating files presumably owned by the same user (tomcat1). If your files are being created with a different owner, then that will explain why you can't overwrite existing downloads and you'll need to work out why the ownership is differen. If it's not ownership, then are the files being created without write permission to the user. In this case, consider explicitly setting the permissions on each file saved to allow the owner to write to it, or change the umask of the user account.

jowierun
"or change the umask of the user account." -- hmm, interesting idea, thank you!
mno2go