Changeset 442


Ignore:
Timestamp:
May 15, 2008, 1:32:36 AM (11 years ago)
Author:
bruno
Message:

Adds support for multi VM for setupvm command (took way too much time to debug, I'm really tired :-()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r437 r442  
    791791    my $vmpid = shift || 0;             # 0 is FALSE
    792792
     793    pb_log(2,"DEBUG: pb_send2target($cmt,$v,$vmexist,$vmpid)\n");
    793794    my $host = "sshhost";
    794795    my $login = "sshlogin";
     
    10271028        pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
    10281029        pb_send2target("Packages",$odir."-".$over."-".$oarch,$vmexist,$vmpid);
    1029         if ((! $vmexist) && ($cmt eq "vm")) {
    1030             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)");
    1031         }
    10321030        pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
     1031    }
     1032    pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
     1033    if ((! $vmexist) && (($cmt eq "vm") || ($cmt eq "Script"))) {
     1034        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)");
    10331035    }
    10341036}
     
    10371039    my $pbscript=shift;
    10381040    my $vtype=shift;
    1039 
     1041    my $force=shift || 0;   # Force stop of VM. Default not
     1042    my $vm1=shift || undef; # Only that VM to treat
     1043    my $vm;
     1044    my $all;
     1045
     1046    pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$force,$vm1)\n");
    10401047    # Prepare the script to be executed on the VM
    10411048    # in $ENV{'PBDESTDIR'}/pbscript
     
    10451052    }
    10461053
    1047     my ($vm,$all) = pb_get_v($vtype);
     1054    if (not defined $vm1) {
     1055        ($vm,$all) = pb_get_v($vtype);
     1056    } else {
     1057        @$vm = ($vm1);
     1058    }
    10481059    my ($vmexist,$vmpid) = (undef,undef);
    10491060
     
    10521063        if ($vtype eq "vm") {
    10531064            ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
     1065            pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
    10541066
    10551067            # Skip that VM if something went wrong
    1056             next if (($vmpid == 0) && ($vmexist ==0));
     1068            next if (($vmpid == 0) && ($vmexist == 0));
     1069
     1070            # If force stopping the VM then reset vmexist
     1071            if ($force == 1) {
     1072                $vmpid = $vmexist;
     1073                $vmexist = 0;
     1074            }
    10571075        }
    10581076
    10591077        # Gather all required files to send them to the VM
    10601078        # and launch the build through pbscript
     1079        pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
    10611080        pb_send2target("Script","$v",$vmexist,$vmpid);
    10621081
     
    10691088    my $create = shift || 0;        # By default do not create a VM
    10701089
     1090    pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create)\n");
    10711091    die "No VM/VE defined, unable to launch" if (not defined $v);
    10721092    # Keep only the first VM in case many were given
     
    11441164            pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
    11451165        }
     1166        pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
    11461167        return($vmexist,$vmpid);
    11471168    # VE here
     
    13831404
    13841405        # Skip that VM if something went wrong
    1385         return if (($vmpid == 0) && ($vmexist == 0));
     1406        next if (($vmpid == 0) && ($vmexist == 0));
    13861407   
    13871408        # Store the pub key part in a variable
     
    15331554system "pb 2>&1 | head -5";
    15341555EOF
    1535     if ((! $vmexist) && ($vtype eq "vm")) {
    1536         print SCRIPT << 'EOF';
    1537 pb_system("sudo /sbin/halt -p","Halting the VM");
    1538 EOF
    1539     }
    1540    
    15411556    # Adds pb_distro_init from ProjectBuilder::Distribution
    15421557    foreach my $d (@INC) {
     
    15591574    chmod 0755,"$pbscript";
    15601575
    1561     # That build script needs to be run as root
     1576    # That build script needs to be run as root and force stop of VM at end
    15621577    $pbaccount = "root";
    1563     pb_script2v($pbscript,$vtype);
     1578
     1579    # Force shutdown of VM exept if it was already launched
     1580    my $force = 0;
     1581    if ((! $vmexist) && ($vtype eq "vm")) {
     1582        $force = 1;
     1583    }
     1584   
     1585    pb_script2v($pbscript,$vtype,$force,$v);
    15641586}
    15651587return;
Note: See TracChangeset for help on using the changeset viewer.