I have a very simple script to log when new files are created, in fact, for test purposes I told it to watch for any event.
#!/bin/sh
WATCHED_DIR="/var/www/html/magento/media/tmp/catalog/product"
echo "Watching directory: $WATCHED_DIR for events"
inotifywait -m -q -r "$WATCHED_DIR" --format "%|e %w%f" |
while read resp
do
echo "$resp" >> watcher.log
done
when i create a file within the watch directory, it reacts and logs
CREATE /var/www/html/magento/media/tmp/catalog/product/2/1/new file
OPEN /var/www/html/magento/media/tmp/catalog/product/2/1/new file
CLOSE_WRITE|CLOSE /var/www/html/magento/media/tmp/catalog/product/2/1/new file
OPEN /var/www/html/magento/media/tmp/catalog/product/2/1/new file
CLOSE_NOWRITE|CLOSE /var/www/html/magento/media/tmp/catalog/product/2/1/new file
OPEN|ISDIR /var/www/html/magento/media/tmp/catalog/product/2/1
OPEN|ISDIR /var/www/html/magento/media/tmp/catalog/product/2/1/
OPEN /var/www/html/magento/media/tmp/catalog/product/2/1/new file
CLOSE_NOWRITE|CLOSE /var/www/html/magento/media/tmp/catalog/product/2/1/new file
CLOSE_NOWRITE|CLOSE|ISDIR /var/www/html/magento/media/tmp/catalog/product/2/1
CLOSE_NOWRITE|CLOSE|ISDIR /var/www/html/magento/media/tmp/catalog/product/2/1/
OPEN /var/www/html/magento/media/tmp/catalog/product/2/1/new file
CLOSE_NOWRITE|CLOSE /var/www/html/magento/media/tmp/catalog/product/2/1/new file
OPEN /var/www/html/magento/media/tmp/catalog/product/2/1/new file
CLOSE_NOWRITE|CLOSE /var/www/html/magento/media/tmp/catalog/product/2/1/new file
but when apache creates a file, nothing is logged
The only difference I can spot is when apache creates the file, the file is owned by apache, where as when i create the file, it is owned by root.
-rwxrwxrwx. 1 apache apache 55659 Feb 11 16:46 2164.jpg
-rw-rw-r--. 1 root root 0 Feb 11 17:02 new file
The watcher script is run as root.
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 0 29137 2705 0 80 0 - 26538 wait pts/14 00:00:00 test.sh
1 S 0 29139 29137 0 80 0 - 26538 pipe_w pts/14 00:00:00 test.sh
Does anyone know the solution?
You are using the recursive mode, which adds watch automatically for all subdirectories. The maximum amouint of inode watches per user is 8192, are there more than 8192 directories under /var/www/html/magento/media/tmp/catalog/product ?
if it's greater than 8192 you can do as suggested by the man page: write to /proc/sys/fs/inotify/max_user_watches
Also, might look stupid but in data you provide, we can see that the apache file was created 16 minutes before the file created by root. Are you certain you launched your script before Feb 11, 16:46 ? Also, if you launched it just before, there is possibility that you did not receive the event because the program was still recursively creating the inode watches, and since you use the "-q" option you have no way to know when this phase has completed.
Seems it took a while to start recording but when it eventually did, it wasnt reporting CLOSE_WRITE, it was reporting MOVED_TO