IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 3, 2009, 3:14:24 PM (17 years ago)
Author:
jhoblitt
Message:

merge everything from head except Server.pm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/neb_distrib_20081210/Nebulous-Server/bin/nebdiskd

    r20206 r23708  
    1616use File::Spec;
    1717use Filesys::Df;
     18use Log::Log4perl;
    1819use Nebulous::Server::SQL;
    1920use Net::Server::Daemonize qw( daemonize unlink_pid_file );
     
    8586    unless $db && $dbuser && $dbpass;
    8687
     88# start up logging
     89my $conf = '
     90    log4perl.category.nebdiskd = WARN, Screen, SERVERLOGFILE, Mailer
     91
     92    log4perl.appender.Screen        = Log::Log4perl::Appender::Screen
     93    log4perl.appender.Screen.stderr = 1
     94    log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
     95    log4perl.appender.Screen.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n
     96
     97    log4perl.appender.SERVERLOGFILE           = Log::Log4perl::Appender::File
     98    log4perl.appender.SERVERLOGFILE.filename  = /tmp/nebdiskd.log
     99    log4perl.appender.SERVERLOGFILE.mode      = append
     100    log4perl.appender.SERVERLOGFILE.layout    = Log::Log4perl::Layout::PatternLayout
     101    log4perl.appender.SERVERLOGFILE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n
     102
     103    log4perl.filter.MatchWarn  = Log::Log4perl::Filter::LevelMatch
     104    log4perl.filter.MatchWarn.LevelToMatch  = WARN
     105    log4perl.filter.MatchWarn.AcceptOnMatch = off
     106
     107    log4perl.appender.Mailer         = Log::Dispatch::Email::MailSend
     108    log4perl.appender.Mailer.to      = ps-ipp-ops@ifa.hawaii.edu
     109    log4perl.appender.Mailer.subject = nebdiskd alert
     110    log4perl.appender.AppError.Filter= MatchWarn
     111    log4perl.appender.Mailer.layout = Log::Log4perl::Layout::PatternLayout
     112    log4perl.appender.Mailer.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n
     113';
     114Log::Log4perl::init(\$conf);
     115my $log = Log::Log4perl::get_logger("nebdiskd");
     116$log->level('WARN');
     117$log->level('DEBUG') if $debug;
     118
    87119daemonize(
    88120    $user,     # User
     
    104136                poll_interval   => $poll_interval,
    105137                debug           => $debug,
    106         ) or die "poll_mounts() should not have returned";
     138        );
    107139    };
    108     if ($!) {
    109         warn $@;
     140    if ($@) {
     141        $log->warn($@);
    110142    }
    111143
     
    113145}
    114146
    115 die "poll loop exited -- THIS SHOULD NOT HAPPEN";
     147$log->logdie("poll loop exited -- THIS SHOULD NOT HAPPEN");
    116148
    117149
     
    141173        # determine valid mountpoints
    142174        foreach my $mnt (@$mounts) {
    143             print "checking $mnt\n" if $debug;
     175            $log->debug("checking $mnt");
    144176            # this /SHOULD/ fail if the mount point is handled by the
    145177            # automounter and it fails to mount
    146178            eval {
    147179                unless (is_mountpoint($mnt)) {
    148                     die "$mnt is not a valid mountpoint\n";
     180                    $log->warn("$mnt is not a valid mountpoint");
    149181                }
    150182            };
    151183            if ($@) {
    152                 print $@ if $debug;
     184                $log->warn($@);
    153185                $d_query->execute($mnt);
    154186                next;
     
    160192            my $dev_info = df($mnt, 1024);
    161193            unless (defined $dev_info) {
    162                 print "can't find device info for $mnt\n" if $debug;
     194                $log->error("can't find device info for $mnt");
    163195                next;
    164196            }
    165197
    166198            $r_query->execute($mnt, @$dev_info{qw( blocks used )});
    167             print "adding $mnt to db\n" if $debug;
     199            $log->debug("adding $mnt to db");
    168200
    169201        }
     
    172204
    173205        $dbh->commit;
    174         print "commited to database\n" if $debug;
     206        $log->debug("commited to database");
    175207    };
    176208    if ($@) {
    177209        $dbh->rollback;
    178         print "rolledback transaction\n" if $debug;
    179         warn $@;
     210        $log->debug("rolledback transaction");
     211        $log->logdie($@);
    180212    }
    181213}
     
    188220
    189221    if (!-f $rcfile) {
    190         open(my $fh, '>', $rcfile) or die "can't open file: $!";
    191         close($fh) or die "can't close file:$!";
     222        open(my $fh, '>', $rcfile) or $log->logdie("can't open file: $!");
     223        close($fh) or $log->logdie("can't close file:$!");
    192224    }
    193225
     
    226258    };
    227259    if ($@) {
    228         $db->rollback;
    229         die $@;
     260        $dbh->rollback;
     261        $log->logdie($@);
    230262    }
    231263
     
    242274    foreach my $path (@$mounts) {
    243275        if (stat File::Spec->canonpath($path)) {
    244             print "stated $path\n" if $debug;
     276            $log->debug("stated $path");
    245277        } else {
    246             warn "can not stat path: $path";
     278            $log->warn("can not stat path: $path");
    247279        }
    248280    }
     
    263295  ### get the currently listed pid
    264296  if( ! open(_PID,$pid_file) ){
    265     die "Couldn't open existant pid_file \"$pid_file\" [$!]\n";
     297    $log->logdie("Couldn't open existant pid_file \"$pid_file\" [$!]");
    266298  }
    267299  my $_current_pid = <_PID>;
    268300  close _PID;
    269   my $current_pid = $_current_pid =~ /^(\d{1,10})/ ? $1 : die "Couldn't find pid in existing pid_file";
     301  my $current_pid = $_current_pid =~ /^(\d{1,10})/ ? $1 : $log->logdie("Couldn't find pid in existing pid_file");
    270302
    271303  my $exists = undef;
     
    289321
    290322        if( $current_pid == $$ ){
    291             warn "Pid_file created by this same process. Doing nothing.\n";
     323            $log->warn("Pid_file created by this same process. Doing nothing.");
    292324            return 1;
    293325        }else{
    294326            kill 'TERM', $current_pid
    295                 or die "Failed to signal process ($current_pid)";
    296             unlink $pid_file || die "Couldn't remove pid_file \"$pid_file\" [$!]\n";
     327                or $log->logdie("Failed to signal process ($current_pid)");
     328            unlink $pid_file || $log->logdie("Couldn't remove pid_file \"$pid_file\" [$!]");
    297329        }
    298330    }
Note: See TracChangeset for help on using the changeset viewer.