I don't think Linux systems guarantee an entire file write is an atomic process, do they? The process doing a file write can generally be interrupted by the OS task scheduler, and paused while another process starts which is reading that file, regardless of internal buffers. That's why things like .lock files, or checking if the file is open elsewhere, is needed if you want to be sure you have a complete file.
How about if you have two JPEG output files and ping-pong between them. After each fresh file is written, you swap a symlink to the newly updated one, and your static HTML page refers to that symlink, not the file directly.
http://en.wikipedia.org/wiki/Symbolic_link
I haven't tried this, so maybe my syntax is wrong, but I am thinking of something like:
Code: Select all
<html><head>Current Events</head><body>
Here is what it looks like now! <img src="NOW.jpg"> </body></html>
...and meanwhile, a script is running to write alternate files and then swap the "NOW" link to it:
#!/bin/bash
while [ 1 ] do
raspistill -o file1.jpg
ln -f -s file1.jpg NOW.jpg
raspistill -o file2.jpg
ln -f -s file2.jpg NOW.jpg
done
At least with some servers and some browsers, even pressing refresh will not update to a new picture of the same name, unless it has a timestamp different by at least 1 minute from the previous one. Maybe there is a workaround for this, I don't know.