[LON-CAPA-cvs] cvs: loncom / loncron /init.d loncontrol

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 31 May 2007 05:20:18 -0000


albertel		Thu May 31 01:20:18 2007 EDT

  Modified files:              
    /loncom/init.d	loncontrol 
    /loncom	loncron 
  Log:
  - cleanup sockets directory when starting or stopping lonc
  
  
Index: loncom/init.d/loncontrol
diff -u loncom/init.d/loncontrol:1.29 loncom/init.d/loncontrol:1.30
--- loncom/init.d/loncontrol:1.29	Mon Apr  2 20:47:28 2007
+++ loncom/init.d/loncontrol	Thu May 31 01:20:06 2007
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 #
-# $Id: loncontrol,v 1.29 2007/04/03 00:47:28 albertel Exp $
+# $Id: loncontrol,v 1.30 2007/05/31 05:20:06 albertel Exp $
 #
 # The LearningOnline Network with CAPA
 #
@@ -158,6 +158,14 @@
     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";
@@ -178,6 +186,7 @@
 	&stop_daemon($daemon,$killallname);
     }
     &firewall_close_port();
+    &clean_sockets();
 } elsif ($command eq "start") {
     &firewall_open_port();
     print 'Starting LON-CAPA'."\n";
Index: loncom/loncron
diff -u loncom/loncron:1.73 loncom/loncron:1.74
--- loncom/loncron:1.73	Fri Apr 13 14:26:22 2007
+++ loncom/loncron	Thu May 31 01:20:18 2007
@@ -2,7 +2,7 @@
 
 # Housekeeping program, started by cron, loncontrol and loncron.pl
 #
-# $Id: loncron,v 1.73 2007/04/13 18:26:22 albertel Exp $
+# $Id: loncron,v 1.74 2007/05/31 05:20:18 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -81,7 +81,9 @@
     }
     my $error_fname="$perlvar{'lonDaemons'}/logs/${daemon}_errors";
     &rotate_logfile($error_fname,$fh,'error logs');
-
+    if ($daemon eq 'lonc') {
+	&clean_sockets($fh);
+    }
     system("$perlvar{'lonDaemons'}/$progname 2>$perlvar{'lonDaemons'}/logs/${daemon}_errors");
     sleep 1;
     if (-e $pidfile) {
@@ -399,6 +401,21 @@
     &log($fh,"<h3>$active open session(s)</h3>");
 }
 
+# ----------------------------------------------------------- clean out sockets
+sub clean_sockets {
+    my ($fh)=@_;
+    my $cleaned=0;
+    opendir(SOCKETS,$perlvar{'lonSockDir'});
+    while (my $fname=readdir(SOCKETS)) {
+	next if (-d $fname 
+		 || $fname=~/(mysqlsock|maximasock|\Q$perlvar{'lonSockDir'}\E)/);
+	$cleaned++;
+	&log($fh,"Unlinking $fname<br />");
+	unlink("/home/httpd/sockets/$fname");
+    }
+    &log($fh,"<p>Cleaned up ".$cleaned." stale sockets.</p>");
+}
+
 
 # ----------------------------------------------------------------------- httpd
 sub check_httpd_logs {