IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 24, 2009, 12:50:43 PM (17 years ago)
Author:
jhoblitt
Message:

nebdiskd bug fixes: fix debug mode outpoint going to mail, remove db passwd requirement (not all dbs require a password param)
completely rework how mountedvol is populated, drop mount table

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/bin/nebdiskd

    r24539 r24540  
    3737
    3838GetOptions(
    39     'dbhost|h=s'    => \$dbhost,
     39    'dbhost|H=s'    => \$dbhost,
    4040    'dbpass|p=s'    => \$dbpass,
    4141    'dbuser|u=s'    => \$dbuser,
     
    4747    'retry=i'       => \$retry,
    4848    'stop|s'        => \$stop,
    49     'user=s'        => \$user,
     49    'user|U=s'      => \$user,
    5050    'verbose|v'     => \$verbose,
    5151) || pod2usage( 2 );
     
    6161$dbhost     ||= $c->get_dbhost  || $ENV{'NEB_DBHOST'} || 'localhost';
    6262$dbuser     ||= $c->get_dbuser  || $ENV{'NEB_USER'};
    63 $dbpass     ||= $c->get_dbpass  || $ENV{'NEB_PASS'};
     63$dbpass     ||= $c->get_dbpass  || $ENV{'NEB_PASS'} || undef;
    6464$pidfile    ||= $c->get_pidfile || "/var/tmp/nebdiskd";
    6565$user       ||= $c->get_user    || $<; # user
     
    8585
    8686pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    87 pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 )
    88     unless $db && $dbuser && $dbpass;
     87pod2usage( -msg => "Required options: --db --dbuser", -exitval => 2 )
     88    unless $db && $dbuser;
    8989
    9090# start up logging
     
    111111    log4perl.appender.Mailer.subject = nebdiskd alert
    112112    log4perl.appender.Mailer.buffered = 0
    113     log4perl.appender.AppError.Filter= MatchWarn
     113    log4perl.appender.Mailer.Filter= MatchWarn
    114114    log4perl.appender.Mailer.layout = Log::Log4perl::Layout::PatternLayout
    115115    log4perl.appender.Mailer.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n
     
    163163    my $dbhost          = $p{dbhost} or return;
    164164    my $dbuser          = $p{dbuser} or return;
    165     my $dbpass          = $p{dbpass} or return;
     165#    my $dbpass          = $p{dbpass} or return;
    166166    my $poll_interval   = $p{poll_interval} || 60;
    167167    my $debug           = $p{debug} || 0;
     
    177177
    178178    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 = ?");
    181181
    182182        # get list of mount points
    183183        my $mounts = [];
    184184        {
    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");
    186188            $query->execute;
    187189            while (my $row = $query->fetchrow_hashref) {
    188                 push @$mounts, $row->{'mountpoint'};
     190                push @$mounts, $row;
    189191            }
    190192            $query->finish;
     
    193195        # determine valid mountpoints
    194196        foreach my $mnt (@$mounts) {
    195             $log->debug("checking $mnt");
     197            my $mountpoint = $mnt->{'mountpoint'};
     198            $log->debug("checking $mountpoint");
    196199            # this /SHOULD/ fail if the mount point is handled by the
    197200            # automounter and it fails to mount
     
    199202            TEST: eval {
    200203                $tries++;
    201                 unless (is_mountpoint($mnt)) {
     204                unless (is_mountpoint($mountpoint)) {
    202205                    $log->warn("$mnt is not a valid mountpoint");
    203206                }
     
    206209                # try is_mountpoint() again if $retry > 1
    207210                if ($tries < $retry) {
    208                     $log->warn("retrying test of $mnt");
     211                    $log->warn("retrying test of $mountpoint");
    209212                    goto TEST;
    210213                }
    211214                $log->warn($@);
    212                 $d_query->execute($mnt);
     215                $d_query->execute($mountpoint);
    213216                next;
    214217            }
     
    217220            # we determine if it's a valid mountpoint incase
    218221            # is_mountpoint() invokes the automounter
    219             my $dev_info = df($mnt, 1024);
     222            my $dev_info = df($mountpoint, 1024);
    220223            unless (defined $dev_info) {
    221                 $log->error("can't find device info for $mnt");
     224                $log->error("can't find device info for $mountpoint");
    222225                next;
    223226            }
    224227
    225228            # find vol_id(s) for mountpoint
    226             $r_query->execute($mnt, @$dev_info{qw( blocks used )});
    227             $log->debug("adding $mnt to db");
     229            $r_query->execute(@$dev_info{qw( blocks used )}, $mountpoint);
     230            $log->debug("adding $mountpoint to db");
    228231
    229232        }
    230233
    231         $dbh->do("call getmountedvol()");
     234#        $dbh->do("call getmountedvol()");
    232235
    233236        $dbh->commit;
     
    263266    my %p = @_;
    264267
     268    # $p{dbpass} may be undef;
     269
    265270    return unless defined $p{db}
    266271              and defined $p{dbhost}
    267               and defined $p{dbuser}
    268               and defined $p{dbpass};
     272              and defined $p{dbuser};
    269273
    270274    my $sql = Nebulous::Server::SQL->new;
     
    372376=head1 SYNOPSIS
    373377
    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]
    375382
    376383=head1 DESCRIPTION
     
    383390=over 4
    384391
    385 =item * --db|-d <db name>
     392=item * --db|-D <db name>
    386393
    387394Name of database (C<namespace>) to write too.
     
    390397variable is set.
    391398
    392 =item * --user|-u <db username>
     399=item * --dbuser|-u <username>
    393400
    394401Username to authenticate with.
     
    397404variable is set.
    398405
    399 =item * --pass|-p <db password>
     406=item * --dbpass|-p <password>
    400407
    401408Password to authenticate with.
     409
     410Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
     411variable is set or if the database does not require a password.
     412
     413=item * --dbhost|-H <hostname>
     414
     415Database host to connect to.
    402416
    403417Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
    404418variable is set.
    405419
    406 =item * --debug
     420=item * --debug|-d
    407421
    408422This flag prevents the program from "daemonizing" so output can be sent to
     
    425439instance.
    426440
    427 =item * --verbose|-r
     441=item * --retry
     442
     443The number of times to test a mountpoint for "mountedness" before giving up on
     444it.
     445
     446=item * --verbose|-v
    428447
    429448Turns on informational/debugging messages to be sent to the
     
    431450with C<--debug>.
    432451
     452=item * --user|-U
     453
     454user account to run daemon as.
     455
     456=item * --group|-g
     457
     458group to run daemon as.
     459
    433460=back
    434461
     
    443470=item * C<NEB_DB>
    444471
    445 Equivalent to --db|-d
     472Equivalent to --db|-D
    446473
    447474=item * C<NEB_USER>
    448475
    449 Equivalent to --user|-u
     476Equivalent to --dbuser|-u
    450477
    451478=item * C<NEB_PASS>
    452479
    453 Equivalent to --pass|-p
     480Equivalent to --dbpass|-p
    454481
    455482=back
     
    467494    dbpass: '@neb@'
    468495    dbuser: nebulous
    469     mounts:
    470       - /mnt
    471       - /tmp
    472       - /usr
    473496    pidfile: /var/tmp/nebdiskd
    474497    poll_interval: 5
     
    480503=over 4
    481504
    482 =item * C<mounts>
    483 
    484 A list of "paths" to C<stat(2)> before mounted volumes are polled.  The propose
    485 of this option is to attempt to keep "automounted" volumes mounted while this
    486 program is running.
    487 
    488505This value may be omitted or left blank.
    489506
     
    493510
    494511This value may be omitted or left blank.  The default value is C<60>s.
     512
     513=item * C<retry>
     514
     515Same as C<--retry>.
    495516
    496517=back
Note: See TracChangeset for help on using the changeset viewer.