Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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