inotifywait not reacting to file creation by apache

395 views Asked by At

I have a script which is supposed to copy photos uploaded by admin users to our website to two other backend servers. To do so it does the following:

while true; do                                                                                                                                                                                                                                     
    inotifywait -e create "$TRANSFER_FILES" && \                                                                                                                                                                                               
            sleep 20 && \                                                                                                                                                                                               
            copy_files "$SSH_SERVER_1" "$REMOTE_DIR_1"  && \                                                                                                                                                                                               
            copy_files "$SSH_SERVER_2" "$REMOTE_DIR_2"
    sleep 2
done

The sleep 20 is to give apache time to resize the uploaded images.

The problem:

If I create a file in the $TRANSFER_FILES directory (which is on a local filesystem), either as root or the apache user, with touch or cat or whatever, inotifywait receives the CREATE evenc and the copy_files function (wrapping rsync) is called. However, when the apache process creates the files, nothing happens.

1

There are 1 answers

0
anydot On

Not direct answer for your question, but you should consider using lsyncd. It does exactly what you are trying to do: It waits through inotify and then run synchronization (by default by rsync). It's standalone daemon, well tested.