Changeset 23654
- Timestamp:
- Apr 1, 2009, 2:03:55 PM (17 years ago)
- Location:
- trunk/Nebulous-Server
- Files:
-
- 2 edited
-
Changes (modified) (1 diff)
-
bin/nebdiskd (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r23458 r23654 3 3 0.17 4 4 - retry database transactions when a deadlock is detected 5 - add log4perl logging to nebdiskd 5 6 6 7 0.16 -
trunk/Nebulous-Server/bin/nebdiskd
r20206 r23654 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 =<<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 102 END 103 Log::Log4perl::init(\$conf); 104 my $log = Log::Log4perl::get_logger("nebdiskd"); 105 $log->level('WARN'); 106 $log->level('DEBUG') if $debug; 107 87 108 daemonize( 88 109 $user, # User … … 104 125 poll_interval => $poll_interval, 105 126 debug => $debug, 106 ) or die "poll_mounts() should not have returned";127 ); 107 128 }; 108 if ($ !) {109 warn $@;129 if ($@) { 130 $log->warn($@); 110 131 } 111 132 … … 113 134 } 114 135 115 die "poll loop exited -- THIS SHOULD NOT HAPPEN";136 $log->logdie("poll loop exited -- THIS SHOULD NOT HAPPEN"); 116 137 117 138 … … 141 162 # determine valid mountpoints 142 163 foreach my $mnt (@$mounts) { 143 print "checking $mnt\n" if $debug;164 $log->debug("checking $mnt"); 144 165 # this /SHOULD/ fail if the mount point is handled by the 145 166 # automounter and it fails to mount 146 167 eval { 147 168 unless (is_mountpoint($mnt)) { 148 die "$mnt is not a valid mountpoint\n";169 $log->warn("$mnt is not a valid mountpoint"); 149 170 } 150 171 }; 151 172 if ($@) { 152 print $@ if $debug;173 $log->warn($@); 153 174 $d_query->execute($mnt); 154 175 next; … … 160 181 my $dev_info = df($mnt, 1024); 161 182 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"); 163 184 next; 164 185 } 165 186 166 187 $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"); 168 189 169 190 } … … 172 193 173 194 $dbh->commit; 174 print "commited to database\n" if $debug;195 $log->debug("commited to database"); 175 196 }; 176 197 if ($@) { 177 198 $dbh->rollback; 178 print "rolledback transaction\n" if $debug;179 warn $@;199 $log->debug("rolledback transaction"); 200 $log->logdie($@); 180 201 } 181 202 } … … 188 209 189 210 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:$!"); 192 213 } 193 214 … … 226 247 }; 227 248 if ($@) { 228 $db ->rollback;229 die $@;249 $dbh->rollback; 250 $log->logdie($@); 230 251 } 231 252 … … 242 263 foreach my $path (@$mounts) { 243 264 if (stat File::Spec->canonpath($path)) { 244 print "stated $path\n" if $debug;265 $log->debug("stated $path"); 245 266 } else { 246 warn "can not stat path: $path";267 $log->warn("can not stat path: $path"); 247 268 } 248 269 } … … 263 284 ### get the currently listed pid 264 285 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\" [$!]"); 266 287 } 267 288 my $_current_pid = <_PID>; 268 289 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"); 270 291 271 292 my $exists = undef; … … 289 310 290 311 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."); 292 313 return 1; 293 314 }else{ 294 315 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\" [$!]"); 297 318 } 298 319 }
Note:
See TracChangeset
for help on using the changeset viewer.
