root/tags/mogilefs-server-2.16/mogautomount

Revision 221, 2.7 kB (checked in by bradfitz, 4 years ago)

pod docs, verbose/help options, return values, copyright/warranty/etc...

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl
2
3use strict;
4use Getopt::Long;
5
6my ($help, $verbose);
7usage(0) unless GetOptions(
8                           'help' => \$help,
9                           'verbose' => \$verbose,
10                           );
11usage(0) if @ARGV;
12usage(2) if $help;
13
14sub usage {
15    my $verbosity = shift;
16    require Pod::Usage;
17    Pod::Usage::pod2usage({
18        -exitval => 1,
19        -verbose => $verbosity,
20    });
21}
22
23my $base = "/var/mogdata";
24my @bdevs = `/sbin/blkid -c /dev/null`;
25die "Failed to run /sbin/blkid to get available block devices." if $?;
26
27my %mounted;  # dev -> 1
28open (M, "/proc/mounts") or die "Failed to open /proc/mounts for reading: $!\n";
29while (<M>) {
30    m!^(\S+) /var/mogdata/dev(\d+)! or next;
31    my $devid = $2;
32    $mounted{$1} = 1;
33    if ($verbose) {
34        warn "Mogile device $devid, $1, is already mounted.\n";
35    }
36}
37
38my $bad_count = 0;
39my $good_count = 0;
40
41foreach my $bdev (@bdevs) {
42    next unless $bdev =~ /^(.+?):.*LABEL="MogileDev(\d+)"/;
43    my ($dev, $devid) = ($1, $2);
44    unless (-d "$base") { mkdir $base or die "Failed to mkdir $base: $!"; }
45    my $mnt = "$base/dev$devid";
46    unless (-d $mnt) { mkdir $mnt or die "Failed to mkdir $mnt: $!"; }
47    next if $mounted{$dev};
48
49    if (system("mount", '-o', 'noatime', $dev, $mnt)) {
50        warn "Failed to mount $dev at $mnt.\n";
51        $bad_count++;
52    } else {
53        warn "Mounted device $devid at $mnt.\n" if $verbose;
54        $good_count++;
55    }
56}
57
58exit 0 if ! $bad_count;
59exit 1 if $good_count;
60exit 2;
61
62__END__
63
64=head1 NAME
65
66mogautomount - automatically discover and mount MogileFS disks
67
68=head1 SYNOPSIS
69
70  mogautomount [--verbose | -v]
71  mogautomount [--help | -h]
72
73=head1 DESCRIPTION
74
75Mounts all unmounted filesystems with labels of form "MogileDev<n>" at
76/var/mogdata/dev<n>, creating the needed directories as well.
77
78You can do this at runtime without restarting mogstored, assuming you
79can add new block devices at runtime via your SCSI/SATA/etc controller.
80
81=head1 OPTIONS
82
83=over
84
85=item --help | -h
86
87this help
88
89=item --verbose | -verbose
90
91be verbose
92
93=back
94
95=head1 RETURN CODE
96
970 on success or inaction because no action needed to happen.
98
991 on partial failure (some mounts succeeed).
100
1012 on total failure (things had to be done, but nothing was).
102
103=head1 AUTHOR
104
105Brad Fitzpatrick, E<lt>brad@danga.comE<gt>
106
107=head1 WARRANTY, BUGS, DISCLAIMER
108
109This tool mounts disks, and disks hold data, so naturally you should
110be afraid.  Real the source code to see what it does.  This tool comes
111with no warranty of any kind.  You're response for its use or misuse.
112
113=head1 COPYRIGHT & LICENSE
114
115This tool is Copyright 2006, Six Apart, Ltd.
116You're free to redistribute it under the same terms as perl itself.
117
118=end
Note: See TracBrowser for help on using the browser.