1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
vslb.inc
|
5
|
Copyright (C) 2005-2008 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 relayd_configure() {
|
37
|
global $config, $g;
|
38
|
|
39
|
$vs_a = &$config['load_balancer']['virtual_server'];
|
40
|
$pool_a = &$config['load_balancer']['lbpool'];
|
41
|
|
42
|
$fd = fopen("{$g['varetc_path']}/relayd.conf", "w");
|
43
|
|
44
|
/* reindex pools by name as we loop through the pools array */
|
45
|
$pools = array();
|
46
|
/* Virtual server pools */
|
47
|
if(is_array($pool_a)) {
|
48
|
for ($i = 0; isset($pool_a[$i]); $i++) {
|
49
|
/* Don't deal with gateway pools - XXX remove me after gateways are converted */
|
50
|
if ($pool_a[$i]['type'] == "gateway")
|
51
|
continue;
|
52
|
|
53
|
if(is_array($pool_a[$i]['servers'])) {
|
54
|
$srvtxt = implode(", ", $pool_a[$i]['servers']);
|
55
|
$conf .= "table <{$pool_a[$i]['name']}> { $srvtxt }\n";
|
56
|
/* Index by name for easier fetching when we loop through the virtual servers */
|
57
|
$pools[$pool_a[$i]['name']] = $pool_a[$i];
|
58
|
}
|
59
|
}
|
60
|
}
|
61
|
|
62
|
if(is_array($vs_a)) {
|
63
|
for ($i = 0; isset($vs_a[$i]); $i++) {
|
64
|
$conf .= "redirect \"{$vs_a[$i]['name']}\" {\n";
|
65
|
$conf .= " listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
|
66
|
$conf .= " forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} check tcp timeout 1000\n";
|
67
|
/* XXX - this needs to use the backup pool aka sitedown - but that isn't converted yet */
|
68
|
if (isset($vs_a[$i]['sitedown']) && $vs_a[$i]['sitedown'] != "")
|
69
|
$conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} check tcp timeout 1000\n";
|
70
|
$conf .= "}\n";
|
71
|
}
|
72
|
}
|
73
|
fwrite($fd, $conf);
|
74
|
fclose($fd);
|
75
|
|
76
|
if (is_process_running('relayd: parent')) {
|
77
|
/*
|
78
|
* XXX: Something breaks our control connection with relayd and makes relayctl stop working
|
79
|
* rule reloads are the current suspect
|
80
|
* mwexec('/usr/local/bin/relayctl stop');
|
81
|
*/
|
82
|
mwexec('pkill relayd');
|
83
|
}
|
84
|
mwexec("/usr/local/sbin/relayd -f {$g['varetc_path']}/relayd.conf");
|
85
|
|
86
|
}
|
87
|
|
88
|
?>
|