aboutsummaryrefslogtreecommitdiffstats
path: root/config/haproxy-dev
diff options
context:
space:
mode:
authorserg dvoriancev <dv_serg@mail.ru>2010-04-12 21:52:00 +0400
committerserg dvoriancev <dv_serg@mail.ru>2010-04-12 21:52:00 +0400
commit312f6a4827d742869daba0ebb186b6de5483379a (patch)
tree9285758224d8a53d519f7fab142629397e1ef13d /config/haproxy-dev
parent8d8c3e1278c35aaf235710d07cbe6583337700d5 (diff)
parente8fa9505ad3c402bf4a5b5143842c0028382a658 (diff)
downloadpfsense-packages-312f6a4827d742869daba0ebb186b6de5483379a.tar.gz
pfsense-packages-312f6a4827d742869daba0ebb186b6de5483379a.tar.bz2
pfsense-packages-312f6a4827d742869daba0ebb186b6de5483379a.zip
Merge branch 'master' of http://gitweb.pfsense.org/pfsense-packages/mainline
Diffstat (limited to 'config/haproxy-dev')
-rw-r--r--config/haproxy-dev/haproxy.inc535
-rwxr-xr-xconfig/haproxy-dev/haproxy_global.php33
-rwxr-xr-xconfig/haproxy-dev/haproxy_pool_edit.php11
-rwxr-xr-xconfig/haproxy-dev/haproxy_pools.php33
4 files changed, 424 insertions, 188 deletions
diff --git a/config/haproxy-dev/haproxy.inc b/config/haproxy-dev/haproxy.inc
index a799cd48..f14d479c 100644
--- a/config/haproxy-dev/haproxy.inc
+++ b/config/haproxy-dev/haproxy.inc
@@ -58,48 +58,14 @@ $a_acltypes[] = array('name' => 'path_contains', 'descr' => 'Path contains',
$a_acltypes[] = array('name' => 'source_ip', 'descr' => 'Source IP',
'mode' => '', 'syntax' => 'src');
-function haproxy_find_acl($name) {
- global $a_acltypes;
-
- /* XXX why is this broken from xmlsync? */
- if (!$a_acltypes) {
- $a_acltypes = array();
- $a_acltypes[] = array('name' => 'host_starts_with', 'descr' => 'Host starts with',
- 'mode' => 'http', 'syntax' => 'hdr_beg(host) -i');
- $a_acltypes[] = array('name' => 'host_ends_with', 'descr' => 'Host ends with',
- 'mode' =>'http', 'syntax' => 'hdr_end(host) -i');
- $a_acltypes[] = array('name' => 'host_matches', 'descr' => 'Host matches',
- 'mode' =>'http', 'syntax' => 'hdr(host) -i');
- $a_acltypes[] = array('name' => 'host_regex', 'descr' => 'Host regex',
- 'mode' =>'http', 'syntax' => 'hdr_reg(host) -i');
- $a_acltypes[] = array('name' => 'host_contains', 'descr' => 'Host contains',
- 'mode' => 'http', 'syntax' => 'hdr_dir(host) -i');
- $a_acltypes[] = array('name' => 'path_starts_with', 'descr' => 'Path starts with',
- 'mode' => 'http', 'syntax' => 'path_beg -i');
- $a_acltypes[] = array('name' => 'path_ends_with', 'descr' => 'Path ends with',
- 'mode' => 'http', 'syntax' => 'path_end -i');
- $a_acltypes[] = array('name' => 'path_matches', 'descr' => 'Path matches',
- 'mode' => 'http', 'syntax' => 'path -i');
- $a_acltypes[] = array('name' => 'path_regex', 'descr' => 'Path regex',
- 'mode' => 'http', 'syntax' => 'path_reg -i');
- $a_acltypes[] = array('name' => 'path_contains', 'descr' => 'Path contains',
- 'mode' => 'http', 'syntax' => 'path_dir -i');
- $a_acltypes[] = array('name' => 'source_ip', 'descr' => 'Source IP',
- 'mode' => '', 'syntax' => 'src');
- }
-
- if($a_acltypes) {
- foreach ($a_acltypes as $acl) {
- if ($acl['name'] == $name)
- return $acl;
- }
- }
-}
-
function haproxy_custom_php_deinstall_command() {
exec("rm /usr/local/sbin/haproxy");
exec("rm /usr/local/pkg/haproxy.inc");
exec("rm /usr/local/www/haproxy*");
+ exec("rm /usr/local/etc/rc.d/haproxy.sh");
+ exec("rm /etc/devd/haproxy.conf");
+ exec("/etc/rc.d/devd restart");
+ haproxy_install_cron(false);
}
function haproxy_custom_php_install_command() {
@@ -122,6 +88,8 @@ haproxy_enable=\${haproxy-"YES"}
start_cmd="haproxy_start"
stop_postcmd="haproxy_stop"
+check_cmd="haproxy_check"
+extra_commands="check"
load_rc_config \$name
@@ -139,6 +107,20 @@ haproxy_start () {
ENDOFF
}
+haproxy_check () {
+ echo "Checking haproxy."
+ /usr/bin/env \
+ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
+ /usr/local/bin/php -q -d auto_prepend_file=config.inc <<ENDOFF
+ <?php
+ require_once("globals.inc");
+ require_once("functions.inc");
+ require_once("haproxy.inc");
+ haproxy_check_run(0);
+ ?>
+ENDOFF
+}
+
haproxy_stop () {
echo "Stopping haproxy."
killall haproxy
@@ -153,12 +135,211 @@ EOD;
fclose($fd);
exec("chmod a+rx /usr/local/etc/rc.d/haproxy.sh");
+ $devd = <<<EOD
+notify 0 {
+ match "system" "IFNET";
+ match "subsystem" "carp[0-9]+";
+ match "type" "LINK_UP";
+ action "/usr/local/etc/rc.d/haproxy.sh check";
+};
+notify 0 {
+ match "system" "IFNET";
+ match "subsystem" "carp[0-9]+";
+ match "type" "LINK_DOWN";
+ action "/usr/local/etc/rc.d/haproxy.sh check";
+};
+
+EOD;
+ exec("mkdir -p /etc/devd");
+ $fd = fopen("/etc/devd/haproxy.conf", "w");
+ fwrite($fd, $devd);
+ fclose($fd);
+ exec("/etc/rc.d/devd restart");
+
conf_mount_ro();
exec("/usr/local/etc/rc.d/haproxy.sh start");
}
+function haproxy_install_cron($should_install) {
+ global $config, $g;
+ if($g['booting']==true)
+ return;
+ $is_installed = false;
+ if(!$config['cron']['item'])
+ return;
+ $x=0;
+ foreach($config['cron']['item'] as $item) {
+ if(strstr($item['command'], "/usr/local/etc/rc.d/haproxy.sh")) {
+ $is_installed = true;
+ break;
+ }
+ $x++;
+ }
+ switch($should_install) {
+ case true:
+ if(!$is_installed) {
+ $cron_item = array();
+ $cron_item['minute'] = "*/2";
+ $cron_item['hour'] = "*";
+ $cron_item['mday'] = "*";
+ $cron_item['month'] = "*";
+ $cron_item['wday'] = "*";
+ $cron_item['who'] = "root";
+ $cron_item['command'] = "/usr/local/etc/rc.d/haproxy.sh check";
+ $config['cron']['item'][] = $cron_item;
+ parse_config(true);
+ write_config();
+ configure_cron();
+ }
+ break;
+ case false:
+ if($is_installed == true) {
+ if($x > 0) {
+ unset($config['cron']['item'][$x]);
+ parse_config(true);
+ write_config();
+ }
+ configure_cron();
+ }
+ break;
+ }
+}
+
+function haproxy_find_acl($name) {
+ global $a_acltypes;
+
+ /* XXX why is this broken from xmlsync? */
+ if (!$a_acltypes) {
+ $a_acltypes = array();
+ $a_acltypes[] = array('name' => 'host_starts_with', 'descr' => 'Host starts with',
+ 'mode' => 'http', 'syntax' => 'hdr_beg(host) -i');
+ $a_acltypes[] = array('name' => 'host_ends_with', 'descr' => 'Host ends with',
+ 'mode' =>'http', 'syntax' => 'hdr_end(host) -i');
+ $a_acltypes[] = array('name' => 'host_matches', 'descr' => 'Host matches',
+ 'mode' =>'http', 'syntax' => 'hdr(host) -i');
+ $a_acltypes[] = array('name' => 'host_regex', 'descr' => 'Host regex',
+ 'mode' =>'http', 'syntax' => 'hdr_reg(host) -i');
+ $a_acltypes[] = array('name' => 'host_contains', 'descr' => 'Host contains',
+ 'mode' => 'http', 'syntax' => 'hdr_dir(host) -i');
+ $a_acltypes[] = array('name' => 'path_starts_with', 'descr' => 'Path starts with',
+ 'mode' => 'http', 'syntax' => 'path_beg -i');
+ $a_acltypes[] = array('name' => 'path_ends_with', 'descr' => 'Path ends with',
+ 'mode' => 'http', 'syntax' => 'path_end -i');
+ $a_acltypes[] = array('name' => 'path_matches', 'descr' => 'Path matches',
+ 'mode' => 'http', 'syntax' => 'path -i');
+ $a_acltypes[] = array('name' => 'path_regex', 'descr' => 'Path regex',
+ 'mode' => 'http', 'syntax' => 'path_reg -i');
+ $a_acltypes[] = array('name' => 'path_contains', 'descr' => 'Path contains',
+ 'mode' => 'http', 'syntax' => 'path_dir -i');
+ $a_acltypes[] = array('name' => 'source_ip', 'descr' => 'Source IP',
+ 'mode' => '', 'syntax' => 'src');
+ }
+
+ if($a_acltypes) {
+ foreach ($a_acltypes as $acl) {
+ if ($acl['name'] == $name)
+ return $acl;
+ }
+ }
+}
+
+function write_backend($fd, $name, $pool, $frontend) {
+ if(!is_array($pool['ha_servers']['item']))
+ continue;
+
+ fwrite ($fd, "backend " . $name . "\n");
+ if($pool['cookie_name'] && strtolower($frontend['type']) == "http")
+ fwrite ($fd, "\tcookie\t\t\t" . $pool['cookie_name'] . " insert indirect\n");
+
+ // https is an alias for tcp for clarity purpouses
+ if(strtolower($frontend['type']) == "https") {
+ $backend_type = "tcp";
+ $httpchk = "ssl-hello-chk";
+ } else {
+ $backend_type = $frontend['type'];
+ $httpchk = "httpchk";
+ }
+
+ fwrite ($fd, "\tmode\t\t\t" . $backend_type . "\n");
+
+ if($frontend['balance'])
+ fwrite ($fd, "\tbalance\t\t\t" . $frontend['balance'] . "\n");
+
+ if($frontend['connection_timeout'])
+ fwrite ($fd, "\tcontimeout\t\t" . $frontend['connection_timeout'] . "\n");
+
+ if($frontend['server_timeout'])
+ fwrite ($fd, "\tsrvtimeout\t\t" . $frontend['server_timeout'] . "\n");
+
+ if($frontend['retries'])
+ fwrite ($fd, "\tretries\t\t\t" . $frontend['retries'] . "\n");
+
+ if($frontend['stats_enabled']=='yes') {
+ fwrite ($fd, "\tstats\t\t\tenable\n");
+ if($frontend['stats_uri'])
+ fwrite ($fd, "\tstats\t\t\turi ".$frontend['stats_uri']."\n");
+ if($frontend['stats_realm'])
+ fwrite ($fd, "\tstats\t\t\trealm " . $frontend['stats_realm'] . "\n");
+ else
+ fwrite ($fd, "\tstats\t\t\trealm .\n");
+ fwrite ($fd, "\tstats\t\t\tauth " . $frontend['stats_username'].":". $frontend['stats_password']."\n");
+ }
+
+ $uri = $pool['monitor_uri'];
+ if ($pool['monitor_uri'])
+ $uri = $pool['monitor_uri'];
+ else
+ $uri = "/";
+ fwrite ($fd, "\toption\t\t\t{$httpchk} HEAD " . $uri . " HTTP/1.0\n");
+
+ if($pool['cookie'] && strtolower($frontend['type']) == "http")
+ $cookie = " cookie {$pool['cookie']} ";
+ else
+ $cookie = "";
+ if($pool['advanced']) {
+ $advanced = base64_decode($pool['advanced']);
+ $advanced_txt = " " . $advanced;
+ } else {
+ $advanced_txt = "";
+ }
+ if($pool['checkinter'])
+ $checkinter = "check inter {$pool['checkinter']}";
+ else if (strtolower($frontend['type']) != "tcp")
+ $checkinter = "check inter 1000";
+ else
+ $checkinter = "";
+
+ $a_servers = &$pool['ha_servers']['item'];
+ foreach($a_servers as $be) {
+ if(!$be['port']) {
+ // the listener can specify a default port
+ $be['port'] = $frontend['svrport'];
+ }
+ if(!$be['port']) {
+ // last resort, use the frontend port
+ $ports = split(",", "{$frontend['port']},");
+ $be['port'] = $ports[0];
+ }
+ if (!$be['name'])
+ $be['name'] = $be['address'];
+ if($be['backup']) {
+ $isbackup = "backup";
+ } else {
+ $isbackup = "";
+ }
+ fwrite ($fd, "\tserver\t\t\t" . $be['name'] . " " . $be['address'].":" . $be['port'] . " $cookie " . " $checkinter $isbackup weight " . $be['weight'] . "{$advanced_txt}\n");
+ }
+ fwrite ($fd, "\n");
+}
+
function haproxy_configure() {
+ // reload haproxy
+ haproxy_writeconf();
+ return haproxy_check_run(1);
+}
+
+function haproxy_writeconf() {
global $config, $g;
$a_global = &$config['installedpackages']['haproxy'];
@@ -170,7 +351,7 @@ function haproxy_configure() {
if(is_array($a_global)) {
fwrite ($fd, "global\n");
if($a_global['advanced'])
- fwrite ($fd, "\t" . base64deode($a_global['advanced']) . "\n");
+ fwrite ($fd, "\t" . base64_decode($a_global['advanced']) . "\n");
fwrite ($fd, "\tmaxconn\t\t\t".$a_global['maxconn']."\n");
if($a_global['remotesyslog'])
fwrite ($fd, "\tlog\t\t\t{$a_global['remotesyslog']}\t{$a_global['logfacility']}\t{$a_global['loglevel']}\n");
@@ -187,17 +368,51 @@ function haproxy_configure() {
fwrite ($fd, "\n");
}
- // Construct and write out configuration file
+ // Try and get a unique array for address:port as frontends can duplicate
+ $a_bind = array();
if(is_array($a_backends)) {
foreach ($a_backends as $backend) {
-
if($backend['status'] != 'active')
continue;
- // Define our backend name
- $backendinfo = "listen {$backend['name']}\n";
+ if(!$backend['pool'])
+ continue;
+
+ $bname = $backend['extaddr'] . ":" . $backend['port'];
+ if (!is_array($a_bind[$bname])) {
+ $a_bind[$bname] = array();
+ $a_bind[$bname]['config'] = array();
+ // Settings which are constant for a merged frontend
+ $a_bind[$bname]['name'] = $backend['name'];
+ $a_bind[$bname]['extaddr'] = $backend['extaddr'];
+ $a_bind[$bname]['port'] = $backend['port'];
+ }
+ $b = &$a_bind[$bname];
+
+ // Overwrite ?
+ $b['type'] = $backend['type'];
+ $b['forwardfor'] = $backend['forwardfor'];
+ $b['httpclose'] = $backend['httpclose'];
+ $b['max_connections'] = $backend['max_connections'];
+ $b['client_timeout'] = $backend['client_timeout'];
+ $b['advanced'] = $backend['advanced'];
+
+ // pointer to each backend
+ $b['config'][] = $backend;
+ }
+ }
+
+ $a_pendingpl = array();
+
+ // Construct and write out configuration file
+ if(is_array($a_bind)) {
+ foreach ($a_bind as $bind) {
+ if (count($bind['config']) > 1)
+ $frontendinfo = "frontend {$bind['name']}-merged\n";
+ else
+ $frontendinfo = "frontend {$bind['name']}\n";
// Prepare ports for processing by splitting
- $portss = "{$backend['port']},";
+ $portss = "{$bind['port']},";
$ports = split(",", $portss);
// Initialize variable
@@ -206,30 +421,30 @@ function haproxy_configure() {
// Process and add bind directives for ports
foreach($ports as $port) {
if($port) {
- if($backend['extaddr'] == "any")
+ if($bind['extaddr'] == "any")
$listenip .= "\tbind\t\t\t0.0.0.0:{$port}\n";
- elseif($backend['extaddr'])
- $listenip .= "\tbind\t\t\t{$backend['extaddr']}:{$port}\n";
+ elseif($bind['extaddr'])
+ $listenip .= "\tbind\t\t\t{$bind['extaddr']}:{$port}\n";
else
$listenip .= "\tbind\t\t\t" . get_current_wan_address('wan') . ":{$port}\n";
}
}
- fwrite ($fd, "{$backendinfo}");
+ fwrite ($fd, "{$frontendinfo}");
fwrite ($fd, "{$listenip}");
// Advanced pass thru
- if($backend['advanced']) {
- $advanced = base64_decode($backend['advanced']);
+ if($bind['advanced']) {
+ $advanced = base64_decode($bind['advanced']);
fwrite($fd, "\t" . $advanced . "\n");
}
// https is an alias for tcp for clarity purpouses
- if(strtolower($backend['type']) == "https") {
+ if(strtolower($bind['type']) == "https") {
$backend_type = "tcp";
$httpchk = "ssl-hello-chk";
} else {
- $backend_type = $backend['type'];
+ $backend_type = $bind['type'];
$httpchk = "httpchk";
}
@@ -237,157 +452,153 @@ function haproxy_configure() {
fwrite ($fd, "\tlog\t\t\tglobal\n");
fwrite ($fd, "\toption\t\t\tdontlognull\n");
- if($backend['httpclose'])
+ if($bind['httpclose'])
fwrite ($fd, "\toption\t\t\thttpclose\n");
- if($backend['forwardfor'])
+ if($bind['forwardfor'])
fwrite ($fd, "\toption\t\t\tforwardfor\n");
- if($backend['max_connections'])
- fwrite ($fd, "\tmaxconn\t\t\t" . $backend['max_connections'] . "\n");
-
- if($backend['client_timeout'])
- fwrite ($fd, "\tclitimeout\t\t" . $backend['client_timeout'] . "\n");
-
- if($backend['balance'])
- fwrite ($fd, "\tbalance\t\t\t" . $backend['balance'] . "\n");
+ if($bind['max_connections'])
+ fwrite ($fd, "\tmaxconn\t\t\t" . $bind['max_connections'] . "\n");
- if($backend['connection_timeout'])
- fwrite ($fd, "\tcontimeout\t\t" . $backend['connection_timeout'] . "\n");
+ if($bind['client_timeout'])
+ fwrite ($fd, "\tclitimeout\t\t" . $bind['client_timeout'] . "\n");
- if($backend['server_timeout'])
- fwrite ($fd, "\tsrvtimeout\t\t" . $backend['server_timeout'] . "\n");
+
+ // Combine the rest of the listener configs
+ $default_once = 0;
+ $i = 0;
+ foreach ($bind['config'] as $bconfig) {
+ $a_acl=&$bconfig['ha_acls']['item'];
+ if(!is_array($a_acl))
+ $a_acl=array();
+
+ $poolname = $bconfig['pool'] . "_" . strtolower($bconfig['type']);
- if($backend['retries'])
- fwrite ($fd, "\tretries\t\t\t" . $backend['retries'] . "\n");
+ // Create different pools if the svrport is set
+ if ($bconfig['svrport'] > 0)
+ $poolname .= "_" . $bconfig['svrport'];
- if($backend['stats_enabled']=='yes') {
- fwrite ($fd, "\tstats\t\t\tenable\n");
- if($backend['stats_uri'])
- fwrite ($fd, "\tstats\t\t\turi ".$backend['stats_uri']."\n");
- if($backend['stats_realm'])
- fwrite ($fd, "\tstats\t\t\trealm " . $backend['stats_realm'] . "\n");
- else
- fwrite ($fd, "\tstats\t\t\trealm .\n");
- fwrite ($fd, "\tstats\t\t\tauth " . $backend['stats_username'].":". $backend['stats_password']."\n");
- }
+ // Write this out once, and must be before any backend config text
+ if ($default_once == 0) {
+ fwrite ($fd, "\tdefault_backend\t\t" . $poolname . "\n");
+ $default_once++;
+ }
- $a_acl=&$backend['ha_acls']['item'];
- if(!is_array($a_acl))
- $a_acl=array();
-
- foreach ($a_acl as $entry) {
- $acl = haproxy_find_acl($entry['expression']);
- if (!$acl)
- continue;
+ if (!isset($a_pendingpl[$poolname])) {
+ $a_pendingpl[$poolname] = array();
+ $a_pendingpl[$poolname]['name'] = $poolname;
+ $a_pendingpl[$poolname]['frontend'] = $bconfig;
+ }
- // Filter out acls for different modes
- if ($acl['mode'] != '' && $acl['mode'] != strtolower($backend['type']))
- continue;
+ foreach ($a_acl as $entry) {
+ $acl = haproxy_find_acl($entry['expression']);
+ if (!$acl)
+ continue;
- if ($acl['syntax'] != '')
- $expr = $acl['syntax'] . " " . $entry['value'];
- else
- $expr = $entry['expression'] . " " . $entry['value'];
+ // Filter out acls for different modes
+ if ($acl['mode'] != '' && $acl['mode'] != strtolower($bind['type']))
+ continue;
- fwrite ($fd, "\tacl\t\t\t".$entry['name']."\t".$expr."\n");
- }
+ if ($acl['syntax'] != '')
+ $expr = $acl['syntax'] . " " . $entry['value'];
+ else
+ $expr = $entry['expression'] . " " . $entry['value'];
- if (is_array($a_pools)) {
- foreach ($a_pools as $pool) {
- if ($backend['pool'] == $pool['name'] && is_array($pool['ha_servers']['item'])) {
- if($pool['status'] != 'active')
- continue;
- if($pool['cookie_name'] && strtolower($backend['type']) == "http")
- fwrite ($fd, "\tcookie\t\t\t" . $pool['cookie_name'] . " insert indirect\n");
-
- $uri = $pool['monitor_uri'];
- if ($pool['monitor_uri'])
- $uri = $pool['monitor_uri'];
- else
- $uri = "/";
- fwrite ($fd, "\toption\t\t\t{$httpchk} HEAD " . $uri . " HTTP/1.0\n");
-
- if($pool['cookie'] && strtolower($backend['type']) == "http")
- $cookie = " cookie {$pool['cookie']} ";
- else
- $cookie = "";
- if($pool['advanced']) {
- $advanced = base64_decode($pool['advanced']);
- $advanced_txt = " " . $advanced;
- } else {
- $advanced_txt = "";
- }
- if($pool['checkinter'])
- $checkinter = "check inter {$pool['checkinter']}";
- else
- $checkinter = "check inter 1000";
-
- $a_servers = &$pool['ha_servers']['item'];
- foreach($a_servers as $be) {
- if(!$be['port']) {
- // the listener can specify a default port
- $be['port'] = $backend['svrport'];
- }
- if(!$be['port']) {
- // last resort, use the frontend port
- $ports = split(",", "{$backend['port']},");
- $be['port'] = $ports[0];
- }
- if (!$be['name'])
- $be['name'] = $be['address'];
- if($be['backup']) {
- $isbackup = "backup";
- } else {
- $isbackup = "";
- }
- fwrite ($fd, "\tserver\t\t\t" . $be['name'] . " " . $be['address'].":" . $be['port'] . " $cookie " . " $checkinter $isbackup weight " . $be['weight'] . "{$advanced_txt}\n");
- }
-
- }
+ $aclname = $i . "_" . $entry['name'];
+ fwrite ($fd, "\tacl\t\t\t" . $aclname . "\t" . $expr . "\n");
+ fwrite ($fd, "\tuse_backend\t\t" . $poolname . " if " . $aclname . "\n");
+ $i++;
}
+
}
fwrite ($fd, "\n");
}
- // Sync HAProxy configuration (if enabled)
- if(isset($config['installedpackages']['haproxy']['enablesync'])) {
- if($config['installedpackages']['haproxy']['synchost1']) {
- haproxy_do_xmlrpc_sync($config['installedpackages']['haproxy']['synchost1'],
- $config['installedpackages']['haproxy']['syncpassword']);
- }
- if($config['installedpackages']['haproxy']['synchost2']) {
- haproxy_do_xmlrpc_sync($config['installedpackages']['haproxy']['synchost2'],
- $config['installedpackages']['haproxy']['syncpassword']);
- }
- if($config['installedpackages']['haproxy']['synchost3']) {
- haproxy_do_xmlrpc_sync($config['installedpackages']['haproxy']['synchost3'],
- $config['installedpackages']['haproxy']['syncpassword']);
+ }
+ if (is_array($a_pendingpl) && is_array($a_pools)) {
+ foreach ($a_pendingpl as $pending) {
+ foreach ($a_pools as $pool) {
+ if ($pending['frontend']['pool'] == $pool['name']) {
+ write_backend($fd, $pending['name'], $pool, $pending['frontend']);
+ }
}
}
}
+ fwrite ($fd, "\n");
+
+ // Sync HAProxy configuration (if enabled)
+ if(isset($config['installedpackages']['haproxy']['enablesync'])) {
+ if($config['installedpackages']['haproxy']['synchost1']) {
+ haproxy_do_xmlrpc_sync($config['installedpackages']['haproxy']['synchost1'],
+ $config['installedpackages']['haproxy']['syncpassword']);
+ }
+ if($config['installedpackages']['haproxy']['synchost2']) {
+ haproxy_do_xmlrpc_sync($config['installedpackages']['haproxy']['synchost2'],
+ $config['installedpackages']['haproxy']['syncpassword']);
+ }
+ if($config['installedpackages']['haproxy']['synchost3']) {
+ haproxy_do_xmlrpc_sync($config['installedpackages']['haproxy']['synchost3'],
+ $config['installedpackages']['haproxy']['syncpassword']);
+ }
+ }
// create config file
fclose($fd);
+ if (isset($a_global['carpdev']))
+ haproxy_install_cron(true);
+ else
+ haproxy_install_cron(false);
+
$freebsd_version = substr(trim(`uname -r`), 0, 1);
if(!file_exists("/usr/bin/limits")) {
exec("fetch -q -o /usr/bin/limits http://files.pfsense.org/extras/{$freebsd_version}/limits");
exec("chmod a+rx /usr/bin/limits");
}
+}
+
+function haproxy_is_running() {
+ $running = (shell_exec("/bin/pgrep -x haproxy") != '');
+ return $running;
+}
+
+function haproxy_check_run($reload) {
+ global $config, $g;
+
+ $a_global = &$config['installedpackages']['haproxy'];
exec("/usr/bin/limits -n 300014");
- // reload haproxy
if(isset($a_global['enable'])) {
- if(is_process_running('haproxy')) {
+ if (isset($a_global['carpdev'])) {
+ $status = get_carp_interface_status($a_global['carpdev']);
+ if ($status != "MASTER") {
+ if (haproxy_is_running()) {
+ log_error("Stopping haproxy on CARP backup.");
+ exec("/bin/pkill -F /var/run/haproxy.pid haproxy");
+ }
+ return (0);
+ } else if (haproxy_is_running() && $reload == 0) {
+ return (0);
+ }
+ log_error("Starting haproxy on CARP master.");
+ /* fallthrough */
+ } else if ($reload == 0)
+ return (0);
+
+ if (haproxy_is_running()) {
exec("/usr/local/sbin/haproxy -f /var/etc/haproxy.cfg -p /var/run/haproxy.pid -st `cat /var/run/haproxy.pid`");
} else {
exec("/usr/local/sbin/haproxy -f /var/etc/haproxy.cfg -p /var/run/haproxy.pid -D");
}
return (0);
} else {
+ if ($reload && haproxy_is_running()) {
+ exec("/bin/pkill -F /var/run/haproxy.pid haproxy");
+ }
return (1);
}
+
}
function haproxy_do_xmlrpc_sync($sync_to_ip, $password) {
diff --git a/config/haproxy-dev/haproxy_global.php b/config/haproxy-dev/haproxy_global.php
index f7864a4d..7f4ce483 100755
--- a/config/haproxy-dev/haproxy_global.php
+++ b/config/haproxy-dev/haproxy_global.php
@@ -56,6 +56,9 @@ if ($_POST) {
$reqdfieldsn = explode(",", "Maximum connections");
}
+ if ($_POST['carpdev'] == "disabled")
+ unset($_POST['carpdev']);
+
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
if ($_POST['maxconn'] && (!is_numeric($_POST['maxconn'])))
@@ -78,6 +81,7 @@ if ($_POST) {
$config['installedpackages']['haproxy']['remotesyslog'] = $_POST['remotesyslog'] ? $_POST['remotesyslog'] : false;
$config['installedpackages']['haproxy']['logfacility'] = $_POST['logfacility'] ? $_POST['logfacility'] : false;
$config['installedpackages']['haproxy']['loglevel'] = $_POST['loglevel'] ? $_POST['loglevel'] : false;
+ $config['installedpackages']['haproxy']['carpdev'] = $_POST['carpdev'] ? $_POST['carpdev'] : false;
$config['installedpackages']['haproxy']['syncpassword'] = $_POST['syncpassword'] ? $_POST['syncpassword'] : false;
$config['installedpackages']['haproxy']['advanced'] = base64_encode($_POST['advanced']) ? $_POST['advanced'] : false;
$config['installedpackages']['haproxy']['nbproc'] = $_POST['nbproc'] ? $_POST['nbproc'] : false;
@@ -98,6 +102,7 @@ $pconfig['synchost3'] = $config['installedpackages']['haproxy']['synchost3'];
$pconfig['remotesyslog'] = $config['installedpackages']['haproxy']['remotesyslog'];
$pconfig['logfacility'] = $config['installedpackages']['haproxy']['logfacility'];
$pconfig['loglevel'] = $config['installedpackages']['haproxy']['loglevel'];
+$pconfig['carpdev'] = $config['installedpackages']['haproxy']['carpdev'];
$pconfig['advanced'] = base64_decode($config['installedpackages']['haproxy']['advanced']);
$pconfig['nbproc'] = $config['installedpackages']['haproxy']['nbproc'];
@@ -271,6 +276,34 @@ function enable_change(enable_change) {
</td>
</tr>
<tr>
+ <td valign="top" class="vncell">
+ Carp monitor
+ </td>
+ <td class="vtable">
+ <select name="carpdev" class="formfld">
+ <option value="disabled" <?php if (!isset($pconfig['carpdev'])) echo "selected"; ?>>
+ disabled
+ </option>
+ <?php
+ if(is_array($config['virtualip']['vip'])) {
+ foreach($config['virtualip']['vip'] as $carp):
+ if ($carp['mode'] != "carp") continue;
+ $ipaddress = $carp['subnet'];
+ $carp_int = find_carp_interface($ipaddress);
+ ?>
+ <option value="<?=$carp_int;?>" <?php if ($carp_int == $pconfig['carpdev']) echo "selected"; ?>>
+ <?=$carp_int;?> (<?=$ipaddress;?>)
+ </option>
+ <?php
+ endforeach;
+ }
+ ?>
+ </select>
+ <br/>
+ Monitor carp interface and only run haproxy on the firewall which is MASTER.
+ </td>
+ </tr>
+ <tr>
<td>
&nbsp;
</td>
diff --git a/config/haproxy-dev/haproxy_pool_edit.php b/config/haproxy-dev/haproxy_pool_edit.php
index 6087e9d7..d25f0675 100755
--- a/config/haproxy-dev/haproxy_pool_edit.php
+++ b/config/haproxy-dev/haproxy_pool_edit.php
@@ -52,7 +52,6 @@ if (isset($id) && $a_pools[$id]) {
$pconfig['checkinter'] = $a_pools[$id]['checkinter'];
$pconfig['monitor_uri'] = $a_pools[$id]['monitor_uri'];
$pconfig['cookie'] = $a_pools[$id]['cookie'];
- $pconfig['status'] = $a_pools[$id]['status'];
$pconfig['advanced'] = base64_decode($a_pools[$id]['advanced']);
$pconfig['a_servers']=&$a_pools[$id]['ha_servers']['item'];
}
@@ -145,7 +144,6 @@ if ($_POST) {
$pool['ha_servers']['item']=$a_servers;
update_if_changed("name", $pool['name'], $_POST['name']);
- update_if_changed("status", $pool['status'], $_POST['status']);
update_if_changed("cookie", $pool['cookie'], $_POST['cookie']);
update_if_changed("advanced", $pool['advanced'], base64_encode($_POST['advanced']));
update_if_changed("checkinter", $pool['checkinter'], $_POST['checkinter']);
@@ -231,15 +229,6 @@ function clearcombo(){
</td>
</tr>
<tr align="left">
- <td width="22%" valign="top" class="vncellreq">Status</td>
- <td width="78%" class="vtable" colspan="2">
- <select name="status">
- <option value="active" <?php if($pconfig['status']=='active') echo "SELECTED";?>>active</option>
- <option value="inactive" <?php if($pconfig['status']=='inactive') echo "SELECTED";?>>inactive</option>
- </select>
- </td>
- </tr>
- <tr align="left">
<td width="22%" valign="top" class="vncell">Cookie</td>
<td width="78%" class="vtable" colspan="2">
<input name="cookie" type="text" <?if(isset($pconfig['cookie'])) echo "value=\"{$pconfig['cookie']}\"";?>size="64"><br/>
diff --git a/config/haproxy-dev/haproxy_pools.php b/config/haproxy-dev/haproxy_pools.php
index 78a1fdff..c5adc70b 100755
--- a/config/haproxy-dev/haproxy_pools.php
+++ b/config/haproxy-dev/haproxy_pools.php
@@ -103,38 +103,41 @@ include("head.inc");
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="30%" class="listhdrr">Name</td>
- <td width="20%" class="listhdrr">Status</td>
- <td width="30%" class="listhdrr">Listener</td>
+ <td width="10%" class="listhdrr">Servers</td>
+ <td width="40%" class="listhdrr">Listener</td>
<td width="10%" class="list"></td>
</tr>
<?php
$i = 0;
foreach ($a_pools as $pool):
+
+ $fe_list = "";
+ $sep = "";
+ foreach ($a_backends as $backend) {
+ if($backend['pool'] == $pool['name']) {
+ $fe_list .= $sep . $backend['name'];
+ $sep = ", ";
+ }
+ }
$textss = $textse = "";
- if ($pool['status'] != 'active') {
+ if ($fe_list == "") {
$textss = "<span class=\"gray\">";
$textse = "</span>";
}
+ if (is_array($pool['ha_servers']['item']))
+ $count = count($pool['ha_servers']['item']);
+ else
+ $count = 0;
?>
<tr>
<td class="listlr" ondblclick="document.location='haproxy_pool_edit.php?id=<?=$i;?>';">
<?=$textss . $pool['name'] . $textse;?>
</td>
<td class="listlr" ondblclick="document.location='haproxy_pool_edit.php?id=<?=$i;?>';">
- <?=$textss . $pool['status'] . $textse;?>
+ <?=$textss . $count . $textse;?>
</td>
<td class="listlr" ondblclick="document.location='haproxy_pool_edit.php?id=<?=$i;?>';">
-<?php
- echo $textss;
- $sep = "";
- foreach ($a_backends as $backend) {
- if($backend['pool'] == $pool['name']) {
- echo $sep . $backend['name'];
- $sep = ", ";
- }
- }
- echo $textse;
-?>
+ <?=$textss . $fe_list . $textse;?>
</td>
<td class="list" nowrap>
<table border="0" cellspacing="0" cellpadding="1">