Annotation of loncom/init.d/loncontrol, revision 1.38
1.1 harris41 1: #!/usr/bin/perl
1.2 harris41 2: #
1.38 ! raeburn 3: # $Id: loncontrol,v 1.37 2009/06/10 23:51:46 raeburn Exp $
1.23 matthew 4: #
1.6 harris41 5: # The LearningOnline Network with CAPA
6: #
1.21 matthew 7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
1.2 harris41 29: # Startup script for the LON-CAPA network processes
1.6 harris41 30: #
1.7 harris41 31:
1.3 harris41 32: # chkconfig: 345 95 5
1.21 matthew 33: # description: LON-CAPA is a "network of knowledge". It is used to \
1.6 harris41 34: # distribute knowledge resources and instructional management.
1.35 raeburn 35: # processnames: lonc, lond, lonsql, lonmaxima, lonr
1.2 harris41 36: # pidfiles: /home/httpd/perl/logs/lon*.pid
1.7 harris41 37: # config: /etc/httpd/conf/loncapa.conf
1.2 harris41 38: # config: /home/httpd/lonTabs/hosts.tab
39: # config: /home/httpd/lonTabs/spare.tab
1.31 albertel 40: # SuSE chkconfig/insserv info
41: ### BEGIN INIT INFO
42: # Provides: loncapa
43: # Required-Start: mysql apache2 $network $remote_fs
44: # Required-Stop:
45: # Default-Start: 3 4 5
46: # Default-Stop:
47: # Description: Starts the LON-CAPA services
48: ### END INIT INFO
49:
1.34 raeburn 50: use strict;
51: use lib '/home/httpd/lib/perl/';
52: use LONCAPA::Configuration;
1.37 raeburn 53: use LONCAPA::Firewall;
1.36 raeburn 54: use Apache::lonnet;
1.2 harris41 55:
1.34 raeburn 56: my $command=$ARGV[0]; $command=~s/[^a-z]//g;
1.1 harris41 57:
58: $ENV{'PATH'}="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin";
59: $ENV{'BASH_ENV'}="";
60:
1.11 albertel 61: sub stop_daemon {
1.19 albertel 62: my ($daemon,$killallname)=@_;
1.11 albertel 63: my $pidfile="/home/httpd/perl/logs/$daemon.pid";
64:
1.24 albertel 65: printf("%-15s ",$daemon);
1.11 albertel 66: if (-e $pidfile) {
67: open(PIDFILE,$pidfile);
68: my $daemonpid=<PIDFILE>;
69: chomp($daemonpid);
70: kill TERM => $daemonpid;
1.32 albertel 71: my $count=0;
72: while ($count++ < 5 && kill(0 => $daemonpid)) {
73: sleep 1;
74: }
1.11 albertel 75: if (kill 0 => $daemonpid) {
76: kill KILL => $daemonpid;
1.26 albertel 77: sleep 1;
1.11 albertel 78: if (kill 0 => $daemonpid) {
1.19 albertel 79: print("failed to kill");
1.11 albertel 80: } else {
1.19 albertel 81: print("killed");
1.11 albertel 82: }
83: } else {
1.19 albertel 84: print("stopped");
1.11 albertel 85: }
1.19 albertel 86: } else {
87: print("not running");
88: }
89: system("killall -q -0 $killallname");
90: if ($? == 0) {
91: system("killall -q $killallname");
92: print(", killed off extraneous processes");
1.11 albertel 93: }
1.24 albertel 94: unlink($pidfile);
1.19 albertel 95: print("\n");
1.11 albertel 96: }
97:
1.30 albertel 98: sub clean_sockets {
99: opendir(SOCKETS,"/home/httpd/sockets/");
1.34 raeburn 100: my $perlvarref=&LONCAPA::Configuration::read_conf();
101: return if (ref($perlvarref) ne 'HASH');
1.30 albertel 102: while (my $fname=readdir(SOCKETS)) {
103: next if (-d $fname
1.34 raeburn 104: || $fname=~/(mysqlsock|maximasock|\Q$perlvarref->{'lonSockDir'}\E)/);
1.30 albertel 105: unlink("/home/httpd/sockets/$fname");
106: }
107: }
1.20 matthew 108:
1.29 albertel 109: if ($command eq "restart") {
1.12 albertel 110: print 'Restarting LON-CAPA'."\n";
111: print 'Ending LON-CAPA client and daemon processes'."\n";
1.35 raeburn 112: foreach my $daemon ('lonsql','lond','lonc','lonmemcached','lonmaxima','lonr') {
1.19 albertel 113: my $killallname=$daemon;
114: if ($daemon eq 'lonc') { $killallname='loncnew'; }
115: &stop_daemon($daemon,$killallname);
1.12 albertel 116: }
117: print 'Starting LON-CAPA client and daemon processes (please be patient)'.
118: "\n";
1.18 albertel 119: system("su www -c '/home/httpd/perl/loncron --justcheckdaemons'");
1.37 raeburn 120: } elsif (($command eq "stop") || ($command eq 'start') || ($command eq 'status')) {
121: my $iptables = &LONCAPA::Firewall::get_pathto_iptables();
1.38 ! raeburn 122: my $fw_chain = &LONCAPA::Firewall::get_fw_chain($iptables);
1.37 raeburn 123: my $lond_port = &LONCAPA::Firewall::get_lond_port();
124: my %iphost = &Apache::lonnet::get_iphost();
125: if ($command eq 'stop') {
126: print 'Stopping LON-CAPA'."\n";
127: foreach my $daemon ('lonsql','lond','lonc','lonmemcached','lonmaxima','lonr') {
128: my $killallname=$daemon;
129: if ($daemon eq 'lonc') { $killallname='loncnew'; }
130: &stop_daemon($daemon,$killallname);
131: }
132: my $firewall_result =
133: &LONCAPA::Firewall::firewall_close_port($iptables,$fw_chain,$lond_port,[$lond_port]);
134: if ($firewall_result) {
135: print "$firewall_result\n";
136: }
137: &clean_sockets();
138: } elsif ($command eq "start") {
139: my $firewall_result =
140: &LONCAPA::Firewall::firewall_open_port($iptables,$fw_chain,$lond_port,\%iphost,[$lond_port]);
141: if (($firewall_result eq 'ok') || ($firewall_result eq 'inactive firewall')) {
142: if ($firewall_result eq 'inactive firewall') {
143: print "WARNING: iptables firewall is currently inactive\n";
144: }
145: print 'Starting LON-CAPA'."\n";
146: print 'Starting LON-CAPA client and daemon processes (please be patient)'.
147: "\n";
148: system("su www -c '/home/httpd/perl/loncron --justcheckdaemons'");
149: } else {
150: print "Not starting LON-CAPA\n";
151: if ($firewall_result eq 'port number unknown') {
152: print "Could not check for status of LON-CAPA port in running firewall - port number unknown. \n";
153: } elsif ($firewall_result) {
154: print "$firewall_result\n";
155: }
156: }
157: } elsif ($command eq "status") {
158: my $response=`/bin/cat /home/httpd/perl/logs/*.pid 2>&1`;
159: if ($response=~/No such file or directory/) {
160: print 'LON-CAPA is not running.'."\n";
161: } else {
162: print 'LON-CAPA is running.'."\n";
163: system("su www -c '/home/httpd/perl/loncron --justcheckconnections'");
164: }
165: if (! &LONCAPA::Firewall::firewall_is_active()) {
166: print 'The iptables firewall is not active'."\n";
1.34 raeburn 167: }
1.37 raeburn 168: if ($lond_port) {
169: if (&LONCAPA::Firewall::firewall_is_port_open($iptables,$fw_chain,$lond_port,$lond_port,\%iphost)) {
170: print "The LON-CAPA port ($lond_port) is open in firewall.\n";
171: } elsif (&LONCAPA::Firewall::firewall_is_active) {
172: print "The LON-CAPA port ($lond_port) is NOT open in running firewall!\n";
173: }
174: } else {
175: if (&LONCAPA::Firewall::firewall_is_active()) {
176: print "Could not check for status of LON-CAPA port in running firewall - port number unknown.\n";
177: } else {
178: print "LON-CAPA port number is unknown, and firewall is not running.\n";
179: }
1.34 raeburn 180: }
181: }
1.25 albertel 182: } elsif ($command eq "reload") {
183: print 'Reload LON-CAPA config files'."\n";
184: system("su www -c '/home/httpd/perl/loncron --justreload'");
1.16 albertel 185: } else {
1.37 raeburn 186: print "You need to specify one of reload|restart|stop|start|status on the command line.\n";
1.1 harris41 187: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>