IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 1, 2009, 2:03:55 PM (17 years ago)
Author:
jhoblitt
Message:

add log4perl logging to nebdiskd

File:
1 edited

Legend:

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

    r20206 r23654  
    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 =<<END;
     90    log4perl.category.nebdiskd = WARN, Screen, SERVERLOGFILE
     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 | %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
     102END
     103Log::Log4perl::init(\$conf);
     104my $log = Log::Log4perl::get_logger("nebdiskd");
     105$log->level('WARN');
     106$log->level('DEBUG') if $debug;
     107
    87108daemonize(
    88109    $user,     # User
     
    104125                poll_interval   => $poll_interval,
    105126                debug           => $debug,
    106         ) or die "poll_mounts() should not have returned";
     127        );
    107128    };
    108     if ($!) {
    109         warn $@;
     129    if ($@) {
     130        $log->warn($@);
    110131    }
    111132
     
    113134}
    114135
    115 die "poll loop exited -- THIS SHOULD NOT HAPPEN";
     136$log->logdie("poll loop exited -- THIS SHOULD NOT HAPPEN");
    116137
    117138
     
    141162        # determine valid mountpoints
    142163        foreach my $mnt (@$mounts) {
    143             print "checking $mnt\n" if $debug;
     164            $log->debug("checking $mnt");
    144165            # this /SHOULD/ fail if the mount point is handled by the
    145166            # automounter and it fails to mount
    146167            eval {
    147168                unless (is_mountpoint($mnt)) {
    148                     die "$mnt is not a valid mountpoint\n";
     169                    $log->warn("$mnt is not a valid mountpoint");
    149170                }
    150171            };
    151172            if ($@) {
    152                 print $@ if $debug;
     173                $log->warn($@);
    153174                $d_query->execute($mnt);
    154175                next;
     
    160181            my $dev_info = df($mnt, 1024);
    161182            unless (defined $dev_info) {
    162                 print "can't find device info for $mnt\n" if $debug;
     183                $log->error("can't find device info for $mnt");
    163184                next;
    164185            }
    165186
    166187            $r_query->execute($mnt, @$dev_info{qw( blocks used )});
    167             print "adding $mnt to db\n" if $debug;
     188            $log->debug("adding $mnt to db");
    168189
    169190        }
     
    172193
    173194        $dbh->commit;
    174         print "commited to database\n" if $debug;
     195        $log->debug("commited to database");
    175196    };
    176197    if ($@) {
    177198        $dbh->rollback;
    178         print "rolledback transaction\n" if $debug;
    179         warn $@;
     199        $log->debug("rolledback transaction");
     200        $log->logdie($@);
    180201    }
    181202}
     
    188209
    189210    if (!-f $rcfile) {
    190         open(my $fh, '>', $rcfile) or die "can't open file: $!";
    191         close($fh) or die "can't close file:$!";
     211        open(my $fh, '>', $rcfile) or $log->logdie("can't open file: $!");
     212        close($fh) or $log->logdie("can't close file:$!");
    192213    }
    193214
     
    226247    };
    227248    if ($@) {
    228         $db->rollback;
    229         die $@;
     249        $dbh->rollback;
     250        $log->logdie($@);
    230251    }
    231252
     
    242263    foreach my $path (@$mounts) {
    243264        if (stat File::Spec->canonpath($path)) {
    244             print "stated $path\n" if $debug;
     265            $log->debug("stated $path");
    245266        } else {
    246             warn "can not stat path: $path";
     267            $log->warn("can not stat path: $path");
    247268        }
    248269    }
     
    263284  ### get the currently listed pid
    264285  if( ! open(_PID,$pid_file) ){
    265     die "Couldn't open existant pid_file \"$pid_file\" [$!]\n";
     286    $log->logdie("Couldn't open existant pid_file \"$pid_file\" [$!]");
    266287  }
    267288  my $_current_pid = <_PID>;
    268289  close _PID;
    269   my $current_pid = $_current_pid =~ /^(\d{1,10})/ ? $1 : die "Couldn't find pid in existing pid_file";
     290  my $current_pid = $_current_pid =~ /^(\d{1,10})/ ? $1 : $log->logdie("Couldn't find pid in existing pid_file");
    270291
    271292  my $exists = undef;
     
    289310
    290311        if( $current_pid == $$ ){
    291             warn "Pid_file created by this same process. Doing nothing.\n";
     312            $log->warn("Pid_file created by this same process. Doing nothing.");
    292313            return 1;
    293314        }else{
    294315            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";
     316                or $log->logdie("Failed to signal process ($current_pid)");
     317            unlink $pid_file || $log->logdie("Couldn't remove pid_file \"$pid_file\" [$!]");
    297318        }
    298319    }
Note: See TracChangeset for help on using the changeset viewer.