6 # Rename binary in process list to make init scripts saner
9 my ($help, $verbose, $chmod_mountpoints);
10 usage
(0) unless GetOptions
(
12 'verbose' => \
$verbose,
13 'chmod-mountpoints' => \
$chmod_mountpoints,
19 my $verbosity = shift;
21 Pod
::Usage
::pod2usage
({
23 -verbose
=> $verbosity,
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 $?
;
31 my %mounted; # dev -> 1
32 open (M
, "/proc/mounts") or die "Failed to open /proc/mounts for reading: $!\n";
34 m!^(\S+) /var/mogdata/dev(\d+)! or next;
38 warn "Mogile device $devid, $1, is already mounted.\n";
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};
53 if ($chmod_mountpoints and ((stat($mnt))[2] & 0777) != 0) {
54 warn "Mountpoint on parent filesystem is writable, fixing.\n" if $verbose;
56 or die "Unable to set mogile device mountpoint '$mnt' mode to 0 (no access)";
59 if (system("mount", '-o', 'noatime', $dev, $mnt)) {
60 warn "Failed to mount $dev at $mnt.\n";
63 warn "Mounted device $devid at $mnt.\n" if $verbose;
68 exit 0 if ! $bad_count;
69 exit 1 if $good_count;
76 mogautomount - automatically discover and mount MogileFS disks
80 mogautomount [--verbose | -v]
81 mogautomount [--help | -h]
85 Mounts all unmounted filesystems with labels of form "MogileDev<n>" at
86 /var/mogdata/dev<n>, creating the needed directories as well.
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.
99 =item --verbose | -verbose
103 =item --chmod-mountpoints
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.
113 0 on success or inaction because no action needed to happen.
115 1 on partial failure (some mounts succeed).
117 2 on total failure (things had to be done, but nothing was).
121 Brad Fitzpatrick, E<lt>brad@danga.comE<gt>
123 =head1 WARRANTY, BUGS, DISCLAIMER
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.
129 =head1 COPYRIGHT & LICENSE
131 This tool is Copyright 2006, Six Apart, Ltd.
132 You're free to redistribute it under the same terms as perl itself.