Changeset 19791
- Timestamp:
- Sep 30, 2008, 2:30:53 PM (18 years ago)
- Location:
- trunk/Nebulous-Server
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Build.PL
r19623 r19791 16 16 'Digest::SHA1' => 0, 17 17 'File::ExtAttr' => '1.03', 18 'File::Mountpoint' => '0.01', 18 19 'File::Path' => '1.08', 19 20 'File::Spec' => 0, -
trunk/Nebulous-Server/Changes
r19790 r19791 5 5 - rename neb-addvol -> neb-voladd 6 6 - add a pid file to neb-admin so only one instance can be run at a time 7 - rework nebdiskd to only record data on volumes it is supposed to be 8 monitoring and then only for paths that actually have volumes mounted on 9 them 7 10 8 11 0.15 Thu Sep 11 13:00:59 HST 2008 -
trunk/Nebulous-Server/bin/nebdiskd
r18416 r19791 3 3 # Copyright (C) 2007 Joshua Hoblitt 4 4 # 5 # $Id: nebdiskd,v 1. 6 2008-07-03 22:01:03 jhoblitt Exp $5 # $Id: nebdiskd,v 1.7 2008-10-01 00:30:53 jhoblitt Exp $ 6 6 7 7 use strict; … … 9 9 10 10 use vars qw( $VERSION ); 11 $VERSION = '0.0 2';11 $VERSION = '0.03'; 12 12 13 13 use Config::YAML; 14 14 use DBI; 15 use File::Mountpoint qw( is_mountpoint ); 15 16 use File::Spec; 16 17 use Nebulous::Server::SQL; … … 74 75 $SIG{HUP} = sub { $c = read_rcfile($rcfile) }; 75 76 76 my $dbh = setup_db(77 db => $db,78 dbhost => $dbhost,79 dbuser => $dbuser,80 dbpass => $dbpass,81 );82 77 83 78 poll_mounts( 84 dbh => $dbh, 79 db => $db, 80 dbhost => $dbhost, 81 dbuser => $dbuser, 82 dbpass => $dbpass, 85 83 poll_interval => $poll_interval, 86 84 debug => $debug, 87 ) or die "poll_mounts() should not have returned";85 ) or die "poll_mounts() should not have returned"; 88 86 89 87 sub poll_mounts … … 91 89 my %p = @_; 92 90 93 my $dbh = $p{dbh} or return; 91 my $db = $p{db} or return; 92 my $dbhost = $p{dbhost} or return; 93 my $dbuser = $p{dbuser} or return; 94 my $dbpass = $p{dbpass} or return; 94 95 my $poll_interval = $p{poll_interval} || 60; 95 96 my $debug = $p{debug} || 0; … … 98 99 99 100 while (1) { 100 # list of mount points to stat so that the automounter will mount these 101 # volumes if they have been unmounted. 102 stat_dirs($mounts); 101 # setup the db on every pass incase the database died on us 102 my $dbh = setup_db( 103 db => $db, 104 dbhost => $dbhost, 105 dbuser => $dbuser, 106 dbpass => $dbpass, 107 ); 103 108 104 109 eval { 110 my @valid_mounts; 111 112 # determine valid mountpoints 113 foreach my $mnt (@$mounts) { 114 print "checking $mnt\n" if $debug; 115 # this /SHOULD/ fail if the mount point is handled by the 116 # automounter and it fails to mount 117 eval { 118 unless (is_mountpoint($mnt)) { 119 print "$mnt is not a valid mountpoint\n" if $debug; 120 next; 121 } 122 }; 123 if ($@) { 124 print "$mnt is not a valid mountpoint\n" if $debug; 125 next; 126 } 127 push @valid_mounts, $mnt; 128 } 129 # empty the mount table 130 $dbh->do("DELETE FROM mount"); 131 print "flushed mount table\n" if $debug; 132 133 # repopulate the mount table with all valid mounts that we are 134 # supposed to be watching 105 135 my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)"); 106 $dbh->do("DELETE FROM mount"); 107 108 print "flushed mount table\n" if $debug; 109 136 # get stats on all currently mounted volumes 137 # this has to be done AFTER we determine what the valid mountpoints 138 # are incase is_mountpoint() invokes the automounter 110 139 my $stats = $lxs->get; 111 foreach my $dev (keys %$stats) { 112 my $mnt = $stats->{$dev}; 113 my %mount; 114 $query->execute(@$mnt{qw( mountpoint total usage )}); 115 print "adding $mnt->{mountpoint} to db\n" if $debug; 140 $stats = fix_disk_stats($stats); 141 142 foreach my $mnt (@valid_mounts) { 143 my $dev_info = $stats->{$mnt}; 144 unless (defined $dev_info) { 145 print "can't find device info for $mnt\n" 146 if $debug; 147 next; 148 } 149 $query->execute(@$dev_info{qw( mountpoint total usage )}); 150 print "adding $dev_info->{mountpoint} to db\n" if $debug; 116 151 } 117 152 … … 119 154 120 155 $dbh->commit; 156 print "commited to database\n" if $debug; 121 157 }; 122 158 if ($@) { 123 $db->rollback; 159 $dbh->rollback; 160 print "rolledback transaction\n" if $debug; 124 161 warn $@; 125 162 } … … 158 195 my $sql = Nebulous::Server::SQL->new; 159 196 160 my $dbh = DBI->connect (197 my $dbh = DBI->connect_cached( 161 198 "DBI:mysql:database=$p{db}:host=$p{dbhost}", 162 199 $p{dbuser}, … … 247 284 } 248 285 } 286 } 287 288 289 sub fix_disk_stats 290 { 291 my $stats = shift; 292 293 # take the hash returned by Sys::Statistics::Linux::DiskUsage->new->get and 294 # replace the keynames with those of the mountpoint for each device 295 my %new_stats; 296 foreach my $key (keys %$stats) { 297 my $disk = $stats->{$key}; 298 $new_stats{$disk->{mountpoint}} = $disk; 299 } 300 301 return \%new_stats; 249 302 } 250 303
Note:
See TracChangeset
for help on using the changeset viewer.
