Skip to content

Instantly share code, notes, and snippets.

@kasunbg
Last active March 9, 2019 15:36
Show Gist options
  • Save kasunbg/444df28a2e51a16bbd74 to your computer and use it in GitHub Desktop.
Save kasunbg/444df28a2e51a16bbd74 to your computer and use it in GitHub Desktop.
wso2 carbon DepSync via rsync
#!/bin/sh
#A snippet to synchronize the CARBON_HOME/repository/deployment/server folders between manager and all worker nodes.
#Add a file called workers-list.txt that has a syntax like follows separated by new lines.
#ubuntu@192.168.1.1:~/setup/192.168.1.1/as/as_worker/repository/deployment/server
manager_server_dir=~/wso2as-5.2.1/repository/deployment/server
pem_file=~/.ssh/carbon-440-test.pem
#delete the lock on exit
trap 'rm -rf /var/lock/depsync-lock' EXIT
mkdir /tmp/carbon-rsync-logs/
#keep a lock to stop parallel runs
if mkdir /var/lock/depsync-lock; then
echo "Locking succeeded" >&2
else
echo "Lock failed - exit" >&2
exit 1
fi
#get the workers-list.txt
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd`
popd > /dev/null
echo $SCRIPTPATH
for x in `cat ${SCRIPTPATH}/workers-list.txt`
do
echo ================================================== >> /tmp/carbon-rsync-logs/logs.txt;
echo Syncing $x;
rsync --delete -arve "ssh -i $pem_file -o StrictHostKeyChecking=no" $manager_server_dir $x >> /tmp/carbon-rsync-logs/logs.txt
echo ================================================== >> /tmp/carbon-rsync-logs/logs.txt;
done
#The cronjob to run the above script every minute.
#You can add this cronjob by running the command `crontab -e`.
#Verify the cron config by running `crontab -l`
* * * * * /home/ubuntu/setup/rsync-for-depsync/rsync-for-depsync.sh
ubuntu@192.168.1.1:~/setup/192.168.1.1/as/as_worker/repository/deployment/server
ubuntu@192.168.1.2:~/setup/192.168.1.2/as/as_worker/repository/deployment/server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment