loris-imageserver / loris

Loris IIIF Image Server
Other
208 stars 87 forks source link

Loris not creating tmp file #446

Open ericvanderlinden opened 5 years ago

ericvanderlinden commented 5 years ago

I have installed Loris according to the documentation. Everything seems to be fine exept I get a Internal Server Error (500) because a temp should be created and it is not created. I'm on Ubuntu 18.

I have searched via google for reports of similar errors but nothing.

Any ideas?

mod_wsgi (pid=23297): Exception occurred processing WSGI script '/var/www/html/loris2/loris2.wsgi'.
 Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/Loris-2.3.3-py2.7.egg/loris/webapp.py", line 453, in __call__

     return self.wsgi_app(environ, start_response)

File "/usr/local/lib/python2.7/dist-packages/Loris-2.3.3-py2.7.egg/loris/webapp.py", line 396, in wsgi_app
     response = self.route(request)
File "/usr/local/lib/python2.7/dist-packages/Loris-2.3.3-py2.7.egg/loris/webapp.py", line 447, in route
     return self.get_img(request, ident, region, size, rotation, quality, fmt, base_uri)
File "/usr/local/lib/python2.7/dist-packages/Loris-2.3.3-py2.7.egg/loris/webapp.py", line 668, in get_img
     image_info=info
File "/usr/local/lib/python2.7/dist-packages/Loris-2.3.3-py2.7.egg/loris/webapp.py", line 722, in _make_image
     delete=False
File "/usr/lib/python2.7/tempfile.py", line 485, in NamedTemporaryFile
     (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
File "/usr/lib/python2.7/tempfile.py", line 254, in _mkstemp_inner`
     fd = _os.open(file, flags, 0600)

OSError: [Errno 2] No such file or directory: '/tmp/loris2/tmp/tmp1G9IJi.jpg'
alexwlchan commented 5 years ago

This looks like a straight-up bug – we assign a temporary directory from the loris.Loris.tmp_dp config setting, but never do anything to check the directory exists or that we can write to it!

You should be able to fix this by running mkdir -p /tmp/loris2/tmp on the system that’s running Loris. I’ll have a look at writing a patch so that Loris handles this automatically.

ericvanderlinden commented 5 years ago

It is always a good ideas to do the checking, but in this case the tmp directory in /tmp/loris2 did exist.

alexwlchan commented 5 years ago

Okay, that’s weird. There might be a problem if Loris didn’t have permissions, say, but then I’d expect to see a different error coming out.

ericvanderlinden commented 5 years ago

Wel I put the permissions on 777 just to make sure... but I still get the same error.

ericvanderlinden commented 5 years ago

You closed this with a solution to a problem I did not have. So I think I must conclude from this you have no ideas...

alexwlchan commented 5 years ago

It got closed automatically by GitHub. I take it you’re still seeing this error?

ericvanderlinden commented 5 years ago

Yes. I was about to rewrite the function in webapp.py to create a temp file bypassing the python module. To see if the problem is python NamedTemporaryFile.

ericvanderlinden commented 5 years ago

Does Loris keep versions of webapp.py somewhere in a cache? I have tried to change some line of code to see what would happen. And now it seems like I get a different response every time I reload.

To be honest... I think I'm going to give up... Maybe there is some problem with Ubuntu 18.04... and temp files....

I deleted temp_file = NamedTemporaryFile( ... And created a new binairy file with open() to see if a file is created... But no file created.

Now I get the same error as befor... but also: Server Side Error: [Errno 2] No such file or directory: '/tmp/loris2/tmpfile2.jpg'

This is likely a permissions problem, though it's possible that there was a problem with the source file (/usr/local/share/images/01/03/0001.jpg). (500)

Server Side Error: [Errno 2] No such file or directory: '/tmp/loris2/tmp/tmp/file2.jpg'

This is likely a permissions problem, though it's possible that there was a problem with the source file (/usr/local/share/images/01/03/0001.jpg). (500)

bcail commented 5 years ago

@ericvanderlinden could you try using a different tmp directory? Maybe try setting the tmp directory to be in your home directory, and see if anything changes. Is /tmp a normal directory on /, or is it mounted somehow?

ericvanderlinden commented 5 years ago

I changed the temp directory to 
 /home/loris/tmp

What happened was that as I kept reloading the image Loris seemed to hope from one version of the loris.config and webapp.py to the other, but did not use the latest version. 
The reason I was puzzled by this behavior is that I have never experienced this before and I have been using a Leaseweb virtual server for the last 4 yours.

This morning I restarted the server and now it works.

Maybe /home/loris is a better initial setting.

For your information:
 server: https://www.leaseweb.com/nl/cloud/public/virtual-server 
installed 2/2019 with Ubuntu 18.04 and the most recent versions of all software like Apache etc.

bcail commented 5 years ago

@ericvanderlinden does "mount | grep /tmp" return anything on the machine?

ericvanderlinden commented 5 years ago

Sorry I have been away. Mount | grep /tmp returns nothing.

bcail commented 5 years ago

@ericvanderlinden can you confirm that you can create a file in /tmp as the loris user? If it works using "touch /tmp/test", maybe you could try with a tiny python script like this:

import tempfile
with tempfile.NamedTemporaryFile(dir='/tmp', delete=False) as f:
    print(f.name)
    f.write('test')

Does it create the file there?

ericvanderlinden commented 5 years ago

I logged in as loris. cd /tml I started nano and created a file test.txt This was successful. Then I create a directory mkdir loristest This was successful as well

I hope this answers your question

bcail commented 5 years ago

ok, that shows that the Loris user can create files/directories in /tmp. You could try the little python script if you want. I'm not sure why the Loris code can't create files, when the loris user can.