MogileFS::Utils - Command line utilities for the MogileFS distributed file system.


MogileFS-Utils documentation Contained in the MogileFS-Utils distribution.

Index


Code Index:

NAME

Top

MogileFS::Utils - Command line utilities for the MogileFS distributed file system.

SYNOPSIS

Top

mogadm

mogstats

mogupload

mogfetch

mogdelete

mogfileinfo

moglistkeys

moglistfids

mogfiledebug

mogtool (DEPRECATED: Do not use!)

SUMMARY

Top

Please refer to the documentation for the tools included in this distribution.

CONFIGURATION FILE

Top

Most of the utilities in this package support a configuration file. Common options can be pushed into the config file, such as trackers, domain, or class. The file is in /etc/mogilefs/mogilefs.conf and ~/.mogilefs.conf by default. You may also specify a configuration via --conf=filename

Example:

    trackers = 10.0.0.1:7001,10.0.0.3:7001
    domain = foo

AUTHOR

Top

Brad Fitzpatrick <brad@danga.com>

Dormando <dormando@rydia.net>

BUGS

Top

Please report any on the MogileFS mailing list: http://groups.google.com/group/mogile/.

LICENSE

Top

Licensed for use and redistribution under the same terms as Perl itself.


MogileFS-Utils documentation Contained in the MogileFS-Utils distribution.

#!/usr/bin/perl
package MogileFS::Utils;

our $VERSION = '2.20';

use Getopt::Long;
use MogileFS::Client;

use fields (
            'config'
           );

# Helper object for the individual utilities.
sub new {
    my MogileFS::Utils $self = shift;
    $self = fields::new($self) unless ref $self;
    $self->_init(@_);

    return $self;
}

# Predefine some options via configuration.
sub _init {
    my MogileFS::Utils $self = shift;

    $self->{config} = {};
}

sub _readconf {
    my MogileFS::Utils $self = shift;
    my $args = shift;

    # Liftedish from mogadm, but we can refactor mogadm to use this instead.
    my @configs = ($args->{conf}, $ENV{MOGUTILSCONF},
        "$ENV{HOME}/.mogilefs.conf",
        "/etc/mogilefs/mogilefs.conf");
    my %opts = ();
    for my $fn (reverse @configs) {
        next unless $fn && -e $fn;
        open my $file, "<$fn"
            or die "unable to open $fn: $!";
        while (<$file>) {
            s/\#.*//;
            next unless m/^\s*(\w+)\s*=\s*(.+?)\s*$/;
            $opts{$1} = $2 unless ( defined $opts{$1} );
        }
        close $file;
    }

    return \%opts;
}

sub config {
    my MogileFS::Utils $self = shift;
    return $self->{config};
}

sub getopts {
    my MogileFS::Utils $self = shift;
    my $usage = shift;
    my @want  = @_;

    my %opts = ();
    $self->abort_usage($usage) unless @ARGV;
    GetOptions(\%opts, @want, qw/help trackers=s domain=s conf=s/)
        or $self->abort_usage($usage);
    my $config = $self->_readconf(\%opts);

    $self->{config} = {%$config, %opts};
    $self->_verify_config;
    $self->abort_usage($usage) if $self->{config}->{help};
    
    return $self->{config};
}

sub _verify_config {
    my MogileFS::Utils $self = shift;
    my $conf = $self->{config};

    while (my ($k, $v) = each %$conf) {
        if ($k =~ m/^trackers/) {
            my @tr = split /,/, $v;
            for (@tr) {
                # Client is obnoxious about requiring a port.
                if ($_ !~ m/:\d+/) {
                    $_ = $_ . ':7001';
                }
            }
            $conf->{$k} = \@tr;
        } elsif ($k =~ m/class/) {
            # "" means "default". Might have to remove this if people have
            # been adding "default" classes, which I don't think is possible?
            if ($v eq 'default') {
                $conf->{$k} = '';
            }
        }
    }
}

# Do we want to be fancier here?
sub abort_usage {
    my MogileFS::Utils $self = shift;
    my $usage = shift;
    print "Usage: $0 $usage\n";
    exit;
}

sub client {
    my MogileFS::Utils $self = shift;
    my $c = $self->{config};
    return MogileFS::Client->new(domain => $c->{domain},
        hosts => $c->{trackers});
}

1;