--- loncom/init.d/loncontrol 2007/04/03 00:47:28 1.29 +++ loncom/init.d/loncontrol 2008/11/04 21:06:31 1.33 @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# $Id: loncontrol,v 1.29 2007/04/03 00:47:28 albertel Exp $ +# $Id: loncontrol,v 1.33 2008/11/04 21:06:31 www Exp $ # # The LearningOnline Network with CAPA # @@ -37,6 +37,16 @@ # config: /etc/httpd/conf/loncapa.conf # config: /home/httpd/lonTabs/hosts.tab # config: /home/httpd/lonTabs/spare.tab +# SuSE chkconfig/insserv info +### BEGIN INIT INFO +# Provides: loncapa +# Required-Start: mysql apache2 $network $remote_fs +# Required-Stop: +# Default-Start: 3 4 5 +# Default-Stop: +# Description: Starts the LON-CAPA services +### END INIT INFO + $command=$ARGV[0]; $command=~s/[^a-z]//g; @@ -54,7 +64,6 @@ $ENV{'BASH_ENV'}=""; } } my $lond_port = 5663; - my $lonhttpd_port = 8080; sub firewall_open_port { return if (! &firewall_is_active); @@ -64,7 +73,7 @@ sub firewall_open_port { # We could restrict the servers allowed to attempt to communicate # here, but the logistics of updating the /home/httpd/lonTabs/host.tab # file are likely to be a problem - foreach my $port ($lond_port,$lonhttpd_port) { + foreach my $port ($lond_port) { print "Opening firewall access on port $port.\n"; my $firewall_command = @@ -105,7 +114,7 @@ sub firewall_is_active { sub firewall_close_port { return if (! &firewall_is_active); - foreach my $port ($lond_port,$lonhttpd_port) { + foreach my $port ($lond_port) { print "Closing firewall access on port $port.\n"; my $firewall_command = "$iptables -D $fw_chain -p tcp -d 0/0 --dport $port -j ACCEPT"; @@ -134,7 +143,10 @@ sub stop_daemon { my $daemonpid=; chomp($daemonpid); kill TERM => $daemonpid; - sleep 1; + my $count=0; + while ($count++ < 5 && kill(0 => $daemonpid)) { + sleep 1; + } if (kill 0 => $daemonpid) { kill KILL => $daemonpid; sleep 1; @@ -158,11 +170,19 @@ sub stop_daemon { print("\n"); } +sub clean_sockets { + opendir(SOCKETS,"/home/httpd/sockets/"); + while (my $fname=readdir(SOCKETS)) { + next if (-d $fname + || $fname=~/(mysqlsock|maximasock|\Q$perlvar{'lonSockDir'}\E)/); + unlink("/home/httpd/sockets/$fname"); + } +} if ($command eq "restart") { print 'Restarting LON-CAPA'."\n"; print 'Ending LON-CAPA client and daemon processes'."\n"; - foreach my $daemon ('lonsql','lond','lonc','lonhttpd','lonmemcached','lonmaxima') { + foreach my $daemon ('lonsql','lond','lonc','lonmemcached','lonmaxima') { my $killallname=$daemon; if ($daemon eq 'lonc') { $killallname='loncnew'; } &stop_daemon($daemon,$killallname); @@ -172,12 +192,13 @@ if ($command eq "restart") { system("su www -c '/home/httpd/perl/loncron --justcheckdaemons'"); } elsif ($command eq "stop") { print 'Stopping LON-CAPA'."\n"; - foreach my $daemon ('lonsql','lond','lonc','lonhttpd','lonmemcached','lonmaxima') { + foreach my $daemon ('lonsql','lond','lonc','lonmemcached','lonmaxima') { my $killallname=$daemon; if ($daemon eq 'lonc') { $killallname='loncnew'; } &stop_daemon($daemon,$killallname); } &firewall_close_port(); + &clean_sockets(); } elsif ($command eq "start") { &firewall_open_port(); print 'Starting LON-CAPA'."\n";