Annotation of loncom/init.d/loncontrol, revision 1.18

1.1       harris41    1: #!/usr/bin/perl
1.2       harris41    2: #
1.6       harris41    3: # The LearningOnline Network with CAPA
                      4: #
1.2       harris41    5: # Startup script for the LON-CAPA network processes
1.6       harris41    6: #
                      7: # YEAR=2000
                      8: # YEAR=2001
1.7       harris41    9: # YEAR=2002
                     10: 
1.3       harris41   11: # chkconfig: 345 95 5
1.9       harris41   12: # description: LON-CAPA is a "network of knowledge".  It is used to
1.6       harris41   13: # distribute knowledge resources and instructional management.
1.2       harris41   14: # processnames: lonc, lond, lonsql
                     15: # pidfiles: /home/httpd/perl/logs/lon*.pid
1.7       harris41   16: # config: /etc/httpd/conf/loncapa.conf
1.2       harris41   17: # config: /home/httpd/lonTabs/hosts.tab
                     18: # config: /home/httpd/lonTabs/spare.tab
                     19: 
1.1       harris41   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: 
1.11      albertel   25: sub stop_daemon {
                     26:     my ($daemon)=@_;
                     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\n"); return;
                     41: 	    } else {
                     42: 		print("killed\n"); return;
                     43: 	    }
                     44: 	} else {
                     45: 	    print("stopped\n"); return;
                     46: 	}
                     47:     }
                     48:     print("not running\n");
                     49: }
                     50: 
1.16      albertel   51: if (($command eq "restartold") or ($command eq "reloadold")) {
1.6       harris41   52:     print 'Restarting LON-CAPA'."\n";
                     53:     print 'Ending LON-CAPA client and daemon processes'."\n";
1.13      albertel   54:     foreach my $daemon ('lonsql','lond','lonc','lonhttpd') {
1.11      albertel   55: 	&stop_daemon($daemon);
                     56:     }
1.6       harris41   57:     print 'Starting LON-CAPA client and daemon processes (please be patient)'.
                     58: 	"\n";
1.18    ! albertel   59:     system("su www -c '/home/httpd/perl/loncron --oldlonc --justcheckdaemons'");
1.16      albertel   60: } elsif (($command eq "restart") or ($command eq "reload")) {
1.12      albertel   61:     print 'Restarting LON-CAPA'."\n";
                     62:     print 'Ending LON-CAPA client and daemon processes'."\n";
1.13      albertel   63:     foreach my $daemon ('lonsql','lond','lonc','lonhttpd') {
1.12      albertel   64: 	&stop_daemon($daemon);
                     65:     }
                     66:     print 'Starting LON-CAPA client and daemon processes (please be patient)'.
                     67: 	"\n";
1.18    ! albertel   68:     system("su www -c '/home/httpd/perl/loncron --justcheckdaemons'");
1.16      albertel   69: } elsif ($command eq "stop") {
1.6       harris41   70:     print 'Stopping LON-CAPA'."\n";
1.13      albertel   71:     foreach my $daemon ('lonsql','lond','lonc','lonhttpd') {
1.11      albertel   72: 	&stop_daemon($daemon);
                     73:     }
1.16      albertel   74: } elsif ($command eq "startold") {
1.6       harris41   75:     print 'Starting LON-CAPA'."\n";
                     76:     print 'Starting LON-CAPA client and daemon processes (please be patient)'.
                     77: 	"\n"; 
1.18    ! albertel   78:     system("su www -c '/home/httpd/perl/loncron --oldlonc --justcheckdaemons'");
1.16      albertel   79: } elsif ($command eq "start") {
1.12      albertel   80:     print 'Starting LON-CAPA'."\n";
                     81:     print 'Starting LON-CAPA client and daemon processes (please be patient)'.
                     82: 	"\n"; 
1.18    ! albertel   83:     system("su www -c '/home/httpd/perl/loncron --justcheckdaemons'");
1.16      albertel   84: } elsif ($command eq "status") {
1.1       harris41   85:     $response=`/bin/cat /home/httpd/perl/logs/*.pid 2>&1`;
                     86:     if ($response=~/No such file or directory/) {
1.6       harris41   87: 	print 'LON-CAPA is not running.'."\n";
1.18    ! albertel   88:     } else {
1.6       harris41   89: 	print 'LON-CAPA is running.'."\n";
1.18    ! albertel   90: 	system("su www -c '/home/httpd/perl/loncron --justcheckconnections'");
1.1       harris41   91:     }
1.16      albertel   92: } else {
1.18    ! albertel   93:     print 'You need to specify one of restart|stop|start|status on the command line.'."\n";
1.1       harris41   94: }

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