Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

File synchronization with rsync

File synchronization with rsync

This section explains how to set up rsync, a file synchronization program. rsync can synchronize asset files between a Commerce Manager and storefront located on different servers. If the Commerce Manager and storefront are located on the same server, or if they are on a shared drive (with an identical mount point or drive name), rsync is not required.

We recommend configuring a central location for storefront template and template resource files, or choosing a master storefront node from the cluster. Synchronizing these files with rsync will allow storefront changes to be instantly replicated in other cluster nodes.

  1. Download and install rsync from http://samba.anu.edu.au/rsync/download.html. If the source code is downloaded, enter the following commands to build it:
    {RSYNC_SRC_DIR}/configure
    {RSYNC_SRC_DIR}/make
    {RSYNC_SRC_DIR}/make install
    
  2. Set up the rsync daemon on the Commerce Manager server. Replace SF1_SERVER_IP and SF2_SERVER_IP with the IP addresses of the servers that will be the nodes in the cluster, EP_ASSETS_PATH with the path to the asset directory, and EP_TEMPLATES_PATH with the path where templates will be stored.
    motd file = /etc/rsyncd.motd
    log file = /var/log/rsyncd.log
    pid file = /var/run/rsyncd.pid
    lock file = /var/run/rsync.lock
    hosts allow = SF1_SERVER_IP, SF2_SERVER_IP
    exclude = .svn .svn/* *.bak
    
    [PD:assets]
       path = EP_ASSETS_PATH
       comment = assets
    
    [PD:templates]
       path = EP_TEMPLATES_PATH
       comment = view templates
    
  3. Create a new file named \etc\rsyncd.motd with the following:
    Welcome to rsyncd server.
    
  4. Start the rsync daemon with the following:
    rsync --verbose  --progress --stats --compress --rsh=/usr/local/bin/ssh \
          --recursive --times --perms --links --delete \
          -daemon
    

Setting up the rsync client on the storefront servers

  1. Create a new file named \sbin\rsync_ep. Replace CM_SERVER_IP with the IP address of the server hosting the Commerce Manager, EP_ASSETS_PATH with the path to the asset directory, and EP_INSTALL_PATH with the path to the root of the Elastic Path code base.
    #!/bin/bash
    
    rsync --verbose  --progress --stats --compress --recursive --times --perms
      --links --delete
      CM_SERVER_IP::assets/*  EP_ASSETS_PATH
    
    rsync --verbose  --progress --stats --compress --recursive --times --perms
      --links --delete
      CM_SERVER_IP::templates/*  EP_INSTALL_PATH/com.elasticpath.sf/WEB-INF/templates
    
  2. Change the file permissions of \sbin\rync_ep to allow anyone read access.
    chmod 744 /sbin/rsync_ep
    
  3. Create a new cron job \etc\cron.d\rsync with the following:
    # run rysnc every 10 minutes
    */10 * * * * root /sbin/rsync_ep
    
    Note:

    If a large number of files need to be replicated, it may take some time to transfer them to each storefront. If you are planning on importing many products into a live production catalog, you should first upload the media files to the Commerce Manager and let the replication finish before running the import.

For more information on rsync, see http://everythinglinux.org/rsync/.