--- loncom/init.d/loncontrol 2011/05/13 01:36:30 1.42 +++ loncom/init.d/loncontrol 2019/06/09 02:35:41 1.46 @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# $Id: loncontrol,v 1.42 2011/05/13 01:36:30 raeburn Exp $ +# $Id: loncontrol,v 1.46 2019/06/09 02:35:41 raeburn Exp $ # # The LearningOnline Network with CAPA # @@ -93,6 +93,9 @@ sub stop_daemon { print(", killed off extraneous processes"); } unlink($pidfile); + if ($killallname eq 'loncnew') { + &clean_nossl_loncpids(); + } print("\n"); } @@ -107,23 +110,60 @@ sub clean_sockets { } } -if ($command eq "restart") { - print 'Restarting LON-CAPA'."\n"; - print 'Ending LON-CAPA client and daemon processes'."\n"; - foreach my $daemon ('lonsql','lond','lonc','lonmemcached','lonmaxima','lonr') { - my $killallname=$daemon; - if ($daemon eq 'lonc') { $killallname='loncnew'; } - &stop_daemon($daemon,$killallname); +sub clean_nossl_loncpids { + my $childpiddir = '/home/httpd/perl/logs/loncpids'; + my $nossldir = '/home/httpd/sockets/nosslverify'; + foreach my $dir ($childpiddir,$nossldir) { + if (-d $dir) { + if (opendir(my $dh,$dir)) { + while (my $fname=readdir($dh)) { + next if ($fname =~ /^\./); + unlink("$dir/$fname"); + } + closedir($dh); + } + } } - print 'Starting LON-CAPA client and daemon processes (please be patient)'. - "\n"; - system("su www -c '/home/httpd/perl/loncron --justcheckdaemons'"); -} elsif (($command eq "stop") || ($command eq 'start') || ($command eq 'status')) { +} + +if (($command eq "restart") || ($command eq 'stop') || + ($command eq 'start') || ($command eq "status")) { my $iptables = &LONCAPA::Firewall::get_pathto_iptables(); my @fw_chains = &LONCAPA::Firewall::get_fw_chains($iptables); my $lond_port = &LONCAPA::Firewall::get_lond_port(); + my $firewalld = &LONCAPA::Firewall::uses_firewalld(); my %iphost; - if ($command eq 'stop') { + if ($command eq 'restart') { + print 'Restarting LON-CAPA'."\n"; + print 'Ending LON-CAPA client and daemon processes'."\n"; + foreach my $daemon ('lonsql','lond','lonc','lonmemcached','lonmaxima','lonr') { + my $killallname=$daemon; + if ($daemon eq 'lonc') { $killallname='loncnew'; } + &stop_daemon($daemon,$killallname); + } + %iphost = &Apache::lonnet::get_iphost('',1); + my $firewall_result = + &LONCAPA::Firewall::firewall_close_port($iptables,\@fw_chains, + $lond_port,\%iphost,[$lond_port], + $firewalld); + if ($firewall_result) { + print "$firewall_result\n"; + } + $firewall_result = + &LONCAPA::Firewall::firewall_open_port($iptables,\@fw_chains, + $lond_port,\%iphost,[$lond_port], + $firewalld); + if (($firewall_result eq 'ok') || ($firewall_result eq 'inactive firewall')) { + if ($firewall_result eq 'inactive firewall') { + print "WARNING: iptables firewall is currently inactive\n"; + } + } elsif ($firewall_result) { + print "$firewall_result\n"; + } + print 'Starting LON-CAPA client and daemon processes (please be patient)'. + "\n"; + system("su www -c '/home/httpd/perl/loncron --justcheckdaemons'"); + } elsif ($command eq 'stop') { print 'Stopping LON-CAPA'."\n"; foreach my $daemon ('lonsql','lond','lonc','lonmemcached','lonmaxima','lonr') { my $killallname=$daemon; @@ -131,15 +171,19 @@ if ($command eq "restart") { &stop_daemon($daemon,$killallname); } my $firewall_result = - &LONCAPA::Firewall::firewall_close_port($iptables,\@fw_chains,$lond_port,\%iphost,[$lond_port]); + &LONCAPA::Firewall::firewall_close_port($iptables,\@fw_chains, + $lond_port,\%iphost,[$lond_port], + $firewalld); if ($firewall_result) { print "$firewall_result\n"; } &clean_sockets(); } elsif ($command eq "start") { - %iphost = &Apache::lonnet::get_iphost(); + %iphost = &Apache::lonnet::get_iphost('',1); my $firewall_result = - &LONCAPA::Firewall::firewall_open_port($iptables,\@fw_chains,$lond_port,\%iphost,[$lond_port]); + &LONCAPA::Firewall::firewall_open_port($iptables,\@fw_chains, + $lond_port,\%iphost,[$lond_port], + $firewalld); if (($firewall_result eq 'ok') || ($firewall_result eq 'inactive firewall')) { if ($firewall_result eq 'inactive firewall') { print "WARNING: iptables firewall is currently inactive\n"; @@ -171,12 +215,12 @@ if ($command eq "restart") { if ($lond_port) { my $londopen; foreach my $fw_chain (@fw_chains) { - my $numopen = &LONCAPA::Firewall::firewall_is_port_open($iptables,$fw_chain,$lond_port,$lond_port,\%iphost); + my $numopen = &LONCAPA::Firewall::firewall_is_port_open($iptables,$fw_chain,$lond_port,$lond_port,\%iphost,$firewalld); $londopen += $numopen; } if ($londopen) { print "The LON-CAPA port ($lond_port) is open in firewall.\n"; - } elsif (&LONCAPA::Firewall::firewall_is_active) { + } elsif (&LONCAPA::Firewall::firewall_is_active()) { print "The LON-CAPA port ($lond_port) is NOT open in running firewall!\n"; } } else {