File:  [LON-CAPA] / loncom / init.d / loncontrol
Revision 1.19: download - view: text, annotated - select for diffs
Thu Aug 19 18:31:42 2004 UTC (19 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_1_2_X, version_1_2_99_0, version_1_2_1, version_1_2_0, version_1_1_99_5, HEAD
- trying to double check after a stop that all daemons are really gone

    1: #!/usr/bin/perl
    2: #
    3: # The LearningOnline Network with CAPA
    4: #
    5: # Startup script for the LON-CAPA network processes
    6: #
    7: # YEAR=2000
    8: # YEAR=2001
    9: # YEAR=2002
   10: 
   11: # chkconfig: 345 95 5
   12: # description: LON-CAPA is a "network of knowledge".  It is used to
   13: # distribute knowledge resources and instructional management.
   14: # processnames: lonc, lond, lonsql
   15: # pidfiles: /home/httpd/perl/logs/lon*.pid
   16: # config: /etc/httpd/conf/loncapa.conf
   17: # config: /home/httpd/lonTabs/hosts.tab
   18: # config: /home/httpd/lonTabs/spare.tab
   19: 
   20: $command=$ARGV[0]; $command=~s/[^a-z]//g;
   21: 
   22: $ENV{'PATH'}="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin";
   23: $ENV{'BASH_ENV'}="";
   24: 
   25: sub stop_daemon {
   26:     my ($daemon,$killallname)=@_;
   27:     my $pidfile="/home/httpd/perl/logs/$daemon.pid";
   28:     
   29:     printf("%-10s ",$daemon);
   30:     if (-e $pidfile) {
   31: 	open(PIDFILE,$pidfile);
   32: 	my $daemonpid=<PIDFILE>;
   33: 	chomp($daemonpid);
   34: 	kill TERM => $daemonpid;
   35: 	sleep 2;
   36: 	if (kill 0 => $daemonpid) {
   37: 	    kill KILL => $daemonpid;
   38: 	    sleep 2;
   39: 	    if (kill 0 => $daemonpid) {
   40: 		print("failed to kill");
   41: 	    } else {
   42: 		print("killed");
   43: 	    }
   44: 	} else {
   45: 	    print("stopped");
   46: 	}
   47:     } else {
   48: 	print("not running");
   49:     }
   50:     system("killall -q -0 $killallname");
   51:     if ($? == 0) {
   52: 	system("killall -q $killallname");
   53: 	print(", killed off extraneous processes");
   54:     }
   55:     print("\n");
   56: }
   57: 
   58: if (($command eq "restartold") or ($command eq "reloadold")) {
   59:     print 'Restarting LON-CAPA'."\n";
   60:     print 'Ending LON-CAPA client and daemon processes'."\n";
   61:     foreach my $daemon ('lonsql','lond','lonc','lonhttpd') {
   62: 	&stop_daemon($daemon,$daemon);
   63:     }
   64:     print 'Starting LON-CAPA client and daemon processes (please be patient)'.
   65: 	"\n";
   66:     system("su www -c '/home/httpd/perl/loncron --oldlonc --justcheckdaemons'");
   67: } elsif (($command eq "restart") or ($command eq "reload")) {
   68:     print 'Restarting LON-CAPA'."\n";
   69:     print 'Ending LON-CAPA client and daemon processes'."\n";
   70:     foreach my $daemon ('lonsql','lond','lonc','lonhttpd') {
   71: 	my $killallname=$daemon;
   72: 	if ($daemon eq 'lonc') { $killallname='loncnew'; }
   73: 	&stop_daemon($daemon,$killallname);
   74:     }
   75:     print 'Starting LON-CAPA client and daemon processes (please be patient)'.
   76: 	"\n";
   77:     system("su www -c '/home/httpd/perl/loncron --justcheckdaemons'");
   78: } elsif ($command eq "stop") {
   79:     print 'Stopping LON-CAPA'."\n";
   80:     foreach my $daemon ('lonsql','lond','lonc','lonhttpd') {
   81: 	my $killallname=$daemon;
   82: 	if ($daemon eq 'lonc') { $killallname='loncnew'; }
   83: 	&stop_daemon($daemon,$killallname);
   84:     }
   85: } elsif ($command eq "startold") {
   86:     print 'Starting LON-CAPA'."\n";
   87:     print 'Starting LON-CAPA client and daemon processes (please be patient)'.
   88: 	"\n"; 
   89:     system("su www -c '/home/httpd/perl/loncron --oldlonc --justcheckdaemons'");
   90: } elsif ($command eq "start") {
   91:     print 'Starting LON-CAPA'."\n";
   92:     print 'Starting LON-CAPA client and daemon processes (please be patient)'.
   93: 	"\n"; 
   94:     system("su www -c '/home/httpd/perl/loncron --justcheckdaemons'");
   95: } elsif ($command eq "status") {
   96:     $response=`/bin/cat /home/httpd/perl/logs/*.pid 2>&1`;
   97:     if ($response=~/No such file or directory/) {
   98: 	print 'LON-CAPA is not running.'."\n";
   99:     } else {
  100: 	print 'LON-CAPA is running.'."\n";
  101: 	system("su www -c '/home/httpd/perl/loncron --justcheckconnections'");
  102:     }
  103: } else {
  104:     print 'You need to specify one of restart|stop|start|status on the command line.'."\n";
  105: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>