Archive for March, 2009

Enable or fix logging for HAProxy load balancer

After configuration of HAProxy to balance web traffic, I’ve noticed that HAProxy is not generating any logs in my server. Due to its load balancer role, logging is vital to diagnose any issue that might come in future.

In its default config, HAProxy send logs to a syslog facility: local0, via a socket connection. By default, your syslog configuration probably doesn’t accept socket connections, and even doesn’t have a local0 facility, so you have no HAProxy log. If you want it, configure syslog to accept TCP connections by adding -r to syslogd parameters.

Script to sync files between web severs having plesk

I got a little assignment where there are two webservers are there behind a load balancer and both needs to have identical files. Both server has plesk control panel. As we know, plesk store website files in /var/www/vhosts/domain/httpdocs directory, here domain is the name of website. Though this script can be used in any other case, just you may need to update it little bit.

I wrote a wrapper script for rsync and deployed there. Here is the script:

#!/bin/bash
 
############### websync.sh by Jagbir Singh #################
#
# This script acts as wrapper for rsync. It checks every domain listed in /var/www/vshots
# for existence in other server, if found there, then sync domain's 'httpdocs' only directory.
#
# ver 1.0 Mar 8, 2009: Initial version.
#
#############################################################
 
cd /var/www/vhosts
webserver2="192.168.30.2"
 
## get directory list
ls --file-type | grep "\/" | sed 's/\///' | grep -Ev "^chroot|^default" > /tmp/dir.list
exec 10</tmp/dir.list
let count=0
 
## check domains in other server and update them.
while read LINE <&10; do
    ## update second webserver if domain exist there (just in case)
    if  `ssh $webserver2 "ls /var/www/vhosts/$LINE/httpdocs/ > /dev/null 2>&1"` ; then
        `rsync -az --delete -e ssh /var/www/vhosts/$LINE/httpdocs/ $webserver2:/var/www/vhosts/$LINE/httpdocs/`
    fi
 
    ((count++))
done
exec 10>&-
Get Adobe Flash playerPlugin by wpburn.com wordpress themes