Skip to content

Instantly share code, notes, and snippets.

@oleksiyp
Last active August 29, 2015 14:05
Show Gist options
  • Save oleksiyp/66e496343642dc9cafe3 to your computer and use it in GitHub Desktop.
Save oleksiyp/66e496343642dc9cafe3 to your computer and use it in GitHub Desktop.
Live deploy of classes using via ssh
#!/bin/bash
# required:
# sudo apt-get install inotify-tools
temp_dir=`mktemp -d`
target_host="...CHANGE..."
target_remote_dir="...CHANGE..."
pid="not_a_pid"
function remote_sync () {
echo -n `date +%H:%M:%S` "Uploading" `find $temp_dir -type f | wc -l` "files to $target_host:$target_remote_dir ... "
tar cjf - -C $temp_dir . | ssh $target_host tar xjf - -C $target_remote_dir &&\
rm -rf $temp_dir &&\
echo "DONE" ||\
echo "Failed!"
}
function spawn_update () {
kill -KILL $pid &> /dev/null
(sleep 7 && remote_sync) &
pid=$!
disown $pid
}
inotifywait -m */target/classes/ -r -e close_write |
while read path action file; do
path_in_jar=`echo -n $path | sed 's!.*target/classes/*!!g'`
echo "Changed $path_in_jar$file"
mkdir -p $temp_dir/$path_in_jar
cp $path$file $temp_dir/$path_in_jar$file
spawn_update
done
@oleksiyp
Copy link
Author

SETUP

  1. Get https://gist.github.com/oleksiyp/66e496343642dc9cafe3
  2. install inotifywatch on Linux
  3. Change target_host=______, target_remote_dir="$HOME/some_path" or whatever
  4. ssh-copy-id $target_host
  5. check if glob "*/target/classes" and SED regex in script matches your needs (this works for maven + IDEA projects) from project dir
  6. put on server to your classapath $target_remote_dir:
  7. press Ctrl+F9 in IDEA
  8. Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment