IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12580


Ignore:
Timestamp:
Mar 23, 2007, 2:40:11 PM (19 years ago)
Author:
jhoblitt
Message:

add nebdiskd support for an rcfile and daemonizing

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Build.PL

    r12553 r12580  
    7878    create_makefile_pl  => 'passthrough',
    7979    requires            => {
     80        'Config::YAML'          => '1.42',
    8081        'URI'                   => '1.30',
    8182        'SOAP::Lite'            => '0.69',
  • trunk/Nebulous-Server/bin/nebdiskd

    r12005 r12580  
    33# Copyright (C) 2007  Joshua Hoblitt
    44#
    5 # $Id: nebdiskd,v 1.1 2007-02-23 01:10:57 jhoblitt Exp $
     5# $Id: nebdiskd,v 1.2 2007-03-24 00:40:11 jhoblitt Exp $
    66
    77use strict;
     
    1111$VERSION = '0.02';
    1212
    13 use Net::Server::Daemonize qw(daemonize);
     13use Config::YAML;
     14use DBI;
     15use File::Spec;
     16use Nebulous::Server::SQL;
     17use Net::Server::Daemonize qw( daemonize unlink_pid_file );
    1418use Sys::Statistics::Linux::DiskUsage;
    15 use DBI;
    16 use Nebulous::Server::SQL;
    1719
    1820use Getopt::Long qw( GetOptions :config auto_help auto_version );
    1921use Pod::Usage qw( pod2usage );
    2022
    21 my ($debug, $db, $dbuser, $dbpass);
    22 
    23 $db     = $ENV{'NEB_DB'} unless $db;
    24 $dbuser = $ENV{'NEB_USER'} unless $dbuser;
    25 $dbpass = $ENV{'NEB_PASS'} unless $dbpass;
    26 
    27 our $POLL_INTERVAL = 5;
    28 
     23my ($debug, $db, $dbuser, $dbpass, $pidfile, $stop, $restart, $verbose);
    2924GetOptions(
    30     'debug|d'   => \$debug,
    31     'db=s'      => \$db,
    32     'user=s'    => \$dbuser,
    33     'pass=s'    => \$dbpass,
     25    'debug'     => \$debug,
     26    'db|d=s'    => \$db,
     27    'user|u=s'  => \$dbuser,
     28    'pass|p=s'  => \$dbpass,
     29    'pidfile=s' => \$pidfile,
     30    'stop|s'    => \$stop,
     31    'restart|r' => \$restart,
     32    'verbose|v' => \$verbose,
    3433) || pod2usage( 2 );
     34
     35my $rcfile = "$ENV{HOME}/.nebdiskrc";
     36$rcfile = File::Spec->canonpath($rcfile);
     37
     38my $c = read_rcfile($rcfile);
     39
     40$db     ||= $c->get_db      || $ENV{'NEB_DB'};
     41$dbuser ||= $c->get_dbuser  || $ENV{'NEB_USER'};
     42$dbpass ||= $c->get_dbpass  || $ENV{'NEB_PASS'};
     43$pidfile ||= $c->get_pidfile || "/var/tmp/nebdiskd";
     44my $mounts = $c->get_mounts;
     45my $poll_interval = $c->get_poll_interval || 5;
     46
     47if ($restart || $stop) {
     48    my $status = kill_pid_file($pidfile);
     49    exit($status) if $stop;
     50}
     51
     52$c->set_db($db);
     53$c->set_dbuser($dbuser);
     54$c->set_dbpass($dbpass);
     55$c->set_pidfile($pidfile);
     56$c->set_poll_interval($poll_interval);
     57$c->write;
    3558
    3659pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     
    3962
    4063daemonize(
    41     'jhoblitt', # User
    42     'wheel',    # Group
    43     undef       # PID file
     64    $<,    # User
     65    $),     # Group
     66    $pidfile,  # PID file
    4467) unless $debug;
    4568
    46 my $sql = Nebulous::Server::SQL->new;
    47 
    48 my $dbh = DBI->connect(
    49     "DBI:mysql:database=$db:host=localhost",
    50     $dbuser,
    51     $dbpass,
    52     {
    53         RaiseError => 1,
    54         PrintError => 0,
    55         AutoCommit => 0,
    56     },
    57 );
    58 
    59 $dbh->do( $sql->set_transaction_model );
    60 $dbh->commit;
    61 
    62 my $lxs   = Sys::Statistics::Linux::DiskUsage->new;
    63 
    64 while (1) {
    65     my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)");
    66     $dbh->do("DELETE FROM mount");
    67 
    68     my $stats = $lxs->get;
    69     foreach my $dev (keys %$stats) {
    70         my $mnt = $stats->{$dev};
    71         my %mount;
    72         $query->execute(@$mnt{qw( mountpoint total usage )});
     69$SIG{TERM} = sub { unlink_pid_file($pidfile); exit(); };
     70$SIG{INT}  = $SIG{TERM};
     71$SIG{HUP}  = sub { $c = read_rcfile($rcfile) };
     72
     73my $dbh = setup_db(
     74        db      => $db,
     75        dbuser  => $dbuser,
     76        dbpass  => $dbpass,
     77    );
     78
     79poll_mounts(
     80        dbh             => $dbh,
     81        poll_interval   => $poll_interval,
     82        debug           => $debug,
     83    ) or die "poll_mounts() should not have returned";
     84
     85sub poll_mounts
     86{
     87    my %p = @_;
     88
     89    my $dbh             = $p{dbh} or return;
     90    my $poll_interval   = $p{poll_interval} || 60;
     91    my $debug           = $p{debug} || 0;
     92
     93    my $lxs = Sys::Statistics::Linux::DiskUsage->new;
     94
     95    while (1) {
     96        # list of mount points to stat so that the automounter will mount these
     97        # volumes if they have been unmounted.
     98        stat_dirs($mounts);
     99
     100        my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)");
     101        $dbh->do("DELETE FROM mount");
     102        print "flushed mount table\n" if $debug;
     103
     104        my $stats = $lxs->get;
     105        foreach my $dev (keys %$stats) {
     106            my $mnt = $stats->{$dev};
     107            my %mount;
     108            $query->execute(@$mnt{qw( mountpoint total usage )});
     109            print "adding $mnt->{mountpoint} to db\n" if $debug;
     110        }
     111
     112        $dbh->commit;
     113
     114        sleep $poll_interval;
    73115    }
    74 
     116}
     117
     118sub read_rcfile
     119{
     120    my $rcfile = shift;
     121
     122    return unless defined $rcfile;
     123
     124    if (!-f $rcfile) {
     125        open(my $fh, '>', $rcfile) or die "can't open file: $!";
     126        close($fh) or die "can't close file:$!";
     127    }
     128
     129    return Config::YAML->new(
     130            config => $rcfile,
     131            output => $rcfile,
     132    );
     133}
     134
     135
     136sub setup_db
     137{
     138    my %p = @_;
     139
     140    return unless defined $p{db}
     141              and defined $p{dbuser}
     142              and defined $p{dbpass};
     143
     144    my $sql = Nebulous::Server::SQL->new;
     145
     146    my $dbh = DBI->connect(
     147        "DBI:mysql:database=$p{db}:host=localhost",
     148        $p{dbuser},
     149        $p{dbpass},
     150        {
     151            RaiseError => 1,
     152            PrintError => 1,
     153            AutoCommit => 0,
     154        },
     155    );
     156
     157    $dbh->do( $sql->set_transaction_model );
    75158    $dbh->commit;
    76159
    77     sleep $POLL_INTERVAL;
    78 }
     160    return $dbh;
     161}
     162
     163
     164sub stat_dirs
     165{
     166    my $mounts = shift;
     167
     168    return unless defined $mounts;
     169
     170    foreach my $path (@$mounts) {
     171        stat File::Spec->canonpath($path) or warn "can not stat path: $path";
     172        print "stated $path\n" if $debug;
     173    }
     174}
     175
     176#
     177# This function, originally named check_pid_file() was copied from
     178# Net::Server::Daemonize '0.05' licensed under the Perl license.  It has been
     179# renamed and modified to kill off process who's PID value is stored in pidfile.
     180#
     181
     182sub kill_pid_file {
     183  my $pid_file = shift;
     184
     185  ### no pid_file = return success
     186  return 1 unless -e $pid_file;
     187
     188  ### get the currently listed pid
     189  if( ! open(_PID,$pid_file) ){
     190    die "Couldn't open existant pid_file \"$pid_file\" [$!]\n";
     191  }
     192  my $_current_pid = <_PID>;
     193  close _PID;
     194  my $current_pid = $_current_pid =~ /^(\d{1,10})/ ? $1 : die "Couldn't find pid in existing pid_file";
     195
     196  my $exists = undef;
     197
     198  ### try a proc file system
     199  if( -d '/proc' ) {
     200    $exists = -e "/proc/$current_pid";
     201
     202  ### try ps
     203  #}elsif( -x '/bin/ps' ){ # not as portable
     204  # the ps command itself really isn't portable
     205  # this follows BSD syntax ps (BSD's and linux)
     206  # this will fail on Unix98 syntax ps (Solaris, etc)
     207  }elsif( `ps h o pid p $$` =~ /^\s*$$\s*$/ ){ # can I play ps on myself ?
     208    $exists = `ps h o pid p $current_pid`;
     209
     210  }
     211
     212  ### running process exists, ouch
     213    if( $exists ){
     214
     215        if( $current_pid == $$ ){
     216            warn "Pid_file created by this same process. Doing nothing.\n";
     217            return 1;
     218        }else{
     219            kill 'TERM', $current_pid
     220                or die "Failed to signal process ($current_pid)";
     221            unlink $pid_file || die "Couldn't remove pid_file \"$pid_file\" [$!]\n";
     222            return 1;
     223
     224        }
     225    }
     226}
     227
     228__END__
     229
     230=pod
     231
     232=head1 NAME
     233
     234nebdiskd - Nebulous mounted volume capacity monitoring daemon
     235
     236=head1 SYNOPSIS
     237
     238    nebdiskd [--db <db name>] [--user <db username>] [--pass <db password>] [--debug] [--pidfile <filename>] [--stop] [--restart] [--verbose]
     239
     240=head1 DESCRIPTION
     241
     242This program looks for mounted volumes, at a configurable interval, and records
     243statistics about them into a database.
     244
     245=head1 OPTIONS
     246
     247=over 4
     248
     249=item * --db|-d <db name>
     250
     251Name of database (C<namespace>) to write too.
     252
     253Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
     254variable is set.
     255
     256=item * --user|-u <db username>
     257
     258Username to authenticate with.
     259
     260Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
     261variable is set.
     262
     263=item * --pass|-p <db password>
     264
     265Password to authenticate with.
     266
     267Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
     268variable is set.
     269
     270=item * --debug
     271
     272This flag prevents the program from "daemonizing" so output can be sent to
     273C<stdout>/C<stderr> and a debugger used on the running process.
     274
     275=item * --pidfile <filename>
     276
     277Filename to log the running daemon's PID too.
     278
     279Optional, if this option is omitted and no value is defined in the
     280F<.nebdiskrc> then no pidfile is created.
     281
     282=item * --stop|-s
     283
     284Uses the pidfile to kill an already running daemon.
     285
     286=item * --restart|-r
     287
     288Uses the pidfile to kill an already running daemon and then starts a new
     289instance.
     290
     291=item * --verbose|-r
     292
     293Turns on informational/debugging messages to be sent to the
     294C<stderr>/C<stdout>.  This option is probably not very usefully unless combined
     295with C<--debug>.
     296
     297=back
     298
     299=head1 ENVIRONMENT
     300
     301These environment variables may be used in place of the specified command line
     302options.  All command line option will override the corresponding environment
     303value.
     304
     305=over 4
     306
     307=item * C<NEB_DB>
     308
     309Equivalent to --db|-d
     310
     311=item * C<NEB_USER>
     312
     313Equivalent to --user|-u
     314
     315=item * C<NEB_PASS>
     316
     317Equivalent to --pass|-p
     318
     319=back
     320
     321=head1 RCFILE
     322
     323This program will attempt to read an C<rcfile> from F<$HOME/.nebdiskrc> and if
     324found will use it's values to override program defaults.  Please not that the
     325precedence for values is: command line, rcfile, environment variables.
     326
     327The format of the C<rcfile> is in L<YAML> format and uses the following values:
     328
     329    ---
     330    db: nebulous
     331    dbpass: '@neb@'
     332    dbuser: nebulous
     333    mounts:
     334      - /mnt
     335      - /tmp
     336      - /usr
     337    pidfile: /var/tmp/nebdiskd
     338    poll_interval: 5
     339
     340The values C<db>, C<dbpass>, C<dbuser>, and C<pidfile> have the same semantics
     341as their command line and/or environment variable equivalents.
     342
     343=over 4
     344
     345=item * C<mounts>
     346
     347A list of "paths" to C<stat(2)> before mounted volumes are polled.  The propose
     348of this option is to attempt to keep "automounted" volumes mounted while this
     349program is running.
     350
     351This value may be omitted or left blank.
     352
     353=item * C<poll_interval>
     354
     355The number of seconds to wait between checks for mounted volumes.
     356
     357This value may be omitted or left blank.  The default value is C<60>s.
     358
     359=back
     360
     361=head1 CREDITS
     362
     363Just me, myself, and I.
     364
     365=head1 SUPPORT
     366
     367Please contact the author directly via e-mail.
     368
     369=head1 AUTHOR
     370
     371Joshua Hoblitt <jhoblitt@cpan.org>
     372
     373=head1 COPYRIGHT
     374
     375Copyright (C) 2007  Joshua Hoblitt.  All rights reserved.
     376
     377This program is free software; you can redistribute it and/or modify it under
     378the terms of the GNU General Public License as published by the Free Software
     379Foundation; either version 2 of the License, or (at your option) any later
     380version.
     381
     382This program is distributed in the hope that it will be useful, but WITHOUT ANY
     383WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
     384PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     385
     386You should have received a copy of the GNU General Public License along with
     387this program; if not, write to the Free Software Foundation, Inc., 59 Temple
     388Place - Suite 330, Boston, MA  02111-1307, USA.
     389
     390The full text of the license can be found in the L<perlgpl> Pod as supplied
     391with Perl 5.8.1 and later.
     392
     393=head1 SEE ALSO
     394
     395L<Nebulous::Server>, L<YAML>
     396
     397=cut
  • trunk/Nebulous/Build.PL

    r12553 r12580  
    7878    create_makefile_pl  => 'passthrough',
    7979    requires            => {
     80        'Config::YAML'          => '1.42',
    8081        'URI'                   => '1.30',
    8182        'SOAP::Lite'            => '0.69',
  • trunk/Nebulous/bin/nebdiskd

    r12005 r12580  
    33# Copyright (C) 2007  Joshua Hoblitt
    44#
    5 # $Id: nebdiskd,v 1.1 2007-02-23 01:10:57 jhoblitt Exp $
     5# $Id: nebdiskd,v 1.2 2007-03-24 00:40:11 jhoblitt Exp $
    66
    77use strict;
     
    1111$VERSION = '0.02';
    1212
    13 use Net::Server::Daemonize qw(daemonize);
     13use Config::YAML;
     14use DBI;
     15use File::Spec;
     16use Nebulous::Server::SQL;
     17use Net::Server::Daemonize qw( daemonize unlink_pid_file );
    1418use Sys::Statistics::Linux::DiskUsage;
    15 use DBI;
    16 use Nebulous::Server::SQL;
    1719
    1820use Getopt::Long qw( GetOptions :config auto_help auto_version );
    1921use Pod::Usage qw( pod2usage );
    2022
    21 my ($debug, $db, $dbuser, $dbpass);
    22 
    23 $db     = $ENV{'NEB_DB'} unless $db;
    24 $dbuser = $ENV{'NEB_USER'} unless $dbuser;
    25 $dbpass = $ENV{'NEB_PASS'} unless $dbpass;
    26 
    27 our $POLL_INTERVAL = 5;
    28 
     23my ($debug, $db, $dbuser, $dbpass, $pidfile, $stop, $restart, $verbose);
    2924GetOptions(
    30     'debug|d'   => \$debug,
    31     'db=s'      => \$db,
    32     'user=s'    => \$dbuser,
    33     'pass=s'    => \$dbpass,
     25    'debug'     => \$debug,
     26    'db|d=s'    => \$db,
     27    'user|u=s'  => \$dbuser,
     28    'pass|p=s'  => \$dbpass,
     29    'pidfile=s' => \$pidfile,
     30    'stop|s'    => \$stop,
     31    'restart|r' => \$restart,
     32    'verbose|v' => \$verbose,
    3433) || pod2usage( 2 );
     34
     35my $rcfile = "$ENV{HOME}/.nebdiskrc";
     36$rcfile = File::Spec->canonpath($rcfile);
     37
     38my $c = read_rcfile($rcfile);
     39
     40$db     ||= $c->get_db      || $ENV{'NEB_DB'};
     41$dbuser ||= $c->get_dbuser  || $ENV{'NEB_USER'};
     42$dbpass ||= $c->get_dbpass  || $ENV{'NEB_PASS'};
     43$pidfile ||= $c->get_pidfile || "/var/tmp/nebdiskd";
     44my $mounts = $c->get_mounts;
     45my $poll_interval = $c->get_poll_interval || 5;
     46
     47if ($restart || $stop) {
     48    my $status = kill_pid_file($pidfile);
     49    exit($status) if $stop;
     50}
     51
     52$c->set_db($db);
     53$c->set_dbuser($dbuser);
     54$c->set_dbpass($dbpass);
     55$c->set_pidfile($pidfile);
     56$c->set_poll_interval($poll_interval);
     57$c->write;
    3558
    3659pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     
    3962
    4063daemonize(
    41     'jhoblitt', # User
    42     'wheel',    # Group
    43     undef       # PID file
     64    $<,    # User
     65    $),     # Group
     66    $pidfile,  # PID file
    4467) unless $debug;
    4568
    46 my $sql = Nebulous::Server::SQL->new;
    47 
    48 my $dbh = DBI->connect(
    49     "DBI:mysql:database=$db:host=localhost",
    50     $dbuser,
    51     $dbpass,
    52     {
    53         RaiseError => 1,
    54         PrintError => 0,
    55         AutoCommit => 0,
    56     },
    57 );
    58 
    59 $dbh->do( $sql->set_transaction_model );
    60 $dbh->commit;
    61 
    62 my $lxs   = Sys::Statistics::Linux::DiskUsage->new;
    63 
    64 while (1) {
    65     my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)");
    66     $dbh->do("DELETE FROM mount");
    67 
    68     my $stats = $lxs->get;
    69     foreach my $dev (keys %$stats) {
    70         my $mnt = $stats->{$dev};
    71         my %mount;
    72         $query->execute(@$mnt{qw( mountpoint total usage )});
     69$SIG{TERM} = sub { unlink_pid_file($pidfile); exit(); };
     70$SIG{INT}  = $SIG{TERM};
     71$SIG{HUP}  = sub { $c = read_rcfile($rcfile) };
     72
     73my $dbh = setup_db(
     74        db      => $db,
     75        dbuser  => $dbuser,
     76        dbpass  => $dbpass,
     77    );
     78
     79poll_mounts(
     80        dbh             => $dbh,
     81        poll_interval   => $poll_interval,
     82        debug           => $debug,
     83    ) or die "poll_mounts() should not have returned";
     84
     85sub poll_mounts
     86{
     87    my %p = @_;
     88
     89    my $dbh             = $p{dbh} or return;
     90    my $poll_interval   = $p{poll_interval} || 60;
     91    my $debug           = $p{debug} || 0;
     92
     93    my $lxs = Sys::Statistics::Linux::DiskUsage->new;
     94
     95    while (1) {
     96        # list of mount points to stat so that the automounter will mount these
     97        # volumes if they have been unmounted.
     98        stat_dirs($mounts);
     99
     100        my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)");
     101        $dbh->do("DELETE FROM mount");
     102        print "flushed mount table\n" if $debug;
     103
     104        my $stats = $lxs->get;
     105        foreach my $dev (keys %$stats) {
     106            my $mnt = $stats->{$dev};
     107            my %mount;
     108            $query->execute(@$mnt{qw( mountpoint total usage )});
     109            print "adding $mnt->{mountpoint} to db\n" if $debug;
     110        }
     111
     112        $dbh->commit;
     113
     114        sleep $poll_interval;
    73115    }
    74 
     116}
     117
     118sub read_rcfile
     119{
     120    my $rcfile = shift;
     121
     122    return unless defined $rcfile;
     123
     124    if (!-f $rcfile) {
     125        open(my $fh, '>', $rcfile) or die "can't open file: $!";
     126        close($fh) or die "can't close file:$!";
     127    }
     128
     129    return Config::YAML->new(
     130            config => $rcfile,
     131            output => $rcfile,
     132    );
     133}
     134
     135
     136sub setup_db
     137{
     138    my %p = @_;
     139
     140    return unless defined $p{db}
     141              and defined $p{dbuser}
     142              and defined $p{dbpass};
     143
     144    my $sql = Nebulous::Server::SQL->new;
     145
     146    my $dbh = DBI->connect(
     147        "DBI:mysql:database=$p{db}:host=localhost",
     148        $p{dbuser},
     149        $p{dbpass},
     150        {
     151            RaiseError => 1,
     152            PrintError => 1,
     153            AutoCommit => 0,
     154        },
     155    );
     156
     157    $dbh->do( $sql->set_transaction_model );
    75158    $dbh->commit;
    76159
    77     sleep $POLL_INTERVAL;
    78 }
     160    return $dbh;
     161}
     162
     163
     164sub stat_dirs
     165{
     166    my $mounts = shift;
     167
     168    return unless defined $mounts;
     169
     170    foreach my $path (@$mounts) {
     171        stat File::Spec->canonpath($path) or warn "can not stat path: $path";
     172        print "stated $path\n" if $debug;
     173    }
     174}
     175
     176#
     177# This function, originally named check_pid_file() was copied from
     178# Net::Server::Daemonize '0.05' licensed under the Perl license.  It has been
     179# renamed and modified to kill off process who's PID value is stored in pidfile.
     180#
     181
     182sub kill_pid_file {
     183  my $pid_file = shift;
     184
     185  ### no pid_file = return success
     186  return 1 unless -e $pid_file;
     187
     188  ### get the currently listed pid
     189  if( ! open(_PID,$pid_file) ){
     190    die "Couldn't open existant pid_file \"$pid_file\" [$!]\n";
     191  }
     192  my $_current_pid = <_PID>;
     193  close _PID;
     194  my $current_pid = $_current_pid =~ /^(\d{1,10})/ ? $1 : die "Couldn't find pid in existing pid_file";
     195
     196  my $exists = undef;
     197
     198  ### try a proc file system
     199  if( -d '/proc' ) {
     200    $exists = -e "/proc/$current_pid";
     201
     202  ### try ps
     203  #}elsif( -x '/bin/ps' ){ # not as portable
     204  # the ps command itself really isn't portable
     205  # this follows BSD syntax ps (BSD's and linux)
     206  # this will fail on Unix98 syntax ps (Solaris, etc)
     207  }elsif( `ps h o pid p $$` =~ /^\s*$$\s*$/ ){ # can I play ps on myself ?
     208    $exists = `ps h o pid p $current_pid`;
     209
     210  }
     211
     212  ### running process exists, ouch
     213    if( $exists ){
     214
     215        if( $current_pid == $$ ){
     216            warn "Pid_file created by this same process. Doing nothing.\n";
     217            return 1;
     218        }else{
     219            kill 'TERM', $current_pid
     220                or die "Failed to signal process ($current_pid)";
     221            unlink $pid_file || die "Couldn't remove pid_file \"$pid_file\" [$!]\n";
     222            return 1;
     223
     224        }
     225    }
     226}
     227
     228__END__
     229
     230=pod
     231
     232=head1 NAME
     233
     234nebdiskd - Nebulous mounted volume capacity monitoring daemon
     235
     236=head1 SYNOPSIS
     237
     238    nebdiskd [--db <db name>] [--user <db username>] [--pass <db password>] [--debug] [--pidfile <filename>] [--stop] [--restart] [--verbose]
     239
     240=head1 DESCRIPTION
     241
     242This program looks for mounted volumes, at a configurable interval, and records
     243statistics about them into a database.
     244
     245=head1 OPTIONS
     246
     247=over 4
     248
     249=item * --db|-d <db name>
     250
     251Name of database (C<namespace>) to write too.
     252
     253Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
     254variable is set.
     255
     256=item * --user|-u <db username>
     257
     258Username to authenticate with.
     259
     260Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
     261variable is set.
     262
     263=item * --pass|-p <db password>
     264
     265Password to authenticate with.
     266
     267Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
     268variable is set.
     269
     270=item * --debug
     271
     272This flag prevents the program from "daemonizing" so output can be sent to
     273C<stdout>/C<stderr> and a debugger used on the running process.
     274
     275=item * --pidfile <filename>
     276
     277Filename to log the running daemon's PID too.
     278
     279Optional, if this option is omitted and no value is defined in the
     280F<.nebdiskrc> then no pidfile is created.
     281
     282=item * --stop|-s
     283
     284Uses the pidfile to kill an already running daemon.
     285
     286=item * --restart|-r
     287
     288Uses the pidfile to kill an already running daemon and then starts a new
     289instance.
     290
     291=item * --verbose|-r
     292
     293Turns on informational/debugging messages to be sent to the
     294C<stderr>/C<stdout>.  This option is probably not very usefully unless combined
     295with C<--debug>.
     296
     297=back
     298
     299=head1 ENVIRONMENT
     300
     301These environment variables may be used in place of the specified command line
     302options.  All command line option will override the corresponding environment
     303value.
     304
     305=over 4
     306
     307=item * C<NEB_DB>
     308
     309Equivalent to --db|-d
     310
     311=item * C<NEB_USER>
     312
     313Equivalent to --user|-u
     314
     315=item * C<NEB_PASS>
     316
     317Equivalent to --pass|-p
     318
     319=back
     320
     321=head1 RCFILE
     322
     323This program will attempt to read an C<rcfile> from F<$HOME/.nebdiskrc> and if
     324found will use it's values to override program defaults.  Please not that the
     325precedence for values is: command line, rcfile, environment variables.
     326
     327The format of the C<rcfile> is in L<YAML> format and uses the following values:
     328
     329    ---
     330    db: nebulous
     331    dbpass: '@neb@'
     332    dbuser: nebulous
     333    mounts:
     334      - /mnt
     335      - /tmp
     336      - /usr
     337    pidfile: /var/tmp/nebdiskd
     338    poll_interval: 5
     339
     340The values C<db>, C<dbpass>, C<dbuser>, and C<pidfile> have the same semantics
     341as their command line and/or environment variable equivalents.
     342
     343=over 4
     344
     345=item * C<mounts>
     346
     347A list of "paths" to C<stat(2)> before mounted volumes are polled.  The propose
     348of this option is to attempt to keep "automounted" volumes mounted while this
     349program is running.
     350
     351This value may be omitted or left blank.
     352
     353=item * C<poll_interval>
     354
     355The number of seconds to wait between checks for mounted volumes.
     356
     357This value may be omitted or left blank.  The default value is C<60>s.
     358
     359=back
     360
     361=head1 CREDITS
     362
     363Just me, myself, and I.
     364
     365=head1 SUPPORT
     366
     367Please contact the author directly via e-mail.
     368
     369=head1 AUTHOR
     370
     371Joshua Hoblitt <jhoblitt@cpan.org>
     372
     373=head1 COPYRIGHT
     374
     375Copyright (C) 2007  Joshua Hoblitt.  All rights reserved.
     376
     377This program is free software; you can redistribute it and/or modify it under
     378the terms of the GNU General Public License as published by the Free Software
     379Foundation; either version 2 of the License, or (at your option) any later
     380version.
     381
     382This program is distributed in the hope that it will be useful, but WITHOUT ANY
     383WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
     384PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     385
     386You should have received a copy of the GNU General Public License along with
     387this program; if not, write to the Free Software Foundation, Inc., 59 Temple
     388Place - Suite 330, Boston, MA  02111-1307, USA.
     389
     390The full text of the license can be found in the L<perlgpl> Pod as supplied
     391with Perl 5.8.1 and later.
     392
     393=head1 SEE ALSO
     394
     395L<Nebulous::Server>, L<YAML>
     396
     397=cut
Note: See TracChangeset for help on using the changeset viewer.