IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/Nebulous-Server

  • branches/pap/Nebulous-Server/bin/nebdiskd

    r23675 r25027  
    11#!/usr/bin/env perl
    22
    3 # Copyright (C) 2007  Joshua Hoblitt
    4 #
    5 # $Id: nebdiskd,v 1.14 2008-10-16 22:51:34 jhoblitt Exp $
     3# Copyright (C) 2007-2009  Joshua Hoblitt
    64
    75use strict;
     
    3533    $user,
    3634    $group,
     35    $retry,
    3736);
    3837
    3938GetOptions(
    40     'dbhost|h=s'    => \$dbhost,
     39    'dbhost|H=s'    => \$dbhost,
    4140    'dbpass|p=s'    => \$dbpass,
    4241    'dbuser|u=s'    => \$dbuser,
     
    4645    'pidfile=s'     => \$pidfile,
    4746    'restart|r'     => \$restart,
     47    '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
    6666$group      ||= $c->get_group   || $); # group
    67 
    68 my $mounts = $c->get_mounts;
     67$retry      ||= $c->get_retry   || 1;
     68
     69#my $mounts = $c->get_mounts;
    6970my $poll_interval = $c->get_poll_interval || 5;
    7071
     
    8081$c->set_pidfile($pidfile);
    8182$c->set_poll_interval($poll_interval);
     83$c->set_retry($retry);
    8284$c->write;
    8385
    8486pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    85 pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 )
    86     unless $db && $dbuser && $dbpass;
     87pod2usage( -msg => "Required options: --db --dbuser", -exitval => 2 )
     88    unless $db && $dbuser;
    8789
    8890# start up logging
     
    108110    log4perl.appender.Mailer.to      = ps-ipp-ops@ifa.hawaii.edu
    109111    log4perl.appender.Mailer.subject = nebdiskd alert
    110     log4perl.appender.AppError.Filter= MatchWarn
     112    log4perl.appender.Mailer.buffered = 0
     113    log4perl.appender.Mailer.Filter= MatchWarn
    111114    log4perl.appender.Mailer.layout = Log::Log4perl::Layout::PatternLayout
    112115    log4perl.appender.Mailer.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n
     116
     117    log4perl.appender.Limiter              = Log::Log4perl::Appender::Limit
     118    log4perl.appender.Limiter.appender     = Mailer
     119    log4perl.appender.Limiter.block_period = 300
    113120';
    114121Log::Log4perl::init(\$conf);
     
    136143                poll_interval   => $poll_interval,
    137144                debug           => $debug,
     145                retry           => $retry,
    138146        );
    139147    };
     
    155163    my $dbhost          = $p{dbhost} or return;
    156164    my $dbuser          = $p{dbuser} or return;
    157     my $dbpass          = $p{dbpass} or return;
     165#    my $dbpass          = $p{dbpass} or return;
    158166    my $poll_interval   = $p{poll_interval} || 60;
    159167    my $debug           = $p{debug} || 0;
     168    my $retry           = $p{retry} || 1;
    160169
    161170    # setup the db on every pass incase the database died on us
     
    168177
    169178    eval {
    170         my $r_query = $dbh->prepare_cached("REPLACE INTO mount VALUES(?, ?, ?)");
    171         my $d_query = $dbh->prepare_cached("DELETE FROM mount WHERE mountpoint = ?");
    172 
     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
     182        # get list of mount points
     183        my $mounts = [];
     184        {
     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 WHERE available = 1");
     188            $query->execute;
     189            while (my $row = $query->fetchrow_hashref) {
     190                push @$mounts, $row;
     191            }
     192            $query->finish;
     193        }
     194       
    173195        # determine valid mountpoints
    174196        foreach my $mnt (@$mounts) {
    175             $log->debug("checking $mnt");
     197            my $mountpoint = $mnt->{'mountpoint'};
     198            $log->debug("checking $mountpoint");
    176199            # this /SHOULD/ fail if the mount point is handled by the
    177200            # automounter and it fails to mount
    178             eval {
    179                 unless (is_mountpoint($mnt)) {
     201            my $tries = 0;
     202            TEST: eval {
     203                $tries++;
     204                unless (is_mountpoint($mountpoint)) {
    180205                    $log->warn("$mnt is not a valid mountpoint");
    181206                }
    182207            };
    183208            if ($@) {
     209                # try is_mountpoint() again if $retry > 1
     210                if ($tries < $retry) {
     211                    $log->warn("retrying test of $mountpoint");
     212                    goto TEST;
     213                }
    184214                $log->warn($@);
    185                 $d_query->execute($mnt);
     215                $d_query->execute($mountpoint);
    186216                next;
    187217            }
     
    190220            # we determine if it's a valid mountpoint incase
    191221            # is_mountpoint() invokes the automounter
    192             my $dev_info = df($mnt, 1024);
     222            my $dev_info = df($mountpoint, 1024);
    193223            unless (defined $dev_info) {
    194                 $log->error("can't find device info for $mnt");
     224                $log->error("can't find device info for $mountpoint");
    195225                next;
    196226            }
    197227
    198             $r_query->execute($mnt, @$dev_info{qw( blocks used )});
    199             $log->debug("adding $mnt to db");
     228            # find vol_id(s) for mountpoint
     229            $r_query->execute(@$dev_info{qw( blocks used )}, $mountpoint);
     230            $log->debug("adding $mountpoint to db");
    200231
    201232        }
    202233
    203         $dbh->do("call getmountedvol()");
    204 
    205         $dbh->commit;
    206         $log->debug("commited to database");
     234#        $dbh->do("call getmountedvol()");
     235
     236#        $dbh->commit;
     237#        $log->debug("commited to database");
    207238    };
    208239    if ($@) {
    209         $dbh->rollback;
    210         $log->debug("rolledback transaction");
     240#        $dbh->rollback;
     241#        $log->debug("rolledback transaction");
    211242        $log->logdie($@);
    212243    }
     
    235266    my %p = @_;
    236267
     268    # $p{dbpass} may be undef;
     269
    237270    return unless defined $p{db}
    238271              and defined $p{dbhost}
    239               and defined $p{dbuser}
    240               and defined $p{dbpass};
     272              and defined $p{dbuser};
    241273
    242274    my $sql = Nebulous::Server::SQL->new;
     
    249281            RaiseError => 1,
    250282            PrintError => 1,
    251             AutoCommit => 0,
     283            AutoCommit => 1, # don't want this to be trasnactional
    252284        },
    253285    );
     
    255287    eval {
    256288        $dbh->do( $sql->set_transaction_model );
    257         $dbh->commit;
     289#        $dbh->commit;
    258290    };
    259291    if ($@) {
    260         $dbh->rollback;
     292#        $dbh->rollback;
    261293        $log->logdie($@);
    262294    }
     
    344376=head1 SYNOPSIS
    345377
    346     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]
    347382
    348383=head1 DESCRIPTION
     
    355390=over 4
    356391
    357 =item * --db|-d <db name>
     392=item * --db|-D <db name>
    358393
    359394Name of database (C<namespace>) to write too.
     
    362397variable is set.
    363398
    364 =item * --user|-u <db username>
     399=item * --dbuser|-u <username>
    365400
    366401Username to authenticate with.
     
    369404variable is set.
    370405
    371 =item * --pass|-p <db password>
     406=item * --dbpass|-p <password>
    372407
    373408Password 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.
    374416
    375417Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
    376418variable is set.
    377419
    378 =item * --debug
     420=item * --debug|-d
    379421
    380422This flag prevents the program from "daemonizing" so output can be sent to
     
    397439instance.
    398440
    399 =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
    400447
    401448Turns on informational/debugging messages to be sent to the
     
    403450with C<--debug>.
    404451
     452=item * --user|-U
     453
     454user account to run daemon as.
     455
     456=item * --group|-g
     457
     458group to run daemon as.
     459
    405460=back
    406461
     
    415470=item * C<NEB_DB>
    416471
    417 Equivalent to --db|-d
     472Equivalent to --db|-D
    418473
    419474=item * C<NEB_USER>
    420475
    421 Equivalent to --user|-u
     476Equivalent to --dbuser|-u
    422477
    423478=item * C<NEB_PASS>
    424479
    425 Equivalent to --pass|-p
     480Equivalent to --dbpass|-p
    426481
    427482=back
     
    439494    dbpass: '@neb@'
    440495    dbuser: nebulous
    441     mounts:
    442       - /mnt
    443       - /tmp
    444       - /usr
    445496    pidfile: /var/tmp/nebdiskd
    446497    poll_interval: 5
     498    retry: 3
    447499
    448500The values C<db>, C<dbpass>, C<dbuser>, and C<pidfile> have the same semantics
     
    451503=over 4
    452504
    453 =item * C<mounts>
    454 
    455 A list of "paths" to C<stat(2)> before mounted volumes are polled.  The propose
    456 of this option is to attempt to keep "automounted" volumes mounted while this
    457 program is running.
    458 
    459505This value may be omitted or left blank.
    460506
     
    465511This value may be omitted or left blank.  The default value is C<60>s.
    466512
     513=item * C<retry>
     514
     515Same as C<--retry>.
     516
    467517=back
    468518
     
    481531=head1 COPYRIGHT
    482532
    483 Copyright (C) 2007  Joshua Hoblitt.  All rights reserved.
     533Copyright (C) 2007-2009  Joshua Hoblitt.  All rights reserved.
    484534
    485535This program is free software; you can redistribute it and/or modify it under
Note: See TracChangeset for help on using the changeset viewer.