Last active
August 29, 2015 14:05
-
-
Save oleksiyp/66e496343642dc9cafe3 to your computer and use it in GitHub Desktop.
Live deploy of classes using via ssh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SETUP