--- loncom/auth/lonauth.pm 2016/08/11 09:24:13 1.121.2.14 +++ loncom/auth/lonauth.pm 2017/01/21 21:25:26 1.121.2.15 @@ -1,7 +1,7 @@ # The LearningOnline Network # User Authentication Module # -# $Id: lonauth.pm,v 1.121.2.14 2016/08/11 09:24:13 raeburn Exp $ +# $Id: lonauth.pm,v 1.121.2.15 2017/01/21 21:25:26 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -238,7 +238,6 @@ sub reroute { sub handler { my $r = shift; my $londocroot = $r->dir_config('lonDocRoot'); - my $form; # Are we re-routing? if (-e "$londocroot/lon-status/reroute.txt") { &reroute($r); @@ -455,13 +454,25 @@ sub handler { unless ($hosthere) { ($is_balancer,$otherserver) = - &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'}); + &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login'); + if ($is_balancer) { + if ($otherserver eq '') { + my $lowest_load; + ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'}); + if ($lowest_load > 100) { + $otherserver = &Apache::lonnet::spareserver($lowest_load,$lowest_load,1,$form{'udom'}); + } + } + if ($otherserver ne '') { + my @hosts = &Apache::lonnet::current_machine_ids(); + if (grep(/^\Q$otherserver\E$/,@hosts)) { + $hosthere = $otherserver; + } + } + } } - if ($is_balancer) { - if (!$otherserver) { - ($otherserver) = &Apache::lonnet::choose_server($form{'udom'}); - } + if (($is_balancer) && (!$hosthere)) { if ($otherserver) { &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef, \%form); @@ -529,6 +540,9 @@ sub handler { return OK; } } + if (($is_balancer) && ($hosthere)) { + $form{'noloadbalance'} = $hosthere; + } &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef, \%form); return OK;