1: #!/usr/bin/perl
2: # The LearningOnline Network with CAPA
3: #
4: # lonManage supports remote management of nodes in a LonCAPA cluster.
5: #
6: # $Id: lonManage,v 1.6 2003/08/12 11:02:59 foxr Exp $
7: #
8: # $Id: lonManage,v 1.6 2003/08/12 11:02:59 foxr Exp $
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: #
52: # $Log: lonManage,v $
53: # Revision 1.6 2003/08/12 11:02:59 foxr
54: # Implement command switch dispatching.
55: #
56: # Revision 1.5 2003/08/12 10:55:42 foxr
57: # Complete command line parsing (tested)
58: #
59: # Revision 1.4 2003/08/12 10:40:44 foxr
60: # Get switch parsing right.
61: #
62: # Revision 1.3 2003/08/12 10:22:35 foxr
63: # Put in parameter parsing infrastructure
64: #
65: # Revision 1.2 2003/08/12 09:58:49 foxr
66: # Add usage and skeleton documentation.
67: #
68: #
69: use Getopt::Long;
70:
71: sub Usage {
72: print "Usage:";
73: print <<USAGE;
74: lonManage --push=<tablename> newfile host
75: Push <tablename> to the lonTabs directory. Note that
76: <tablename> must be one of:
77: hosts (hosts.tab)
78: domain (domain.tab)
79:
80: lonManage --reinit=lonc host
81: Sends a HUP signal to the remote systems's lond.
82:
83: lonmanage --reinit=lond host
84: Requests the remote system's lond perform the same action as if
85: it had received a HUP signal.
86:
87: In the above syntax, the host above is the hosts.tab name of a host,
88: not the IP address of the host.
89: USAGE
90:
91:
92: }
93:
94: #
95: # Use Getopt::Long to parse the parameters of the program.
96: #
97: # Return value is a list consisting of:
98: # A 'command' which is one of:
99: # push - table push requested.
100: # reinit - reinit requested.
101: # Additional parameters as follows:
102: # for push: Tablename, hostname
103: # for reinit: Appname hostname
104: #
105: # This function does not validation of the parameters of push and
106: # reinit.
107: #
108: # returns a list. The first element of the list is the operation name
109: # (e.g. reinit or push). The second element is the switch parameter.
110: # for push, this is the table name, for reinit, this is the process name.
111: # Additional elements of the list are the command argument. The count of
112: # command arguments is validated, but not their semantics.
113: #
114: # returns an empty list if the parse fails.
115: #
116:
117: sub ParseArgs {
118: my $pushing = '';
119: my $reiniting = '';
120:
121: if(!GetOptions('push=s' => \$pushing,
122: 'reinit=s' => \$reinitting)) {
123: return ();
124: }
125:
126: # Require exactly one of --push and --reinit
127:
128: my $command = '';
129: my $commandarg = '';
130: my $paramcount = @ARGV; # Number of additional arguments.
131:
132:
133: if($pushing ne '') {
134:
135: # --push takes in addition a table, and a host:
136: #
137: if($paramcount != 2) {
138: return (); # Invalid parameter count.
139: }
140: if($command ne '') {
141: return ();
142: } else {
143:
144: $command = 'push';
145: $commandarg = $pushing;
146: }
147: }
148:
149: if ($reinitting ne '') {
150:
151: # --reinit takes in addition just a host name
152:
153: if($paramcount != 1) {
154: return ();
155: }
156: if($command ne '') {
157: return ();
158: } else {
159: $command = 'reinit';
160: $commandarg = $reinitting;
161: }
162: }
163:
164: # Build the result list:
165:
166: my @result = ($command, $commandarg);
167: my $i;
168: for($i = 0; $i < $paramcount; $i++) {
169: push(@result, $ARGV[$i]);
170: }
171:
172: return @result;
173: }
174:
175: #--------------------------- Entry point: --------------------------
176:
177: # Parse the parameters
178: # If command parsing failed, then print usage:
179:
180: @params = ParseArgs;
181: $nparam = @params;
182:
183: if($nparam == 0) {
184: Usage;
185: exit -1;
186: }
187:
188:
189: sub PushFile {
190: print "Pushing a file\n";
191: }
192:
193: sub ReinitProcess {
194: print "Reinitializing a process\n";
195: }
196:
197: # Based on the operation requested invoke the appropriate function:
198:
199: $operation = shift @params;
200:
201: if($operation eq "push") { # push tablename filename host
202: $tablename = shift @params;
203: $tablefile = shift @params;
204: $host = shift @params;
205: PushFile($tablename, $tablefile, $host);
206:
207: }
208: if($operation eq "reinit") { # reinit processname host.
209: $process = shift @params;
210: $host = shift @params;
211: ReinitProcess($process, $host);
212: }
213: exit 0;
214:
215: =head1 NAME
216: lonManage - Command line utility for remote management of lonCAPA
217: cluster nodes.
218:
219: =head1 SYNOPSIS
220:
221: Usage:
222: B<lonManage --push=<tablename> newfile host>
223: Push <tablename> to the lonTabs directory. Note that
224: <tablename> must be one of:
225: hosts (hosts.tab)
226: domain (domain.tab)
227:
228: B<lonManage --reinit=lonc host>
229: Sends a HUP signal to the remote systems's lond.
230:
231: B<lonmanage --reinit=lond host>
232: Requests the remote system's lond perform the same action as if
233: it had received a HUP signal.
234:
235: In the above syntax, the host above is the hosts.tab name of a host,
236: not the IP address of the host.
237:
238:
239: =head1 DESCRIPTION
240:
241: =head1 PREREQUISITES
242:
243: =item Getopt::Long
244:
245: =head1 CATEGORIES
246: Command line utility
247:
248: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>