2

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.

Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59
  • is $TRANSFER_FILES on an NFS filesystem or in local? – Nahuel Fouilleul Sep 10 '12 at 09:24
  • local. I'll update the question. – Tom Macdonald Sep 10 '12 at 09:26
  • 4
    Does Apache actually create the file in `$TRANSFER_FILES`? If the file is created elswhere and then moved to the directory there won't be a `create` event for `$TRANSFER_FILES`. Try monitoring events on the directory by running `inotifywait -m "$TRANSFER_FILES"` when you create a file via the Apache process. – Ansgar Wiechers Sep 10 '12 at 13:57

1 Answers1

1

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.

anydot
  • 1,499
  • 9
  • 14