Project

General

Profile

Download (3.08 KB) Statistics
| Branch: | Tag: | Revision:
1 3ad6d3bb Bill Marquette
<?php
2 577c9191 Bill Marquette
/* $Id$ */
3 3ad6d3bb Bill Marquette
/*
4
	vslb.inc
5
        Copyright (C) 2005 Bill Marquette
6
	All rights reserved.
7
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
29
*/
30
31
/* include all configuration functions */
32
require_once("functions.inc");
33
require_once("pkg-utils.inc");
34
require_once("notices.inc");
35
36
function slbd_configure() {
37
	global $config, $g;
38
39 bdefcbca Bill Marquette
	/* no need to go further if we don't have any load balance stuff */
40 9c418998 Bill Marquette
	if ((!is_array($config['load_balancer'])) || (!is_array($config['load_balancer']['pool'])))
41 bdefcbca Bill Marquette
		return;
42
43 3ad6d3bb Bill Marquette
	$a_vs = &$config['load_balancer']['virtual_server'];
44
	$a_pool = &$config['load_balancer']['pool'];
45
46
47
	$fd = fopen("{$g['varetc_path']}/slbd.conf", "w");
48
49
	foreach ($a_vs as $vsent) {
50
		if ($vsent['desc'] == "")
51
			$slbdconf .= "{$vsent['name']}:\\\n";
52
		else
53
			$slbdconf .= "{$vsent['name']}|{$vsent['desc']}:\\\n";
54
55 6049ece7 Bill Marquette
		/* pool name */
56
        	$slbdconf .= "\t:poolname={$vsent['name']}:\\\n";
57 3ad6d3bb Bill Marquette
		/* virtual IP */
58
	 	$slbdconf .= "\t:vip={$vsent['ipaddr']}:\\\n";
59
		/* virtual port */
60
	 	$slbdconf .= "\t:vip-port={$vsent['port']}:\\\n";
61
		/* fallback IP */
62
	 	$slbdconf .= "\t:sitedown={$vsent['ipaddr']}:\\\n";
63
		/* fallback port */
64
	 	$slbdconf .= "\t:sitedown-port={$vsent['port']}:\\\n";
65
66
		for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
67
			if ($config['load_balancer']['lbpool'][$i]['name'] == $vsent['pool']) {
68
				$svrcnt = 0;
69
				$svrtxt = "";
70
				$svrtxt = "\t:service-port={$config['load_balancer']['lbpool'][$i]['port']}:\\\n";
71
				foreach ($config['load_balancer']['lbpool'][$i]['servers'] as $lbsvr) {
72
					$svrtxt .= "\t:{$svrcnt}={$lbsvr}:\\\n";
73
					$svrcnt++;
74
				}
75
				$slbdconf .= "\t:services={$svrcnt}:\\\n";
76
				$slbdconf .= $svrtxt;
77
			}
78
		}
79
		
80
        	$slbdconf .= "\t:tcppoll:send=:expect=:\n";
81
	}
82
	fwrite($fd, $slbdconf);
83
	fclose($fd);
84
	mwexec("/usr/bin/pkill -9 slbd");
85 9f98a38a Bill Marquette
	/* startup slbd pointing it's config at /var/etc/slbd.conf with a polling interval of 5 seconds */
86
	mwexec("/usr/local/sbin/slbd -c{$g['varetc_path']}/slbd.conf -r5000");
87 3ad6d3bb Bill Marquette
}
88
89
?>