Easy way to auto upload modifications to server under osX (live development)

Here is very simple way to setup immediate automatic upload of source code modifications to server via ssh. This gives you ability to perform live development and testing of your solutions. There are a lot of utilities to achieve this and you even can write some not-so-comlicated script doing recurrent compare of file modification times yourself – but there is very easy solution from Facebook, called watchman. To install it under OsX use Brew

Watchman will call upload script for each modified file – lets write this script and call it uploadauto.sh. It will be really short!

I assume you have ssh keys on server and don’t do manual password entry. Put this script into the folder you want to synchronise. And finally we need to say to watchman to look over this folder and call our script when something changes:

Replace here /Users/me/project1 with your folder name. upload is the name of the trigger. ‘*.*’ is the mask for files to be monitored. More information about trigger syntax can be found here.

And thats all!

To stop the trigger you can use: watchman trigger-del /path/to/dir triggername. To stop watching over folder: watchman watch-del /path/to/dir

Also you can add to script some actions to notify the server to rebuild the service on server side or perform some post processing there. So you can customise the process as you want.

This solution should also work under Linux systems with inotify.

ps. Dont use this for deployment – only for testing and developing.  For production i recommend use version control repositories from your own distribution server.

pss. This tool was initially developed to reduce compilation time so you can setup it to compile each file upon modification. I guess you can imagine other applications.