Common subdirectories: ../../freenx/freenx-server/trunk/.svn and freenx/.svn
diff ../../freenx/freenx-server/trunk/node.conf.sample freenx/node.conf.sample
220a221,250
> # Is this FreeNX script act as frontal load balancer ? Yes=1 No=0
> LOAD_BALANCE_FRONTAL=1
> 
> # What is the frontal load balancer IP on your local network (IP
> # use between node(s) and frontal)
> FRONTAL_IP=192.168.0.42
> 
> # Is this computer can act as node (can act as frontal too) ? Yes=1 No=0
> LOAD_BALANCE_NODE=1
> 
> # Where the lock file are.
> LOCK_FILE_DIR=/var/lock/FreeNX/
> LOCK_FILE_FILES=ld_rr_next.lock
> 
> # Which algorithm do you would for load balacing
> # RAND = Random
> # RR   = RoundRobin
> # LOAD = Load
> CHOOSE_LD_ALG="LOAD"
> 
> # Temporary file for some math cal.
> TMP_RR_FILE=$LOCK_FILE_DIR/ld_cal_rr.file
> TMP_LOAD_FILE=$LOCK_FILE_DIR/ld_cal_load.file
> 
> # Which user do you want to use for Load Balancing with Load
> USER_CAL=nxldcal
> 
> # Which script do you want to use for calculate the load on a node.
> SCRIPT_LD_CAL=./nxcal_note_load.sh
> 
Only in freenx/: nxcal_note_load.sh
diff ../../freenx/freenx-server/trunk/nxloadconfig freenx/nxloadconfig
130a131,141
> LOCK_FILE_DIR=$NX_DIR/var/lock/FreeNX
> LOCK_FILE_FILES=ld_rr_next.lock
> TMP_RR_FILE=$LOCK_FILE_DIR/ld_cal_rr.file
> TMP_LOAD_FILE=$LOCK_FILE_DIR/ld_cal_load.file
> USER_CAL=nxldcal
> SCRIPT_LD_CAL=./nxcal_note_load.sh
> 
> CHOOSE_LD_ALG="LOAD"
> LOAD_BALANCE_FRONTAL=0
> FRONTAL_IP=""
> LOAD_BALANCE_NODE=0
diff ../../freenx/freenx-server/trunk/nxnode freenx/nxnode
660,661c660,663
< 	
< 	[ "$ssl_tunnel" = "1" ] && userip="127.0.0.1"
---
>         if [ "$LOAD_BALANCE_NODE" == 0 ]
>         then
>                 [ "$ssl_tunnel" = "1" ] && userip="127.0.0.1"
>         fi
diff ../../freenx/freenx-server/trunk/nxserver freenx/nxserver
845a846,906
> # Real Round_Robin algorithm
> # FIXME: add a lock file when you change the number inside $LOCK_FILE_FILES
> server_loadbalance_rr()
> {
>         log 5 "Looking for node with RoundRobin algorithm"
>         if [ -f $LOCK_FILE_DIR/$LOCK_FILE_FILES ]
>         then
>                 NODE_NB=`cat $LOCK_FILE_DIR/$LOCK_FILE_FILES`
>         else
>                 touch $LOCK_FILE_DIR/$LOCK_FILE_FILES
>                 NODE_NB=1
>         fi
> 
>         SERVER_HOSTS=$SERVER_LOADBALANCING
> 
>         SERVER_NR_OF_HOSTS=`echo $SERVER_HOSTS | wc -w`
> 
>         SERVER_NR=$NODE_NB
>         SERVER_HOST_RR=`echo $SERVER_HOSTS | cut -d' ' -f$SERVER_NR`
> 
>         echo $SERVER_HOST_RR
>         echo "$SERVER_NR + 1" >> $TMP_RR_FILE
>         echo "quit" >> $TMP_RR_FILE
>         SERVER_NR=`bc -q $TMP_RR_FILE`
>         rm -f $TMP_RR_FILE
> 
>         echo "if ( $SERVER_NR > $SERVER_NR_OF_HOSTS ) 1" >> $TMP_RR_FILE
>         echo "quit" >> $TMP_RR_FILE
>         SERVER_NR_TMP=`bc -q $TMP_RR_FILE`
>         if ! [ "$SERVER_NR_TMP" == "" ]; then SERVER_NR=$SERVER_NR_TMP; fi
>         rm -f $TMP_RR_FILE
> 
>         echo $SERVER_NR > $LOCK_FILE_DIR/$LOCK_FILE_FILES
> }
> 
> # LoadBalancing for the load.
> server_loadbalance_charge()
> {
>         log 5 "Looking for node with Load algorithm"
> 
>         SERVER_HOSTS=$SERVER_LOADBALANCING
>         LD_HIGH_NOTE=0
> 
>         for ipnode in $SERVER_HOSTS
>         do
>                 TMP_NOTE=`ssh $USER_CAL@$ipnode $SCRIPT_LD_CAL`
>                 echo "if ( $TMP_NOTE >= $LD_HIGH_NOTE ) $TMP_NOTE" >> $TMP_LOAD_FILE
>                 echo "quit" >> $TMP_LOAD_FILE
>                 LD_HIGH_NOTE_TMP=`bc -q $TMP_LOAD_FILE`
> 
>                 if ! [ "$LD_HIGH_NOTE_TMP" == "" ]
>                 then
>                         SERVER_NR=$ipnode
>                         LD_HIGH_NOTE=$LD_HIGH_NOTE_TMP
>                 fi
> 
>         done
> 
>         echo $SERVER_NR
> }
> 
857,859c918,930
< 		# Fallback if still empty
< 		[ -z "$SERVER_HOST" ] && SERVER_HOST=$(server_loadbalance_random_rr)
< 		[ -n "$SERVER_HOST" ] && log 5 "Info: Load-Balancing (if possible) to $SERVER_HOST ..."
---
> 
>                 case "$CHOOSE_LD_ALG" in
>                  "RAND" )
>                    [ -z "$SERVER_HOST" ] && SERVER_HOST=$(server_loadbalance_random_rr)
>                  ;;
>                  "RR" )
>                    [ -z "$SERVER_HOST" ] && SERVER_HOST=$(server_loadbalance_rr)
>                  ;;
>                  "LOAD" )
>                    [ -z "$SERVER_HOST" ] && SERVER_HOST=$(server_loadbalance_charge)
>                  ;;
> 		esac
> 		[ -n "$SERVER_HOST" ] && log 5 "Info: Load-Balancing (if possible) with algorithm $CHOOSE_LD_ALG to $SERVER_HOST ..."
911c982,987
< 	USERIP=$(echo $SSH_CLIENT $SSH2_CLIENT | cut -d" " -f1 | sed 's/::ffff://g')
---
>         if [ "$LOAD_BALANCE_FRONTAL" == 1 ]
>         then
>                 USERIP=$FRONTAL_IP
>         else
>                 USERIP=$(echo $SSH_CLIENT $SSH2_CLIENT | cut -d" " -f1 | sed 's/::ffff://g')
>         fi
