My problem is: I have a running lighttpd web server. The files are stored in \var\www, also a python script, which can be executed to get an image from the raspi camera. Every time the script is called, one image should be delivered to the browser.

The lighttpd itself seems to work, I can see my web page from the browser, I also can execute the phyton script (snap.py). But I get only ONE image from the server. The web server executes the script, the script creates a temporary /run/shm/img.jpg. this image is then delivered by the web server. The web server runs on a user "www-data". I can see that the image in /run/shm is owned by "root" and not by "www-data". And this seems to be the problem.

Once this image is created, all later calls of the script cannot delete the temp. image to create a new one.

I currently have no idea why a web server running with "www-data" access rights creates files bolonging to "root", which later cannot be deleted any more..

I'm using this script on 2 older raspis (older installations). There this script runs fine , but now on a new installation I have this problem...

Can anyone help ?

This is the python script:

import sys
import subprocess
import os
import ftplib
import time
import smtplib
import Image
import cStringIO
import SunRiseSet_Lendersdorf

#verschiedene Kameraeinstellungen fuer tag und nacht
FTEMP_DCAM = "/run/shm/img.jpg"
CAPT_UTIL   = "raspistill"  
CAPT_DCAM_DAY   = " -t 500 --ISO 200 -w 1600 -h 1200 -ex auto -o " + FTEMP_DCAM
CAPT_DCAM_NIGHT = " -t 500 --ISO 800 -w 1600 -h 1200 -ex night -o " + FTEMP_DCAM

except OSError:

# Aktuelle Zeit, Sonnenauf-und Untergangszeit bestimmen
lt = time.localtime()
ActHour  = float(time.strftime("%H" , lt))
ActMin   = float(time.strftime("%M" , lt))
ActHour  = ActHour + ActMin/60.
RiseHour = SunRiseSet_Lendersdorf.GetLendersdorfSunRiseOrSet ( 1 )
SetHour  = SunRiseSet_Lendersdorf.GetLendersdorfSunRiseOrSet ( 0 )

# Zugriff mitloggen
#f = open('SNAP_ACCESS.TXT', 'a')
#f.write(time.strftime("%d.%m.%y %H:%M:%s",lt))

    if ActHour > RiseHour and ActHour < SetHour:
        error = subprocess.check_output(CAPT_UTIL+CAPT_DCAM_DAY, shell=True, stderr=subprocess.STDOUT)
        #print "DayTime"
        error = subprocess.check_output(CAPT_UTIL+CAPT_DCAM_NIGHT, shell=True, stderr=subprocess.STDOUT)
        #print "NightTime"
except subprocess.CalledProcessError as e:
    #print "CalledProcessError" 

sys.stdout.write( "Content-Type: image/jpeg;\n\n" + file(FTEMP_DCAM,"rb").read() )
  • Lighttpd runs with uid=www-data, gid=www-data. So wherever you write temporary files (unless you use /tmp), you need to add www-data (userid) or www-data (group) to the access permissions. – Dougie Apr 27 at 20:41
  • yes, may be I do not understand the "ls -la" output correct is the owner "root" and the group "www-data" ? pi@raspberrypi:~ $ ls -la /run/shm lrwxrwxrwx 1 root www-data 8 Apr 27 12:18 /run/shm -> /dev/shm the directory is now empty – Wolli Apr 28 at 7:51
  • I tested with "/tmp" directory instead of "/run/shm." then I get a "Server Error 500" from the web browser. if i run the script manually as user "pi" it runs correct,meaning the old temp. file will be deleted, new file created by raspistill and the output is printed on the terminal. I think there is some access right problem – Wolli Apr 28 at 8:17
  • I have to correct one comment: If the web server runs the python script, the img.jpg is not created. I think during my tries running the script with user "pi" it was "left over". This means the img.jpg cannot be created and not deleted. – Wolli Apr 28 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.