Subversion Repositories ALCASAR

Rev

Rev 1068 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1068 Rev 1078
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-load_balancing.sh 1068 2013-04-10 05:20:10Z franck $
2
# $Id: alcasar-load_balancing.sh 1078 2013-05-02 16:40:54Z franck $
3
 
3
 
4
# Generic Load balancer for multiple WAN links - version 1.1 (04 Feb 2011)
4
# Generic Load balancer for multiple WAN links - version 1.1 (04 Feb 2011)
5
# (c) 2011 Pau Oliva Fora - http://pof.eslack.org
5
# (c) 2011 Pau Oliva Fora - http://pof.eslack.org
6
#
6
#
7
# Licensed under GPLv3 - for full terms see:
7
# Licensed under GPLv3 - for full terms see:
Line 12... Line 12...
12
#
12
#
13
# Specify each WAN link in a separate column, example:
13
# Specify each WAN link in a separate column, example:
14
# In this example we have 3 wan links (vlanXXX interfaces) attached to a single
14
# In this example we have 3 wan links (vlanXXX interfaces) attached to a single
15
# physical interface because we use a vlan-enabled switch between the balancer
15
# physical interface because we use a vlan-enabled switch between the balancer
16
# machine and the ADSL routers we want to balance. The weight parameter should
16
# machine and the ADSL routers we want to balance. The weight parameter should
17
# be kept to a low integer, in this case the ADSL line connected to vlan101 and
17
# be kept to a low integer.
18
# vlan102 is 4Mbps and the ADSL line connected to vlan100 is 8Mbps (twice fast)
-
 
19
# so the WEIGHT value in vlan100 is 2 because it is two times faster.
-
 
20
#
18
#
21
#
19
#
22
# Modified by ALCASAR team :
20
# Modified by ALCASAR team :
23
 
21
 
24
 
22
 
-
 
23
prog="alcasar-load_balancing.sh"
-
 
24
pidfile="/var/run/alcasar-load_balancing.pid"
-
 
25
 
25
###############################
26
###############################
26
# MAIN PARAMETERs Configuration
27
# MAIN PARAMETERs Configuration
27
###############################
28
###############################
-
 
29
 
-
 
30
DIR_ETC="/usr/local/etc"
-
 
31
CONF_FILE="$DIR_ETC/alcasar.conf"
28
# enable link failover watchdog? set to "yes" or "no".
32
MULTIWAN=`grep MULTIWAN= $CONF_FILE|cut -d"=" -f2`
29
WATCHDOG="yes"
33
MULTIWAN=${MULTIWAN:=off}
-
 
34
FAILOVER=`grep FAILOVER= $CONF_FILE|cut -d"=" -f2`
30
SLEEP="30"
35
FAILOVER=${FAILOVER:=30}
-
 
36
 
31
 
37
 
32
# space separated list of public IPs to ping in watchdog mode
38
# space separated list of public IPs to ping in watchdog mode
33
# set this to some public ip addresses pingable and always on.
39
# set this to some public ip addresses pingable and always on.
34
TESTIPS="8.8.8.8 192.0.32.10"
40
TESTIPS="8.8.8.8 192.0.32.10"
35
 
41
 
36
# set to 1 when testing, set to 0 when happy with the results
42
# set to 1 when testing, set to 0 when happy with the results
37
VERBOSE=1
43
VERBOSE=0
38
 
44
 
39
# CONFIGURATION ENDS HERE
45
# CONFIGURATION ENDS HERE
40
###############################
46
###############################
41
 
47
 
42
 
48
 
43
 
-
 
44
if [ $(whoami) != "root" ]; then
49
if [ $(whoami) != "root" ]; then
45
        echo "You must be root to run this!" ; echo ; exit 1
50
        echo "You must be root to run this!" ; echo ; exit 1
46
fi
51
fi
47
 
52
 
48
# Adapter for ALCASAR project
53
# Adapter for ALCASAR project
Line 191... Line 196...
191
	while : ; do
196
	while : ; do
192
	
197
	
193
		if [ $VERBOSE -eq 1 ]; then
198
		if [ $VERBOSE -eq 1 ]; then
194
			echo "[] Sleeping, state=$STATE"
199
			echo "[] Sleeping, state=$STATE"
195
		fi
200
		fi
196
		sleep $SLEEP
201
		sleep $FAILOVER
197
	
202
	
198
		IFINDEX=1
203
		IFINDEX=1
199
		DOWN=""			# liste des interfaces down
204
		DOWN=""			# liste des interfaces down
200
		DOWNCOUNT=0		# nombre d'interface down
205
		DOWNCOUNT=0		# nombre d'interface down
201
		for iface in $WANIFACE ; do
206
		for iface in $WANIFACE ; do
Line 334... Line 339...
334
		create_eth  		
339
		create_eth  		
335
	;;
340
	;;
336
	delete) 
341
	delete) 
337
		delete_eth  		
342
		delete_eth  		
338
	;;
343
	;;
339
	fail) 
-
 
340
		failover 		
-
 
341
	;;
-
 
342
	start) 
344
	start) 
343
		PARAM="add"
-
 
344
		create_eth  		
345
                if [ "$MULTIWAN" != "on" ] && [ "$MULTIWAN" != "On" ]; then 
345
		if [ $WATCHDOG != "yes" ]; then
346
		    echo "The MultiGateway is not activated !"
346
			exit 0
347
		    exit 0
347
		fi
348
		fi
-
 
349
                PARAM="add"
-
 
350
                create_eth
348
		ip route flush cache
351
                ip route flush cache
-
 
352
                if [ $FAILOVER -eq 0 ]; then 
-
 
353
		      echo "The MultiWAN Mode is actived but not failover connectivity !"
349
#		RETVAL=$?
354
		      exit 0
350
#		echo
355
		fi
-
 
356
                echo "Starting down $prog: "
351
#		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/alcasar-load_balancing
357
                pid=`pidof -x "alcasar-load_balancing.sh"`
-
 
358
                if [ $pid != "" ]; then
-
 
359
                        echo $pid > $pidfile
-
 
360
                fi
352
		touch /var/lock/subsys/alcasar-load_balancing
361
                touch /var/lock/subsys/alcasar-load_balancing
353
		failover
362
                failover
354
	;;
363
	;;
355
	stop) 
364
	stop) 
356
		PARAM="del"
365
		PARAM="del"
357
		prog="alcasar-load_balancing.sh"
366
		echo "Shutting down $prog: "
-
 
367
                if [ -f $pidfile ]; then
358
	        gprintf $"Shutting down $prog: "
368
                        pid=`cat $pidfile`
-
 
369
                        kill -9 $pid
-
 
370
                else
-
 
371
                        echo "$prog is not running."
-
 
372
                        exit 1
359
		killproc $prog
373
                fi
360
		RETVAL=$?
374
                RETVAL=$?
361
	        echo
375
                echo
362
	        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/alcasar-load_balancing
376
                [ $RETVAL -eq 0 ] && rm -f $pidfile && rm -f /var/lock/subsys/alcasar-load_balancing
-
 
377
                echo "Delete of virtual interfaces"
-
 
378
                delete_eth
-
 
379
                echo "Network restart"
-
 
380
                service network restart 2>&1 > /dev/null
-
 
381
                ip route
-
 
382
       
-
 
383
	;;
-
 
384
	status)
-
 
385
                echo "Checking  $prog : "
-
 
386
                if [ -f $pidfile ]; then
-
 
387
                        pid=`cat $pidfile`
-
 
388
                        CHECK=`ps -p $pid --no-heading | awk {'printf $1'}`
-
 
389
                        if [ "$CHECK" = "" ]; then
-
 
390
                                echo "$prog is NOT running."
-
 
391
                        else
-
 
392
                                echo "$prog is running !"
-
 
393
                        fi
-
 
394
                else
-
 
395
                                echo "$prog is Not running."
363
		return $RETVAL
396
                fi	
-
 
397
	;;
-
 
398
	fail) 
364
		ip route
399
		failover 		
365
	;;
400
	;;
366
	*) 
401
	*) 
367
		echo "Usage: $0 [start|stop|create|delete]" ; echo ; exit 1
402
		echo "Usage: $0 [start|stop|status|create|delete]" ; echo ; exit 1
368
	;;
403
	;;
369
esac
404
esac
370
 
405
 
371
exit 0
406
exit 0