Friday, August 14, 2015

Rsync to synchronize the artifacts - WSO2 products.

We have to configure the artifact synchronization mechanism to  synchronize the artifacts across the cluster nodes . The SVN based synchronization  is the most recommend way to do it .

The following use case is  just my local testing, try it ..!!  if you also interest. :)

In WSO2 products,  artifacts has stored in the /repository/deployment/server directory. In Linux base system,  we can use the Rsync (https://rsync.samba.org/) to synchronize artifacts across  the cluster nodes.

The syncd (https://github.com/drunomics/syncd) is simple bash script which is based on the rsync  and notify-tools utility. That provides very easy way to run the rsync in daemon mode.
apt-get install inotify-tools rsync
1. Go to the download directory and execute the following command to create symbolic link.
sudo ln -s $PWD/syncd /usr/local/bin/syncd
2. Copy the syncd.conf file to manager-1/repository/deployment/ directory.

3. Open that syncd.conf file and configure the following property.
WATCH_DIR=$SYNCD_CONFIG_DIR/server
SSH_USER=ajith
SSH_HOST=127.0.0.1
REMOTE_TARGET_DIR="/home/ajith/cluster/worker-1/repository/deployment/server"
5. Generate key for remote authentication to establish connection without prompting for the  password.

i)  Execute the following command and just enter for all the prompts.
ssh-keygen
ii) cd /home/<username>/.ssh 

iii) Open the id_rsa.pub   file , copy the key and save the file.
 vi id_rsa.pub  
iv) Execute the following command in same directory (.ssh) and past the key. [Ctrl+X then Y to save]
nano authorized_keys 
6. Go back to manager-1/repository/deployment/ and execute the following command to start the daemon task.
syncd start [stop|restart].

7. Now when you are  deploying the artifacts in manager node , that will be synchronize to the worker node.

8. You can extend the syncd script to synchronize the multiple target locations. :)