Annotation of loncom/lonManage, revision 1.6
1.1 foxr 1: #!/usr/bin/perl
2: # The LearningOnline Network with CAPA
3: #
4: # lonManage supports remote management of nodes in a LonCAPA cluster.
5: #
1.6 ! foxr 6: # $Id: lonManage,v 1.5 2003/08/12 10:55:42 foxr Exp $
1.1 foxr 7: #
1.6 ! foxr 8: # $Id: lonManage,v 1.5 2003/08/12 10:55:42 foxr Exp $
1.1 foxr 9: #
10: # Copyright Michigan State University Board of Trustees
11: #
12: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
13: ## LON-CAPA is free software; you can redistribute it and/or modify
14: # it under the terms of the GNU General Public License as published by
15: # the Free Software Foundation; either version 2 of the License, or
16: # (at your option) any later version.
17: #
18: # LON-CAPA is distributed in the hope that it will be useful,
19: # but WITHOUT ANY WARRANTY; without even the implied warranty of
20: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: # GNU General Public License for more details.
22: #
23: # You should have received a copy of the GNU General Public License
24: # along with LON-CAPA; if not, write to the Free Software
25: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26: #
27: # /home/httpd/html/adm/gpl.txt
28: #
29: # http://www.lon-capa.org/
30: #
31: #
32: # lonManage supports management of remot nodes in a lonCAPA cluster.
33: # it is a command line tool. The following command line syntax (usage)
34: # is supported:
35: #
36: # lonManage -push <tablename> newfile host
37: # Push <tablename> to the lonTabs directory. Note that
38: # <tablename> must be one of:
39: # hosts (hosts.tab)
40: # domain (domain.tab)
41: #
42: # lonManage -reinit lonc host
43: # Sends a HUP signal to the remote systems's lond.
44: #
45: # lonmanage -reinit lond host
46: # Requests the remote system's lond perform the same action as if
47: # it had received a HUP signal.
48: #
49: # In the above syntax, the host above is the hosts.tab name of a host,
50: # not the IP address of the host.
51: #
1.3 foxr 52: # $Log: lonManage,v $
1.6 ! foxr 53: # Revision 1.5 2003/08/12 10:55:42 foxr
! 54: # Complete command line parsing (tested)
! 55: #
1.5 foxr 56: # Revision 1.4 2003/08/12 10:40:44 foxr
57: # Get switch parsing right.
58: #
1.4 foxr 59: # Revision 1.3 2003/08/12 10:22:35 foxr
60: # Put in parameter parsing infrastructure
61: #
1.3 foxr 62: # Revision 1.2 2003/08/12 09:58:49 foxr
63: # Add usage and skeleton documentation.
1.2 foxr 64: #
1.3 foxr 65: #
66: use Getopt::Long;
1.2 foxr 67:
1.3 foxr 68: sub Usage {
1.2 foxr 69: print "Usage:";
70: print <<USAGE;
1.3 foxr 71: lonManage --push=<tablename> newfile host
1.2 foxr 72: Push <tablename> to the lonTabs directory. Note that
73: <tablename> must be one of:
74: hosts (hosts.tab)
75: domain (domain.tab)
76:
1.3 foxr 77: lonManage --reinit=lonc host
1.2 foxr 78: Sends a HUP signal to the remote systems's lond.
79:
1.3 foxr 80: lonmanage --reinit=lond host
1.2 foxr 81: Requests the remote system's lond perform the same action as if
82: it had received a HUP signal.
83:
84: In the above syntax, the host above is the hosts.tab name of a host,
85: not the IP address of the host.
86: USAGE
87:
88:
89: }
90:
91: #
1.3 foxr 92: # Use Getopt::Long to parse the parameters of the program.
93: #
94: # Return value is a list consisting of:
95: # A 'command' which is one of:
96: # push - table push requested.
97: # reinit - reinit requested.
98: # Additional parameters as follows:
99: # for push: Tablename, hostname
100: # for reinit: Appname hostname
101: #
102: # This function does not validation of the parameters of push and
103: # reinit.
1.4 foxr 104: #
105: # returns a list. The first element of the list is the operation name
106: # (e.g. reinit or push). The second element is the switch parameter.
107: # for push, this is the table name, for reinit, this is the process name.
108: # Additional elements of the list are the command argument. The count of
109: # command arguments is validated, but not their semantics.
110: #
1.3 foxr 111: # returns an empty list if the parse fails.
112: #
113:
114: sub ParseArgs {
1.4 foxr 115: my $pushing = '';
116: my $reiniting = '';
1.5 foxr 117:
1.4 foxr 118: if(!GetOptions('push=s' => \$pushing,
119: 'reinit=s' => \$reinitting)) {
120: return ();
121: }
122:
123: # Require exactly one of --push and --reinit
124:
1.5 foxr 125: my $command = '';
1.4 foxr 126: my $commandarg = '';
1.5 foxr 127: my $paramcount = @ARGV; # Number of additional arguments.
128:
129:
1.4 foxr 130: if($pushing ne '') {
1.5 foxr 131:
132: # --push takes in addition a table, and a host:
133: #
134: if($paramcount != 2) {
135: return (); # Invalid parameter count.
136: }
1.4 foxr 137: if($command ne '') {
138: return ();
139: } else {
1.5 foxr 140:
1.4 foxr 141: $command = 'push';
142: $commandarg = $pushing;
143: }
144: }
1.5 foxr 145:
1.4 foxr 146: if ($reinitting ne '') {
1.5 foxr 147:
148: # --reinit takes in addition just a host name
149:
150: if($paramcount != 1) {
151: return ();
152: }
1.4 foxr 153: if($command ne '') {
154: return ();
155: } else {
156: $command = 'reinit';
157: $commandarg = $reinitting;
158: }
159: }
160:
1.5 foxr 161: # Build the result list:
162:
163: my @result = ($command, $commandarg);
164: my $i;
165: for($i = 0; $i < $paramcount; $i++) {
166: push(@result, $ARGV[$i]);
167: }
168:
169: return @result;
1.3 foxr 170: }
171:
1.6 ! foxr 172: #--------------------------- Entry point: --------------------------
! 173:
! 174: # Parse the parameters
! 175: # If command parsing failed, then print usage:
1.2 foxr 176:
1.6 ! foxr 177: @params = ParseArgs;
! 178: $nparam = @params;
1.3 foxr 179:
180: if($nparam == 0) {
1.2 foxr 181: Usage;
1.4 foxr 182: exit -1;
1.2 foxr 183: }
1.5 foxr 184:
1.6 ! foxr 185:
! 186: sub PushFile {
! 187: print "Pushing a file\n";
! 188: }
! 189:
! 190: sub ReinitProcess {
! 191: print "Reinitializing a process\n";
1.5 foxr 192: }
1.4 foxr 193:
1.6 ! foxr 194: # Based on the operation requested invoke the appropriate function:
! 195:
! 196: $operation = shift @params;
! 197:
! 198: if($operation eq "push") { # push tablename filename host
! 199: $tablename = shift @params;
! 200: $tablefile = shift @params;
! 201: $host = shift @params;
! 202: PushFile($tablename, $tablefile, $host);
! 203:
! 204: }
! 205: if($operation eq "reinit") { # reinit processname host.
! 206: $process = shift @params;
! 207: $host = shift @params;
! 208: ReinitProcess($process, $host);
! 209: }
1.4 foxr 210: exit 0;
1.2 foxr 211:
212: =head1 NAME
213: lonManage - Command line utility for remote management of lonCAPA
214: cluster nodes.
215:
216: =head1 SYNOPSIS
217:
218: Usage:
1.3 foxr 219: B<lonManage --push=<tablename> newfile host>
1.2 foxr 220: Push <tablename> to the lonTabs directory. Note that
221: <tablename> must be one of:
222: hosts (hosts.tab)
223: domain (domain.tab)
224:
1.3 foxr 225: B<lonManage --reinit=lonc host>
1.2 foxr 226: Sends a HUP signal to the remote systems's lond.
227:
1.3 foxr 228: B<lonmanage --reinit=lond host>
1.2 foxr 229: Requests the remote system's lond perform the same action as if
230: it had received a HUP signal.
231:
232: In the above syntax, the host above is the hosts.tab name of a host,
233: not the IP address of the host.
234:
235:
236: =head1 DESCRIPTION
237:
238: =head1 PREREQUISITES
1.3 foxr 239:
240: =item Getopt::Long
1.2 foxr 241:
242: =head1 CATEGORIES
243: Command line utility
244:
245: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>