2 package MogileFS
::Utils
;
13 # Helper object for the individual utilities.
15 my MogileFS
::Utils
$self = shift;
16 $self = fields
::new
($self) unless ref $self;
22 # Predefine some options via configuration.
24 my MogileFS
::Utils
$self = shift;
30 my MogileFS
::Utils
$self = shift;
33 # Liftedish from mogadm, but we can refactor mogadm to use this instead.
34 my @configs = ($args->{conf
}, $ENV{MOGUTILSCONF
},
35 "$ENV{HOME}/.mogilefs.conf",
36 "/etc/mogilefs/mogilefs.conf");
38 for my $fn (reverse @configs) {
39 next unless $fn && -e
$fn;
41 or die "unable to open $fn: $!";
44 next unless m/^\s*(\w+)\s*=\s*(.+?)\s*$/;
45 $opts{$1} = $2 unless ( defined $opts{$1} );
54 my MogileFS
::Utils
$self = shift;
55 return $self->{config
};
59 my MogileFS
::Utils
$self = shift;
64 $self->abort_usage($usage) unless @ARGV;
65 GetOptions
(\
%opts, @want, qw
/help trackers=s domain=s conf=s/)
66 or $self->abort_usage($usage);
67 my $config = $self->_readconf(\
%opts);
69 $self->{config
} = {%$config, %opts};
70 $self->_verify_config;
71 $self->abort_usage($usage) if $self->{config
}->{help
};
73 return $self->{config
};
77 my MogileFS
::Utils
$self = shift;
78 my $conf = $self->{config
};
80 while (my ($k, $v) = each %$conf) {
81 if ($k =~ m/^trackers/) {
82 my @tr = split /,/, $v;
84 # Client is obnoxious about requiring a port.
90 } elsif ($k =~ m/class/) {
91 # "" means "default". Might have to remove this if people have
92 # been adding "default" classes, which I don't think is possible?
93 if ($v eq 'default') {
100 # Do we want to be fancier here?
102 my MogileFS
::Utils
$self = shift;
104 print "Usage: $0 $usage\n";
109 my MogileFS
::Utils
$self = shift;
110 my $c = $self->{config
};
111 return MogileFS
::Client
->new(domain
=> $c->{domain
},
112 hosts
=> $c->{trackers
});
117 MogileFS::Utils - Command line utilities for the MogileFS distributed file system.
139 L<mogtool> (DEPRECATED: Do not use!)
143 Please refer to the documentation for the tools included in this distribution.
145 =head1 CONFIGURATION FILE
147 Most of the utilities in this package support a configuration file. Common
148 options can be pushed into the config file, such as trackers, domain, or
149 class. The file is in B</etc/mogilefs/mogilefs.conf> and B<~/.mogilefs.conf>
150 by default. You may also specify a configuration via B<--conf=filename>
154 trackers = 10.0.0.1:7001,10.0.0.3:7001
159 Brad Fitzpatrick E<lt>L<brad@danga.com>E<gt>
161 Dormando E<lt>L<dormando@rydia.net>E<gt>
165 Please report any on the MogileFS mailing list: L<http://groups.google.com/group/mogile/>.
169 Licensed for use and redistribution under the same terms as Perl itself.