Changeset 29478 for trunk/DataStoreServer/scripts/dsreg
- Timestamp:
- Oct 18, 2010, 11:44:34 AM (16 years ago)
- File:
-
- 1 edited
-
trunk/DataStoreServer/scripts/dsreg (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStoreServer/scripts/dsreg
r28800 r29478 42 42 43 43 my $dbname; # Database name 44 my $dbserver; # Database host 44 45 my $dsroot; # root directory of the data store 45 46 … … 82 83 'ps7=s' => \$ps7, 83 84 'dbname=s' => \$dbname, 85 'dbserver=s' => \$dbserver, 86 'ds_dbname=s' => \$dbname, # some scripts use these names 87 'ds_dbserver=s' => \$dbserver, 84 88 'dsroot=s' => \$dsroot, 85 89 'verbose' => \$verbose, 86 90 ) or pod2usage(2); 87 91 92 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 93 94 # collect all command line argument errors and only fail once below. 88 95 my $err = ""; 89 96 … … 121 128 $dsroot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT'); 122 129 if (!$dsroot) { 123 die("Data Store root directory not set"); 124 } 125 } 126 130 &my_die("Data Store root directory not set", $PS_EXIT_CONFIG_ERROR); 131 } 132 } 127 133 128 134 if (!stat("$dsroot/index.txt")) { … … 131 137 132 138 # bail if any errors above 133 show_usage($err) 134 if ($err); 135 136 show_usage("Invalid product '$product'.") 139 show_usage($err) if ($err); 140 141 show_usage("Invalid data store product '$product'.") 137 142 unless defined stat("$dsroot/$product/index.txt"); 138 143 139 144 $dbname = metadataLookupStr($siteConfig, 'DS_DBNAME') unless defined $dbname; 140 my $dbserver = metadataLookupStr($siteConfig, 'DS_DBSERVER');145 $dbserver = metadataLookupStr($siteConfig, 'DS_DBSERVER') unless defined $dbserver; 141 146 my $dbuser = metadataLookupStr($siteConfig, 'DS_DBUSER'); 142 147 my $dbpass = metadataLookupStr($siteConfig, 'DS_DBPASSWORD'); … … 148 153 149 154 my $dbh = DBI->connect_cached($dsn, $dbuser, $dbpass, \%conn_attrs) 150 or die "Cannot connect to DB server\n";155 or &my_die("Cannot connect to DB server\n", $PS_EXIT_SYS_ERROR); 151 156 152 157 print STDERR "dbh: $dbh\n" if $verbose; … … 161 166 162 167 my $stmt = $dbh->prepare("SELECT prod_id, last_fs FROM dsProduct WHERE prod_name = ?"); 163 $stmt->execute($product); 168 my $execute_status = $stmt->execute($product); 169 if (!$execute_status) { 170 print STDERR "failed to execute product lookup\n"; 171 exit 2; 172 } 164 173 165 174 my $prod_row = $stmt->fetchrow_hashref(); … … 228 237 my $rc; 229 238 if (($rc = system "rm -r $fileset_dir")) { 230 die("failed to remove $fileset_dir error code: $rc");239 &my_die("failed to remove $fileset_dir error code: $rc", $PS_EXIT_UNKNOWN_ERROR); 231 240 } 232 241 } else { … … 252 261 253 262 if (!$prod_id) { 254 die("product $product not found");263 &my_die("product $product not found", $PS_EXIT_UNKNOWN_ERROR); 255 264 } 256 265 my $count = $dbh->do("SELECT fileset_id FROM dsFileset WHERE fileset_name = ?" . … … 268 277 if (! -e $fileset_dir) { 269 278 if (!mkdir $fileset_dir) { 270 die("failed trying to create fileset directory $fileset_dir");279 &my_die("failed trying to create fileset directory $fileset_dir", $PS_EXIT_SYS_ERROR); 271 280 } 272 281 if (! -d $fileset_dir ) { 273 die("cannot access just created fileset directory $fileset_dir");282 &my_die("cannot access just created fileset directory $fileset_dir", $PS_EXIT_SYS_ERROR); 274 283 } 275 284 } … … 281 290 $in = *STDIN; 282 291 } else { 283 open $in, "<$filelist" or die "cannot open filelist file $filelist\n";292 open $in, "<$filelist" or &my_die("cannot open filelist file $filelist\n", $PS_EXIT_UNKNOWN_ERROR); 284 293 } 285 294 … … 296 305 my @fields = split /\|/; 297 306 if (@fields < 4) { 298 die "malformed input line at $filelist line $lineno: $_\n";307 &my_die("malformed input line at $filelist line $lineno: $_\n", $PS_EXIT_PROG_ERROR); 299 308 } 300 309 $filename = shift @fields; … … 320 329 } 321 330 322 die("empty filelist\n") if (@files == 0);331 &my_die("empty filelist\n", $PS_EXIT_PROG_ERROR) if (@files == 0); 323 332 324 333 # Prepare the fileset directory … … 350 359 } else { 351 360 if (!copy($src, $dest)) { 352 die("copy($src, $dest) failed");361 &my_die("copy($src, $dest) failed", $PS_EXIT_UNKNOWN_ERROR); 353 362 } 354 363 } … … 359 368 360 369 if (!$no_cleanup && system "rm -r $fileset_dir") { 361 die("failed to remove $fileset_dir");370 &my_die("failed to remove $fileset_dir", $PS_EXIT_UNKNOWN_ERROR); 362 371 } 363 372 exit $PS_EXIT_UNKNOWN_ERROR; … … 370 379 my $path = "$fileset_dir/$filename"; 371 380 if (! -e $path ) { 372 die "file $path not found";381 &my_die("file $path not found", , $PS_EXIT_UNKNOWN_ERROR); 373 382 } 374 383 # get the size of the file 375 384 my @finfo = stat($path); 376 385 unless (@finfo) { 377 die ("can't stat $path");386 &my_die ("can't stat $path", $PS_EXIT_UNKNOWN_ERROR); 378 387 } 379 388 # if size was supplied make sure that it matches the actual … … 382 391 my $current_size = $finfo[7]; 383 392 if ($file->{bytes} != $current_size) { 384 die"size on disk: $current_size does not match supplied"385 . " size: $file->{bytes} for $path" ;393 &my_die("size on disk: $current_size does not match supplied" 394 . " size: $file->{bytes} for $path", $PS_EXIT_PROG_ERROR); 386 395 } 387 396 } else { … … 391 400 # Get MD5 sum 392 401 $file->{md5sum} = file_md5_hex($path); 393 die("failed to compute valid md5sum for $path") if !$file->{md5sum};402 &my_die("failed to compute valid md5sum for $path", $PS_EXIT_UNKNOWN_ERROR) if !$file->{md5sum}; 394 403 } 395 404 } … … 401 410 $dbh->disconnect(); 402 411 $dbh = DBI->connect_cached($dsn, $dbuser, $dbpass, \%conn_attrs) 403 or die "Cannot connect to server\n";412 or &my_die("Cannot connect to server\n", $PS_EXIT_SYS_ERROR); 404 413 print STDERR "ping failed new dbh: $dbh\n" if $verbose; 405 414 } … … 415 424 $ps0, $ps1, $ps2, $ps3, $ps4, $ps5, $ps6, $ps7)); 416 425 417 die("failed to insert $fileset") if (!defined($count) or ($count == 0E0));426 &my_die("failed to insert $fileset", $PS_EXIT_UNKNOWN_ERROR) if (!defined($count) or ($count == 0E0)); 418 427 419 428 # I don't use last_insert_id() because I've seen some problems with it and … … 423 432 my $nfs = @fsids; 424 433 if (!$nfs) { 425 die("fileset '$fileset' missing even though we just added it");434 &my_die("fileset '$fileset' missing even though we just added it", $PS_EXIT_UNKNOWN_ERROR); 426 435 } elsif ($nfs > 1) { 427 die("Fileset '$fileset' already exists under $product.");436 &my_die("Fileset '$fileset' already exists under $product.", $PS_EXIT_PROG_ERROR); 428 437 } 429 438 my $fileset_id = $fsids[0]; … … 443 452 444 453 if ($count == 0E0) { 445 die("failed to insert $filename into $fileset");454 &my_die("failed to insert $filename into $fileset", $PS_EXIT_UNKNOWN_ERROR); 446 455 } 447 456 } … … 450 459 . " WHERE prod_id = $prod_id"); 451 460 if ($count == 0E0) { 452 die("failed to update dsProduct $prod_id");461 &my_die("failed to update dsProduct $prod_id", $PS_EXIT_UNKNOWN_ERROR); 453 462 } 454 463 … … 457 466 # create the cgi script index.txt by making a copy of its parent's 458 467 if (!copy("$dsroot/$product/index.txt", $index_script_name)) { 459 die("failed to copy index script to file set");468 &my_die("failed to copy index script to file set", $PS_EXIT_UNKNOWN_ERROR); 460 469 } 461 470 }; … … 531 540 } 532 541 } 542 543 sub my_die { 544 my $msg = shift; 545 my $fault = shift; 546 carp $msg; 547 exit $fault; 548 }
Note:
See TracChangeset
for help on using the changeset viewer.
