Changeset 748 in ProjectBuilder for devel/pb/bin
- Timestamp:
- Mar 29, 2009, 6:52:33 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/bin/pb
r739 r748 36 36 my $action; # action to realize 37 37 my $test = "FALSE"; # Not used 38 my $force = 0; # Force VE/VM rebuild 38 my $pbforce = 0; # Force VE/VM rebuild 39 my $pbsnap = 0; # Use snapshot mode for VM/VE 39 40 my $option = ""; # Not used 40 41 my @pkgs; # list of packages … … 63 64 pb helps you build various packages directly from your project sources. 64 65 Those sources could be handled by a CMS (Configuration Management System) 65 such as Subversion, CVS, Mercurial... or being a simple reference to a compressed tar file.66 such as Subversion, CVS, Git, Mercurial... or being a simple reference to a compressed tar file. 66 67 It's based on a set of configuration files, a set of provided macros to help 67 68 you keeping build files as generic as possible. For example, a single .spec … … 71 72 =head1 SYNOPSIS 72 73 73 pb [-vh q][-r pbroot][-p project][[-s script -a account -P port][-m mach-1[,...]]][-i iso] <action> [<pkg1> ...]74 75 pb [--verbose][--help][--man][--quiet][-- revision pbroot][--project project][[--script script --account account --port port][--machine mach-1[,...]]][--iso iso] <action> [<pkg1> ...]74 pb [-vhSq][-r pbroot][-p project][[-s script -a account -P port][-m mach-1[,...]]][-i iso] <action> [<pkg1> ...] 75 76 pb [--verbose][--help][--man][--quiet][--snapshot][--revision pbroot][--project project][[--script script --account account --port port][--machine mach-1[,...]]][--iso iso] <action> [<pkg1> ...] 76 77 77 78 =head1 OPTIONS … … 90 91 91 92 Print a brief help message and exits. 93 94 =item B<-S|--snapshot> 95 96 Use the snapshot mode of VMs or VEs 92 97 93 98 =item B<--man> … … 214 219 215 220 Setup a virtual environment for pb usage 221 222 =item B<snapvm> 223 224 Snapshot a virtual machine for pb usage 225 226 =item B<snapve> 227 228 Snapshot a virtual environment for pb usage 216 229 217 230 =item B<newver> … … 314 327 # --------------------------------------------------------------------------- 315 328 316 # Old syntax317 #getopts('a:fhi:l:m:P:p:qr:s:vV:',\%opts);318 319 329 my ($projectbuilderver,$projectbuilderrev) = pb_version_init(); 320 330 … … 326 336 "man" => \$opts{'man'}, 327 337 "verbose|v+" => \$opts{'v'}, 338 "snapshot|S" => \$opts{'S'}, 328 339 "quiet|q" => \$opts{'q'}, 329 340 "log-files|l=s" => \$opts{'l'}, … … 349 360 } 350 361 if (defined $opts{'f'}) { 351 $ force=1;362 $pbforce=1; 352 363 } 353 364 if (defined $opts{'q'}) { 354 365 $pbdebug=-1; 366 } 367 if (defined $opts{'S'}) { 368 $pbsnap=1; 355 369 } 356 370 if (defined $opts{'l'}) { … … 444 458 pb_setup_v("ve"); 445 459 } elsif ($action =~ /^setupvm$/) { 460 pb_snap_v("vm"); 461 } elsif ($action =~ /^snapve$/) { 462 pb_snap_v("ve"); 463 } elsif ($action =~ /^snapvm$/) { 446 464 pb_setup_v("vm"); 447 465 } elsif ($action =~ /^newproj$/) { … … 1017 1035 my $vmexist = shift || 0; # 0 is FALSE 1018 1036 my $vmpid = shift || 0; # 0 is FALSE 1037 my $snapme = shift || 0; # 0 is FALSE 1019 1038 1020 1039 pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n"); … … 1365 1384 pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n"); 1366 1385 if ((! $vmexist) && (($cmt eq "vm") || ($cmt eq "VMScript"))) { 1386 # If in setupvm then takes a snapshot just before halting 1387 if ($snapme != 0) { 1388 my ($vmmonport,$vmtype) = pb_conf_get("vmmonport","vmtype"); 1389 # For monitoring control 1390 if ((($vmtype->{$ENV{'PBPROJ'}}) eq "kvm") || (($vmtype->{$ENV{'PBPROJ'}}) eq "qemu")) { 1391 use Net::Telnet; 1392 my $t = new Net::Telnet (Host => "localhost", Port => $vmmonport->{$ENV{'PBPROJ'}}) || die "Unable to dialog on the monitor"; 1393 # move to monitor mode 1394 my @lines = $t->cmd("c"); 1395 # Create a snapshot named pb 1396 @lines = $t->cmd("savevm pb"); 1397 # Write the new status in the VM 1398 @lines = $t->cmd("commit all"); 1399 # End 1400 @lines = $t->cmd("quit"); 1401 } 1402 } 1367 1403 pb_system("$shcmd \"sudo /sbin/halt -p \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $v halt (pid $vmpid)"); 1368 1404 } … … 1372 1408 my $pbscript=shift; 1373 1409 my $vtype=shift; 1374 my $ force=shift || 0; # Force stop of VM. Default not1410 my $pbforce=shift || 0; # Force stop of VM. Default not 1375 1411 my $vm1=shift || undef; # Only that VM to treat 1412 my $snapme=shift || 0; # Do we have to crate a snapshot 1376 1413 my $vm; 1377 1414 my $all; 1378 1415 1379 pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$ force)\n");1416 pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$pbforce)\n"); 1380 1417 # Prepare the script to be executed on the VM 1381 1418 # in $ENV{'PBDESTDIR'}/pbscript … … 1395 1432 # Launch the VM/VE 1396 1433 if ($vtype eq "vm") { 1397 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0 );1434 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,$snapme); 1398 1435 pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n"); 1399 1436 … … 1402 1439 1403 1440 # If force stopping the VM then reset vmexist 1404 if ($ force == 1) {1441 if ($pbforce == 1) { 1405 1442 $vmpid = $vmexist; 1406 1443 $vmexist = 0; … … 1415 1452 # and launch the build through pbscript 1416 1453 pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n"); 1417 pb_send2target(uc($vtype)."Script","$v",$vmexist,$vmpid );1454 pb_send2target(uc($vtype)."Script","$v",$vmexist,$vmpid,$snapme); 1418 1455 1419 1456 } … … 1424 1461 my $v = shift; 1425 1462 my $create = shift || 0; # By default do not create a VM 1463 my $snapme = shift || 0; # By default do not create a VM 1426 1464 1427 1465 pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create)\n"); … … 1436 1474 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0)); 1437 1475 1438 my ($ptr,$vmopt,$vmpath,$vmport,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmpath","vmport","vmtmout","vmsize"); 1476 my ($ptr,$vmpath,$vmport,$vmsize,$vmmonport) = pb_conf_get("vmtype","vmpath","vmport","vmsize","vmmonport"); 1477 my ($vmopt,$vmtmout,$vmsnap) = pb_conf_get_if("vmopt","vmtmout","vmsnap"); 1439 1478 1440 1479 my $vmtype = $ptr->{$ENV{'PBPROJ'}}; … … 1452 1491 } elsif (defined $vmopt->{$ENV{'PBPROJ'}}) { 1453 1492 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/); 1493 } 1494 # Do not use snapshot feature at creation 1495 if ($create != 0) { 1496 if ((defined $vmsnap->{$v}) && ($vmsnap->{$v} =~ /true/i)) { 1497 $ENV{'PBVMOPT'} .= " -snapshot"; 1498 } elsif ((defined $vmsnap->{$ENV{'PBPROJ'}}) && ($vmsnap->{$ENV{'PBPROJ'}} =~ /true/i)) { 1499 $ENV{'PBVMOPT'} .= " -snapshot"; 1500 } elsif ($pbsnap eq 1) { 1501 $ENV{'PBVMOPT'} .= " -snapshot"; 1502 } 1503 } elsif ($snapme != 0) { 1504 if (($vmtype eq "kvm") || ($vmtype eq "qemu")) { 1505 # Configure the monitoring to automize the creation of the 'pb' snapshot 1506 $ENV{'PBVMOPT'} .= "-serial mon:telnet::$vmmonport->{$ENV{'PBPROJ'}},server,nowait "; 1507 } 1454 1508 } 1455 1509 if (defined $vmtmout->{$v}) { … … 1486 1540 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d"; 1487 1541 } 1488 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm" 1542 # Always redirect the network and always try to use a 'pb' snapshot 1543 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 -loadvm pb $vmm" 1489 1544 } elsif ($vmtype eq "xen") { 1490 1545 } elsif ($vmtype eq "vmware") { … … 1539 1594 1540 1595 my ($verpmtype) = pb_conf_get("verpmtype"); 1541 if (($create != 0) || ($verebuild->{$ENV{'PBPROJ'}} eq "true") || ($ force == 1)) {1596 if (($create != 0) || ($verebuild->{$ENV{'PBPROJ'}} eq "true") || ($pbforce == 1)) { 1542 1597 # We have to rebuild the chroot 1543 1598 if ($dtype eq "rpm") { … … 2162 2217 2163 2218 # Force shutdown of VM exept if it was already launched 2164 my $ force = 0;2219 my $pbforce = 0; 2165 2220 if ((! $vmexist) && ($vtype eq "vm")) { 2166 $ force = 1;2221 $pbforce = 1; 2167 2222 } 2168 2223 2169 pb_script2v($pbscript,$vtype,$force,$v); 2224 pb_script2v($pbscript,$vtype,$pbforce,$v); 2225 } 2226 return; 2227 } 2228 2229 # Function to create a snapshot named 'pb' for VMs/VEs 2230 sub pb_snap_v { 2231 2232 my $vtype = shift; 2233 2234 my ($vm,$all) = pb_get_v($vtype); 2235 2236 # Script generated 2237 my $pbscript = "$ENV{'PBDESTDIR'}/snapv"; 2238 2239 foreach my $v (@$vm) { 2240 # Name of the account to deal with for VM/VE 2241 # Do not use the one passed potentially with -a 2242 my ($pbac) = pb_conf_get($vtype."login"); 2243 my ($vmexist,$vmpid); 2244 2245 # Prepare the script to be executed on the VM/VE 2246 # in $ENV{'PBDESTDIR'}/setupv 2247 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript"; 2248 2249 print SCRIPT << 'EOF'; 2250 #!/bin/bash 2251 sleep 60 2252 EOF 2253 close(SCRIPT); 2254 chmod 0755,"$pbscript"; 2255 2256 # Force shutdown of VM/VE 2257 $pbforce = 1; 2258 # Force snapshot of VM/VE 2259 pb_script2v($pbscript,$vtype,$pbforce,$v,1); 2170 2260 } 2171 2261 return;
Note:
See TracChangeset
for help on using the changeset viewer.