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.5 2003/08/12 10:55:42 foxr Exp $
7: #
8: # $Id: lonManage,v 1.5 2003/08/12 10:55:42 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.5 2003/08/12 10:55:42 foxr
54: # Complete command line parsing (tested)
55: #
56: # Revision 1.4 2003/08/12 10:40:44 foxr
57: # Get switch parsing right.
58: #
59: # Revision 1.3 2003/08/12 10:22:35 foxr
60: # Put in parameter parsing infrastructure
61: #
62: # Revision 1.2 2003/08/12 09:58:49 foxr
63: # Add usage and skeleton documentation.
64: #
65: #
66: use Getopt::Long;
67:
68: sub Usage {
69: print "Usage:";
70: print <<USAGE;
71: lonManage --push=<tablename> newfile host
72: Push <tablename> to the lonTabs directory. Note that
73: <tablename> must be one of:
74: hosts (hosts.tab)
75: domain (domain.tab)
76:
77: lonManage --reinit=lonc host
78: Sends a HUP signal to the remote systems's lond.
79:
80: lonmanage --reinit=lond host
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: #
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.
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: #
111: # returns an empty list if the parse fails.
112: #
113:
114: sub ParseArgs {
115: my $pushing = '';
116: my $reiniting = '';
117:
118: if(!GetOptions('push=s' => \$pushing,
119: 'reinit=s' => \$reinitting)) {
120: return ();
121: }
122:
123: # Require exactly one of --push and --reinit
124:
125: my $command = '';
126: my $commandarg = '';
127: my $paramcount = @ARGV; # Number of additional arguments.
128:
129:
130: if($pushing ne '') {
131:
132: # --push takes in addition a table, and a host:
133: #
134: if($paramcount != 2) {
135: print "Bad count $paramcount\n";
136: return (); # Invalid parameter count.
137: }
138: if($command ne '') {
139: return ();
140: } else {
141:
142: $command = 'push';
143: $commandarg = $pushing;
144: }
145: }
146:
147: if ($reinitting ne '') {
148:
149: # --reinit takes in addition just a host name
150:
151: if($paramcount != 1) {
152: print "Bad count $paramcount\n";
153: return ();
154: }
155: if($command ne '') {
156: return ();
157: } else {
158: $command = 'reinit';
159: $commandarg = $reinitting;
160: }
161: }
162:
163: # Build the result list:
164:
165: my @result = ($command, $commandarg);
166: my $i;
167: for($i = 0; $i < $paramcount; $i++) {
168: push(@result, $ARGV[$i]);
169: }
170:
171: return @result;
172: }
173:
174: #
175: # If command parsing failed, then print usage:
176:
177: @status = ParseArgs;
178: $nparam = @status;
179:
180: if($nparam == 0) {
181: Usage;
182: exit -1;
183: }
184:
185: print "---- params ---\n";
186: for($i = 0; $i < $nparam; $i++) {
187: print "Param[$i] = $status[$i]\n";
188: }
189:
190: exit 0;
191:
192: =head1 NAME
193: lonManage - Command line utility for remote management of lonCAPA
194: cluster nodes.
195:
196: =head1 SYNOPSIS
197:
198: Usage:
199: B<lonManage --push=<tablename> newfile host>
200: Push <tablename> to the lonTabs directory. Note that
201: <tablename> must be one of:
202: hosts (hosts.tab)
203: domain (domain.tab)
204:
205: B<lonManage --reinit=lonc host>
206: Sends a HUP signal to the remote systems's lond.
207:
208: B<lonmanage --reinit=lond host>
209: Requests the remote system's lond perform the same action as if
210: it had received a HUP signal.
211:
212: In the above syntax, the host above is the hosts.tab name of a host,
213: not the IP address of the host.
214:
215:
216: =head1 DESCRIPTION
217:
218: =head1 PREREQUISITES
219:
220: =item Getopt::Long
221:
222: =head1 CATEGORIES
223: Command line utility
224:
225: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>