Neither one nor Many
Software engineering blog about my projects, geometry, visualization and music.
This should work for all their editors, PyCharm, Intellij, CLion, PhpStorm, Webstorm, etc.
The editor(s) use this tool to "subscribe" to changes on the filesystem. So if you change a file that's also in a buffer in for example CLion, it will know it needs to reload that file from disk in order to show the latest changes.
Without this tool it will fallback to periodically checking for changes or when a specific file is activated, I don't know exactly, but it's slower anyway.
You probably started searching for a solution because you saw this error in the console or in a popup in the IDE:
trigen@baymax:/home/trigen/Downloads/clion-1.0.4> FSNOTIFIER_LOG_LEVEL=info ./bin/clion.sh
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=350m; support was removed in 8.0
[ 3243] WARN - om.intellij.util.ProfilingUtil - Profiling agent is not enabled. Add -agentlib:yjpagent to idea.vmoptions if necessary to profile IDEA.
[ 14166] WARN - api.vfs.impl.local.FileWatcher - Project files cannot be watched (are they under network mount?) <<<<<<<<<<<
Let's fix it by having the IDE run fsnotifier over SSH on the actually server.
I will use as an example a project named MyFirstProject
mounted via NFS from a server named DevelopmentMachine
:
sudo mount -t nfs DevelopmentMachine:/home/ray/projects/MyFirstProject /projects/MyFirstProject -o rw,user,hard,intr,tcp,vers=3,timeo=600,_netdev,nolock,exec
First you need fsnotifier on DevelopmentMachine
, because that machine should be able to subscribe to the filesystem events.
I downloaded and build the one from ThiefMaster/fsnotifier-remote.
Test it by starting it and adding the project like this (>>>
is your input, <<<
the output you get):
[ray@DevelopmentMachine linux]$ ./fsnotifier
>>> ROOTS
>>> /home/ray/projects/MyFirstProject
>>> #
<<< UNWATCHEABLE
<<< #
Now it's watching, trigger some changes on something in that root (i.e. open a vim hi.txt
):
<<< CREATE
<<< /home/ray/projects/MyFirstProject/.hi.txt.swp
<<< CHANGE
<<< /home/ray/projects/MyFirstProject/.hi.txt.swp
<<< STATS
<<< /home/ray/projects/MyFirstProject/.hi.txt.swp
...
In this example I work locally on /projects/MyFirstProject
, where it's /home/ray/projects/MyFirstProject
on the server.
The super easy solution is to make sure your local path is exactly the same. In my case I made a symlink so I have /home/ray/projects/MyFirstProject
both on my local- and remote machine.
On the local machine I can run the above ./fsnotifier
example through ssh, lets test that (make sure you have ssh keys configured correctly for this, otherwise you will get an authentication prompt):
trigen@baymax:/projects/fsnotifier-remote[master]> ssh -l ray DevelopmentMachine /home/ray/projects/fsnotifier-remote/linux/fsnotifier64
>>> ROOTS
>>> /home/ray/projects/MyFirstProject
...
The fun thing is that the displayed files are actually already correct, so you don't need to do some any mapping. Just make sure you launch your IDE on the /home/ray/projects/MyFirstProject
folder.
(Which the beforementioned fsnotifier-remote
script should be able to do, but I encountered multiple issues executing it under Linux and I didn't like to dive into it's Python code).
I created a local fsnotifier
script with the following contents:
#!/bin/ksh93
ssh -l ray DevelopmentMachine /home/ray/projects/fsnotifier-remote/linux/fsnotifier64
Then told my IDE to use this wrapper (make sure it's executable with chmod +x
)
trigen@baymax:/home/trigen/Downloads/clion-1.0.4/bin> vim idea.properties
idea.filewatcher.executable.path=/projects/fsnotifier-remote/fsnotifier <<< add this line!
You can log the communication between the IDE and fsnotifier over ssh by inserting this in the fsnotifier wrapper script: strace -f -F -ttt -s 512 -o /tmp/fsnotifier-debug.log
(put it before the ssh command).
Then you can find stuff like this in the /tmp/fsnotifier-debug.log
:
823 3722 1439468464.159229 read(4, "ROOTS\n", 16384) = 6
833 3722 1439468464.159644 read(4, "/home/ray/projects/MyFirstProject\n", 16384) = 28
843 3722 1439468464.160011 read(4, "/home/trigen/.clion10/system/extResources\n", 16384) = 42
853 3722 1439468464.160489 read(4, "#\n", 16384) = 2
Hope this approach will help others!
Having this script in place allows for some fun "performance optimizations" in case you have a slow network connection.
Michele
2016-08-17 16:09:36