Project

General

Profile

Download (3.05 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 09894747 Scott Ullrich
	
39 3ad6d3bb Bill Marquette
	$a_vs = &$config['load_balancer']['virtual_server'];
40
	$a_pool = &$config['load_balancer']['pool'];
41
42 09894747 Scott Ullrich
	$should_start=0;
43 3ad6d3bb Bill Marquette
44
	$fd = fopen("{$g['varetc_path']}/slbd.conf", "w");
45
46 fbcda26c Scott Ullrich
	if(is_array($a_vs)) {
47
		foreach ($a_vs as $vsent) {
48
			if ($vsent['desc'] == "")
49
				$slbdconf .= "{$vsent['name']}:\\\n";
50
			else
51
				$slbdconf .= "{$vsent['name']}|{$vsent['desc']}:\\\n";
52
	
53
			/* pool name */
54
			$slbdconf .= "\t:poolname={$vsent['name']}:\\\n";
55
			/* virtual IP */
56
			$slbdconf .= "\t:vip={$vsent['ipaddr']}:\\\n";
57
			/* virtual port */
58
			$slbdconf .= "\t:vip-port={$vsent['port']}:\\\n";
59
			/* fallback IP */
60
			$slbdconf .= "\t:sitedown={$vsent['ipaddr']}:\\\n";
61
			/* fallback port */
62 8df78737 Scott Ullrich
			$slbdconf .= "\t:sitedown-port={$vsent['sitedown']}:\\\n";
63 fbcda26c Scott Ullrich
	
64
			for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
65
				if ($config['load_balancer']['lbpool'][$i]['name'] == $vsent['pool']) {
66
					$svrcnt = 0;
67
					$svrtxt = "";
68
					$svrtxt = "\t:service-port={$config['load_balancer']['lbpool'][$i]['port']}:\\\n";
69
					foreach ($config['load_balancer']['lbpool'][$i]['servers'] as $lbsvr) {
70
						$svrtxt .= "\t:{$svrcnt}={$lbsvr}:\\\n";
71
						$svrcnt++;
72
					}
73
					$slbdconf .= "\t:services={$svrcnt}:\\\n";
74
					$slbdconf .= $svrtxt;
75 3ad6d3bb Bill Marquette
				}
76
			}
77 fbcda26c Scott Ullrich
			
78
			$slbdconf .= "\t:tcppoll:send=:expect=:\n";
79
			
80
			$should_start=1;
81 3ad6d3bb Bill Marquette
		}
82 09894747 Scott Ullrich
	}
83
	
84
	if($should_start == 1) {
85
		fwrite($fd, $slbdconf);
86
		fclose($fd);
87
		mwexec("/usr/bin/pkill -9 slbd");
88
		/* startup slbd pointing it's config at /var/etc/slbd.conf with a polling interval of 5 seconds */
89
		mwexec("/usr/local/sbin/slbd -c{$g['varetc_path']}/slbd.conf -r5000");
90
	} else {
91
		fclose($fd);	
92 3ad6d3bb Bill Marquette
	}
93
}
94
95 09894747 Scott Ullrich
?>