Annotation of loncom/clusteradmin, revision 1.1
1.1 ! foxr 1: #!/usr/bin/perl
! 2:
! 3: =pod
! 4:
! 5: =head1 SYNOPSIS
! 6:
! 7: clusteradmin command [args]
! 8:
! 9: =head1 DESCRIPTION
! 10:
! 11: Performs an adiminstrative action on all hosts in the current dns_hosts.tab
! 12: file. For this to work, the current host must be the cluster administrator
! 13: on the target systems. That is this must be a host in managers.tab
! 14: Furthermore, lonc must be running on this system.
! 15:
! 16: The action is specified by the 'command' parameter which may have additional arguments.
! 17:
! 18: All communications with remote clients are made critical so that
! 19: they will eventually happen even if the host we want to talk with
! 20: is dead.
! 21:
! 22:
! 23: =head1 ACTIONS
! 24:
! 25: =over 3
! 26:
! 27: =item help
! 28:
! 29: Outputs a brief description of the actions supported and what they do.
! 30:
! 31: =item update file
! 32:
! 33: Update the contents of an administrative file with the contents of that file
! 34: on this system. 'file' is the name of that file, not the path for example:
! 35:
! 36: clusteradmin update dns_hosts.tab
! 37:
! 38: =back
! 39:
! 40:
! 41: =cut
! 42:
! 43: use strict;
! 44:
! 45:
! 46: #----------------------------------------------------------------------------------
! 47: #
! 48: # Command dispatch handling:
! 49:
! 50: #
! 51: # Dispatch hash for the subcommands.
! 52: # indexed by the subcommand name, each item is
! 53: # a reference to the sub that handles the command:
! 54: #
! 55:
! 56: my %Dispatch;
! 57:
! 58: #
! 59: # Define a subcommand:
! 60: #
! 61: # Parameters:
! 62: # command - subcommand name string
! 63: # handler - reference to the handler sub.
! 64: # Notes:
! 65: # The handler is dispatched to with the tail of the command
! 66: # as an array reference parameter. Suppose the command is
! 67: #
! 68: # clusteradmin update dns_hosts.tab,
! 69: #
! 70: # the array will have a single element: 'dns_hosts.tab'.
! 71: #
! 72: sub define_command {
! 73: my ($command, $handler) = @_;
! 74:
! 75: $Dispatch{$command} = $handler;
! 76: }
! 77:
! 78: #
! 79: # Dispatch to a command:
! 80: # Parameters:
! 81: # command - Name of the command.
! 82: # tail - Reference to the command tail array.
! 83: # Returns:
! 84: # 1 - Success.
! 85: # 0 - Failure
! 86: # Notes:
! 87: # 1. The command handler is assumed to have output any error messages
! 88: # to stderr by now.
! 89: # 2. This function will indicate to stderr if the command isn't in the
! 90: # dispatch hash.
! 91: #
! 92: sub dispatch_command {
! 93: my ($command, $tail) = @_;
! 94: my $sub;
! 95:
! 96: if (exists($Dispatch{$command})) {
! 97: $sub = $Dispatch{$command};
! 98: return $sub->($tail);
! 99: } else {
! 100: print STDERR "Unrecognized subcommand keyword $command\n";
! 101: &usage();
! 102: return 0;
! 103: }
! 104: }
! 105: #-----------------------------------------------------------------------------------
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>