Changeset 24540 for trunk/Nebulous-Server/bin/nebdiskd
- Timestamp:
- Jun 24, 2009, 12:50:43 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous-Server/bin/nebdiskd (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/bin/nebdiskd
r24539 r24540 37 37 38 38 GetOptions( 39 'dbhost| h=s' => \$dbhost,39 'dbhost|H=s' => \$dbhost, 40 40 'dbpass|p=s' => \$dbpass, 41 41 'dbuser|u=s' => \$dbuser, … … 47 47 'retry=i' => \$retry, 48 48 'stop|s' => \$stop, 49 'user =s'=> \$user,49 'user|U=s' => \$user, 50 50 'verbose|v' => \$verbose, 51 51 ) || pod2usage( 2 ); … … 61 61 $dbhost ||= $c->get_dbhost || $ENV{'NEB_DBHOST'} || 'localhost'; 62 62 $dbuser ||= $c->get_dbuser || $ENV{'NEB_USER'}; 63 $dbpass ||= $c->get_dbpass || $ENV{'NEB_PASS'} ;63 $dbpass ||= $c->get_dbpass || $ENV{'NEB_PASS'} || undef; 64 64 $pidfile ||= $c->get_pidfile || "/var/tmp/nebdiskd"; 65 65 $user ||= $c->get_user || $<; # user … … 85 85 86 86 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 87 pod2usage( -msg => "Required options: --db -- user --pass", -exitval => 2 )88 unless $db && $dbuser && $dbpass;87 pod2usage( -msg => "Required options: --db --dbuser", -exitval => 2 ) 88 unless $db && $dbuser; 89 89 90 90 # start up logging … … 111 111 log4perl.appender.Mailer.subject = nebdiskd alert 112 112 log4perl.appender.Mailer.buffered = 0 113 log4perl.appender. AppError.Filter= MatchWarn113 log4perl.appender.Mailer.Filter= MatchWarn 114 114 log4perl.appender.Mailer.layout = Log::Log4perl::Layout::PatternLayout 115 115 log4perl.appender.Mailer.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n … … 163 163 my $dbhost = $p{dbhost} or return; 164 164 my $dbuser = $p{dbuser} or return; 165 my $dbpass = $p{dbpass} or return;165 # my $dbpass = $p{dbpass} or return; 166 166 my $poll_interval = $p{poll_interval} || 60; 167 167 my $debug = $p{debug} || 0; … … 177 177 178 178 eval { 179 my $r_query = $dbh->prepare_cached("REPLACE INTO mount VALUES(?, ?, ?)");180 my $d_query = $dbh->prepare_cached("DELETE FROM mount , mountedvol WHERE mountpoint = ?");179 my $r_query = $dbh->prepare_cached("REPLACE INTO mountedvol SELECT *, ?, ? FROM volume WHERE mountpoint = ?"); 180 my $d_query = $dbh->prepare_cached("DELETE FROM mountedvol WHERE mountpoint = ?"); 181 181 182 182 # get list of mount points 183 183 my $mounts = []; 184 184 { 185 my $query = $dbh->prepared_cached("SELECT mountpoint FROM volume"); 185 # there may be multiple vol_ids per mountpoint but we only need to 186 # check each mointpont once 187 my $query = $dbh->prepare_cached("SELECT DISTINCT mountpoint FROM volume"); 186 188 $query->execute; 187 189 while (my $row = $query->fetchrow_hashref) { 188 push @$mounts, $row ->{'mountpoint'};190 push @$mounts, $row; 189 191 } 190 192 $query->finish; … … 193 195 # determine valid mountpoints 194 196 foreach my $mnt (@$mounts) { 195 $log->debug("checking $mnt"); 197 my $mountpoint = $mnt->{'mountpoint'}; 198 $log->debug("checking $mountpoint"); 196 199 # this /SHOULD/ fail if the mount point is handled by the 197 200 # automounter and it fails to mount … … 199 202 TEST: eval { 200 203 $tries++; 201 unless (is_mountpoint($m nt)) {204 unless (is_mountpoint($mountpoint)) { 202 205 $log->warn("$mnt is not a valid mountpoint"); 203 206 } … … 206 209 # try is_mountpoint() again if $retry > 1 207 210 if ($tries < $retry) { 208 $log->warn("retrying test of $m nt");211 $log->warn("retrying test of $mountpoint"); 209 212 goto TEST; 210 213 } 211 214 $log->warn($@); 212 $d_query->execute($m nt);215 $d_query->execute($mountpoint); 213 216 next; 214 217 } … … 217 220 # we determine if it's a valid mountpoint incase 218 221 # is_mountpoint() invokes the automounter 219 my $dev_info = df($m nt, 1024);222 my $dev_info = df($mountpoint, 1024); 220 223 unless (defined $dev_info) { 221 $log->error("can't find device info for $m nt");224 $log->error("can't find device info for $mountpoint"); 222 225 next; 223 226 } 224 227 225 228 # find vol_id(s) for mountpoint 226 $r_query->execute( $mnt, @$dev_info{qw( blocks used )});227 $log->debug("adding $m nt to db");229 $r_query->execute(@$dev_info{qw( blocks used )}, $mountpoint); 230 $log->debug("adding $mountpoint to db"); 228 231 229 232 } 230 233 231 $dbh->do("call getmountedvol()");234 # $dbh->do("call getmountedvol()"); 232 235 233 236 $dbh->commit; … … 263 266 my %p = @_; 264 267 268 # $p{dbpass} may be undef; 269 265 270 return unless defined $p{db} 266 271 and defined $p{dbhost} 267 and defined $p{dbuser} 268 and defined $p{dbpass}; 272 and defined $p{dbuser}; 269 273 270 274 my $sql = Nebulous::Server::SQL->new; … … 372 376 =head1 SYNOPSIS 373 377 374 nebdiskd [--db <db name>] [--user <db username>] [--pass <db password>] [--debug] [--pidfile <filename>] [--stop] [--restart] [--verbose] 378 nebdiskd [--db|-D <db name>] [--dbhost|-H <db hostname> 379 [--dbuser|-u <db username>] [--dbpass|-p <db password>] [--debug|-d] 380 [--user|-U <username>] [--group|-g <groupname>] [--pidfile <filename>] 381 [--retry <n>] [--stop|-s] [--restart|-r] [--verbose|-v] 375 382 376 383 =head1 DESCRIPTION … … 383 390 =over 4 384 391 385 =item * --db|- d<db name>392 =item * --db|-D <db name> 386 393 387 394 Name of database (C<namespace>) to write too. … … 390 397 variable is set. 391 398 392 =item * -- user|-u <dbusername>399 =item * --dbuser|-u <username> 393 400 394 401 Username to authenticate with. … … 397 404 variable is set. 398 405 399 =item * -- pass|-p <dbpassword>406 =item * --dbpass|-p <password> 400 407 401 408 Password to authenticate with. 409 410 Optional if defined in the F<.nebdiskdrc> file or the appropriate environment 411 variable is set or if the database does not require a password. 412 413 =item * --dbhost|-H <hostname> 414 415 Database host to connect to. 402 416 403 417 Optional if defined in the F<.nebdiskdrc> file or the appropriate environment 404 418 variable is set. 405 419 406 =item * --debug 420 =item * --debug|-d 407 421 408 422 This flag prevents the program from "daemonizing" so output can be sent to … … 425 439 instance. 426 440 427 =item * --verbose|-r 441 =item * --retry 442 443 The number of times to test a mountpoint for "mountedness" before giving up on 444 it. 445 446 =item * --verbose|-v 428 447 429 448 Turns on informational/debugging messages to be sent to the … … 431 450 with C<--debug>. 432 451 452 =item * --user|-U 453 454 user account to run daemon as. 455 456 =item * --group|-g 457 458 group to run daemon as. 459 433 460 =back 434 461 … … 443 470 =item * C<NEB_DB> 444 471 445 Equivalent to --db|- d472 Equivalent to --db|-D 446 473 447 474 =item * C<NEB_USER> 448 475 449 Equivalent to -- user|-u476 Equivalent to --dbuser|-u 450 477 451 478 =item * C<NEB_PASS> 452 479 453 Equivalent to -- pass|-p480 Equivalent to --dbpass|-p 454 481 455 482 =back … … 467 494 dbpass: '@neb@' 468 495 dbuser: nebulous 469 mounts:470 - /mnt471 - /tmp472 - /usr473 496 pidfile: /var/tmp/nebdiskd 474 497 poll_interval: 5 … … 480 503 =over 4 481 504 482 =item * C<mounts>483 484 A list of "paths" to C<stat(2)> before mounted volumes are polled. The propose485 of this option is to attempt to keep "automounted" volumes mounted while this486 program is running.487 488 505 This value may be omitted or left blank. 489 506 … … 493 510 494 511 This value may be omitted or left blank. The default value is C<60>s. 512 513 =item * C<retry> 514 515 Same as C<--retry>. 495 516 496 517 =back
Note:
See TracChangeset
for help on using the changeset viewer.
