- Timestamp:
- Apr 3, 2009, 3:14:24 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/neb_distrib_20081210/Nebulous-Server/bin/nebdiskd
r20206 r23708 16 16 use File::Spec; 17 17 use Filesys::Df; 18 use Log::Log4perl; 18 19 use Nebulous::Server::SQL; 19 20 use Net::Server::Daemonize qw( daemonize unlink_pid_file ); … … 85 86 unless $db && $dbuser && $dbpass; 86 87 88 # start up logging 89 my $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 '; 114 Log::Log4perl::init(\$conf); 115 my $log = Log::Log4perl::get_logger("nebdiskd"); 116 $log->level('WARN'); 117 $log->level('DEBUG') if $debug; 118 87 119 daemonize( 88 120 $user, # User … … 104 136 poll_interval => $poll_interval, 105 137 debug => $debug, 106 ) or die "poll_mounts() should not have returned";138 ); 107 139 }; 108 if ($ !) {109 warn $@;140 if ($@) { 141 $log->warn($@); 110 142 } 111 143 … … 113 145 } 114 146 115 die "poll loop exited -- THIS SHOULD NOT HAPPEN";147 $log->logdie("poll loop exited -- THIS SHOULD NOT HAPPEN"); 116 148 117 149 … … 141 173 # determine valid mountpoints 142 174 foreach my $mnt (@$mounts) { 143 print "checking $mnt\n" if $debug;175 $log->debug("checking $mnt"); 144 176 # this /SHOULD/ fail if the mount point is handled by the 145 177 # automounter and it fails to mount 146 178 eval { 147 179 unless (is_mountpoint($mnt)) { 148 die "$mnt is not a valid mountpoint\n";180 $log->warn("$mnt is not a valid mountpoint"); 149 181 } 150 182 }; 151 183 if ($@) { 152 print $@ if $debug;184 $log->warn($@); 153 185 $d_query->execute($mnt); 154 186 next; … … 160 192 my $dev_info = df($mnt, 1024); 161 193 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"); 163 195 next; 164 196 } 165 197 166 198 $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"); 168 200 169 201 } … … 172 204 173 205 $dbh->commit; 174 print "commited to database\n" if $debug;206 $log->debug("commited to database"); 175 207 }; 176 208 if ($@) { 177 209 $dbh->rollback; 178 print "rolledback transaction\n" if $debug;179 warn $@;210 $log->debug("rolledback transaction"); 211 $log->logdie($@); 180 212 } 181 213 } … … 188 220 189 221 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:$!"); 192 224 } 193 225 … … 226 258 }; 227 259 if ($@) { 228 $db ->rollback;229 die $@;260 $dbh->rollback; 261 $log->logdie($@); 230 262 } 231 263 … … 242 274 foreach my $path (@$mounts) { 243 275 if (stat File::Spec->canonpath($path)) { 244 print "stated $path\n" if $debug;276 $log->debug("stated $path"); 245 277 } else { 246 warn "can not stat path: $path";278 $log->warn("can not stat path: $path"); 247 279 } 248 280 } … … 263 295 ### get the currently listed pid 264 296 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\" [$!]"); 266 298 } 267 299 my $_current_pid = <_PID>; 268 300 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"); 270 302 271 303 my $exists = undef; … … 289 321 290 322 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."); 292 324 return 1; 293 325 }else{ 294 326 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\" [$!]"); 297 329 } 298 330 }
Note:
See TracChangeset
for help on using the changeset viewer.
