Changeset 639 for devel/pb/bin/pb


Ignore:
Timestamp:
Dec 11, 2008, 12:30:24 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • restore PBVMOPT after modification at end of loop to get the right options each time
  • Adds pb_date_v to handle date in VMs correctly with either ntp or forced date
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r632 r639  
    13801380            $ENV{'PBVMOPT'} = "";
    13811381        }
     1382        # Save the current status for later restoration
     1383        $ENV{'PBOLDVMOPT'} = $ENV{'PBVMOPT'};
    13821384        # Set a default timeout of 2 minutes
    13831385        if (not defined $ENV{'PBVMTMOUT'}) {
     
    14291431            die "VM of type $vmtype not supported. Report to the dev team";
    14301432        }
     1433        # Restore the ENV VAR Value
     1434        $ENV{'PBMOPT'} = $ENV{'PBOLDVMOPT'};
     1435
    14311436        my ($tmpcmd,$void) = split(/ +/,$cmd);
    14321437        my $vmexist = pb_check_ps($tmpcmd,$vmm);
     
    14921497}
    14931498
     1499# Return string for date synchro
     1500sub pb_date_v {
     1501
     1502my $vtype = shift;
     1503
     1504my ($ntp) = pb_conf_get($vtype."ntp");
     1505my $vntp = $ntp->{$ENV{'PBPROJ'}};
     1506my $ntpline;
     1507
     1508if (defined $vntp) {
     1509    $ntpline = "sudo /usr/sbin/ntpdate $vntp";
     1510} else {
     1511    $ntpline = undef;
     1512}
     1513# Force new date to be in the future compared to the date
     1514# of the host by adding 1 minute
     1515my @date=pb_get_date();
     1516$date[1]++;
     1517my $upddate = strftime("%m%d%H%M%Y", @date);
     1518my $dateline = "sudo date $upddate";
     1519return($ntpline,$dateline);
     1520}
     1521
    14941522sub pb_build2v {
    14951523
     
    14981526# Prepare the script to be executed on the VM/VE
    14991527# in $ENV{'PBDESTDIR'}/pbscript
    1500 #my ($ntp) = pb_conf_get($vtype."ntp");
    1501 #my $vntp = $ntp->{$ENV{'PBPROJ'}};
    1502 
     1528my ($ntpline,$dateline) = pb_date_v($vtype);
    15031529open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
    15041530print SCRIPT "#!/bin/bash\n";
     
    15101536print SCRIPT "mv .pbrc \$HOME\n";
    15111537print SCRIPT "cd ..\n";
    1512 # Force new date to be in the future compared to the date of the tar file by adding 1 minute
    1513 my @date=pb_get_date();
    1514 $date[1]++;
    1515 my $upddate = strftime("%m%d%H%M%Y", @date);
    1516 #print SCRIPT "echo Setting up date on $vntp...\n";
    1517 # Or use ntpdate if available TBC
    1518 print SCRIPT "sudo date $upddate\n";
     1538print SCRIPT "# Time sync\n";
     1539if (defined $ntpline) {
     1540    print SCRIPT "if [ -x /usr/sbin/ntpdate ]; then\n";
     1541    print SCRIPT "  $ntpline\n";
     1542    print SCRIPT "else\n";
     1543}
     1544print SCRIPT "  $dateline\n";
     1545if (defined $ntpline) {
     1546    print SCRIPT "fi\n";
     1547}
     1548
    15191549# Get list of packages to build and get some ENV vars as well
    15201550my $ptr = pb_get_pkg();
     
    16981728my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
    16991729
     1730# Deal with date sync.
     1731my ($ntpline,$dateline) = pb_date_v($vtype);
     1732
    17001733foreach my $v (@$vm) {
    17011734    # Name of the account to deal with for VM/VE
     
    17031736    my ($pbac) = pb_conf_get($vtype."login");
    17041737    my ($key,$zero0,$zero1,$zero2);
    1705     my ($vmexist,$vmpid,$ntps);
     1738    my ($vmexist,$vmpid);
    17061739
    17071740    if ($vtype eq "vm") {
     
    17111744        my ($vmhost,$vmport,$vmntp) = pb_conf_get("vmhost","vmport","vmntp");
    17121745        my $nport = $vmport->{$ENV{'PBPROJ'}};
    1713         $ntps = $vmntp->{$ENV{'PBPROJ'}};
    17141746        $nport = "$pbport" if (defined $pbport);
    17151747   
     
    17771809
    17781810# Sync date
    1779 pb_system("/usr/sbin/ntpdate $ntps","Syncing date to $ntps");
    1780 
    1781 EOF
     1811EOF
     1812        if (defined $ntpline) {
     1813            print SCRIPT "if ( -x /usr/sbin/ntpdate ) {\n";
     1814            print SCRIPT "  system(\"$ntpline\")\n";
     1815            print SCRIPT "} else {\n";
     1816        }
     1817        print SCRIPT "  system(\"$dateline\")\n";
     1818        if (defined $ntpline) {
     1819            print SCRIPT "}\n";
     1820        }
    17821821    }
    17831822    print SCRIPT << 'EOF';
Note: See TracChangeset for help on using the changeset viewer.