I'm looking for a solution for being notified about files and directories modifications using inotify or any other API when the files are located on a file-system on a custom board that is configured as a USB device. My Linux is buildroot and deployed on a custom board. I've connected the board to a Host machine running Ubuntu. After creating the file-system on the board I can copy files into the target board with no problems. What I would like to achieve is to get notifications about changes in files and directories on the Linux OS running on the board where the file-system is located. For example, is someone is copying a txt file from the Ubuntu host into the mounted directory I will get a notification on the target board.
What I've been able to do so far is to be notified that a change on the file-system has occurred but could not achieve a specific notification about exactly what has changed. This is how I've accomplished that:
On the target board I've created a file based file-system using:
dd if=/dev/zero of=/tmp/test bs=1M count=500
Then I created a file based file system out of it:
mkdosfs /tmp/test
Then I then started to listen to file-system events (on the target board) with:
inotifywait /tmp/test
Then I copied a foo.txt file onto the mounted directory on the Ubuntu Host side.
I then received a notification (on the target board) that /tmp/test has been modified.
What I want to achieve is to get notification about foo.txt on the board, and once I will be notified about that file I want to have access to it, also on the board. I have no problem if the final solution would be to get notifications about a predefined directory on the mounted file-system if that would be easier.
Is there any way to achieve what I'm asking?
Thanks!
Is there any way NFS client machine to know about changes made on remote file system by another client? How can it know - "Which new files are created, deleted or modified"? NFS share is mounted on Linux machine.
I'm developing daemon monitoring SD card directory with using fanotify.
But, all users have their own mount namespace, so daemon can't receive fanotify event though user app writes SD card (same directory with above).
How can I monitor all mount namespace?
Each mount point needs to be manually added by fanotify_mark().
Here is is a good example:
I have inotify on my linux server. I looked up a whole lot of posting online on how to use inotify and found a sample c code that watches a directory for file create/delete. It worked fine on both local directory and nfs direcory(which is what i really need)
Now looking at opitons on how to make this a always running process i see there are the below options at least from what i understand
I guess try to run this c code with a wait and never close it?
incrond - which apparently is a daemon process. I dont seem to have it on my linux server i have rhel5 so i guess i need to install it. Not very clear on how the incrond would work.
inotify-tools - this sounds the easiest as it says i can just use commands in a shell script
I also have questions like what happens when the nfs mount is removed, server shuts down etc., would inotify know to pick up from where it left?!
I know this is a lot of questions but any pointers would help me a great deal. Thanks in advance. Meanwhile i will continue playing with the sameple c code.
I don't think that inotify(7) works reliably with network file systems (either NFS or CIFS).
It could work (on the local host) if the local host is modifying/writing some NFS mounted system.
It won't work (on the local host) if some remote client is modifying/writing some NFS mounted system (mounted by the local host).
Because the NFS protocol (at least those that I know, pre NFS4) is an RPC protocol, and there is no way for the remote NFS server (mounting that NFS system) to signal to distant clients that something is happenning.
Our Symfony2 webapp uses the Assetic watcher in development mode to re-compile assets on the go.
The webapp runs in a Docker container which runs in a Vagrant VM (Ubuntu 12.04 Precise).
The host is OSX 10.9 Mavericks and it shares the code folder with the VM through a NFS (v3) share and the code is mounted in the container via a host/guest volume in Docker.
Since inotify seems to not be able to detect file modifications over NFSv3, the watcher works in polling mode which can be very slow (~1/2 minutes to detect the modification).
I've read that NFSv4 is inotify compliant but I did not found any good ressource on that.
Is there a way to make NFS/inotify works together?
Unfortunately, inotify cannot work on NFS. inotify works by hooking itself in the VFS (virtual filesystem) layer, in the kernel. Whenever a modification happens, inotify knows about it, because the modification happens on the same machine, therefore in the same kernel — which makes the whole thing possible.
With NFS, modifications happen on the server, and notifications are expected on the client. But the NFS doesn't notify the clients when a change is made. Otherwise, it wouldn't scale. NFS has been designed (and operated) to have thousands of clients on a single server. Imagine if you do a tiny change, and the server has to push it to all clients!
Of course, you could say "hey, there should be a subscription mechanism in the NFS protocol, so that clients can tell the server that they want to know about changes happening in a specific location". Well, NFS was designed 30 years ago, so forgive them for not including this subscription/notification system :-)
I'm not familiar with Assetic, but maybe you could have a custom script to watch for changes manually, and re-compile assets each time you detect a change. Just walk through the directory containing the source for the assets, keep track of the mtime of each file in an associative array, and each time you detect a new file (or a new mtime), recompile. Boom!
See also this other SO question about inotify and NFS.
Here is a plugin which aim to solve this: https://github.com/mhallin/vagrant-notify-forwarder
Just install it and reload your boxes to have inotify notifications forwarded to your guests machine:
vagrant plugin install vagrant-notify-forwarder
You might be interested in this tool called Guard it listens to the file changes made on host OS, and then on Guest it pulls and update those. This worked for me, and now my assets are updated almost instantaneously.
https://serverfault.com/questions/453826/vagrant-shared-folder-and-file-change-events