Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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