diff --git a/db/Node.pm.in b/db/Node.pm.in index da9998c2209d7f81df1392a0c014f458c2551ee2..d1028da7d476fc09dc35b9402089c52b8614d473 100755 --- a/db/Node.pm.in +++ b/db/Node.pm.in @@ -1965,7 +1965,8 @@ sub ClearBootAttributes($) my $node_id = (ref($self) ? $self->node_id() : $self); my $allocFreeState = TBDB_ALLOCSTATE_FREE_DIRTY(); - DBQueryWarn("update nodes set startupcmd='',rpms='',deltas='', ". + DBQueryWarn("update nodes set ". + "startupcmd='',startstatus='none',rpms='',deltas='', ". "tarballs='',failureaction='fatal', routertype='none', ". "def_boot_cmd_line='',next_boot_cmd_line='', ". "temp_boot_osid=NULL,next_boot_osid=NULL, ". @@ -2341,6 +2342,60 @@ sub ResetStartStatus($) return $self->Update({"startstatus" => 'none'}); } +# +# Return the node startupcmd and status fields. +# +sub GetStartupCmd($) +{ + my ($self) = @_; + + my $oldcmd = $self->startupcmd(); + my $oldstatus = $self->startstatus(); + + return ($oldcmd, $oldstatus); +} + +# +# Set the node startupcmd field to the given value or the value +# in the virt_nodes table entry if no value is given. +# +sub SetStartupCmd($$$) +{ + my ($self, $cmd, $status) = @_; + $status = 'none' if (!defined($status)); + my $node_id = $self->node_id(); + + if (!$cmd) { + # Get value from virt_nodes + my $result = + DBQueryWarn("select v.startupcmd ". + " from virt_nodes as v, reserved as r ". + " where v.exptidx=r.exptidx and v.vname=r.vname ". + " and r.node_id='$node_id'"); + if ($result && $result->numrows > 0) { + ($cmd) = $result->fetchrow_array(); + } + } + if ($cmd) { + $self->Update({'startupcmd' => $cmd, 'startstatus' => $status}); + } +} + +# +# Clear the node startupcmd and status fields. +# Returns the old command and status. +# +sub ClearStartupCmd($) +{ + my ($self) = @_; + + my $oldcmd = $self->startupcmd(); + my $oldstatus = $self->startstatus(); + + $self->Update({'startupcmd' => '', 'startstatus' => 'none'}); + return ($oldcmd, $oldstatus); +} + # # Create new vnodes. The argument is a reference; to a a hash of options to # be used when creating the new node(s). A list of the node names is diff --git a/tbsetup/libimageops_ndz.pm.in b/tbsetup/libimageops_ndz.pm.in index 87c01afd418d7268a6849e8ccf0904d6c22c3278..018df44d750f8ea035f15b0ee8b1bca517c6a158 100644 --- a/tbsetup/libimageops_ndz.pm.in +++ b/tbsetup/libimageops_ndz.pm.in @@ -706,7 +706,7 @@ sub DoCapture($$$$) { $EUID = $UID = 0; my $cmd = "$TB/bin/sshtb -n -o ConnectTimeout=10 ". "-host $node_id touch /var/run/updatemasterpasswdfiles"; - print STDERR "About to: '$cmd'\n" if ($debug); + print STDERR "About to: '$cmd'\n" if ($self->debug()); system($cmd); if ($?) { $msg = "'$cmd' failed"; @@ -734,7 +734,7 @@ sub DoCapture($$$$) { # my $cmd = "$TB/bin/sshtb -n -o ConnectTimeout=10 ". "-host $node_id $REBOOT_PREPARE"; - print STDERR "About to: '$cmd'\n" if ($debug); + print STDERR "About to: '$cmd'\n" if ($self->debug()); system($cmd); if ($?) { $msg = "'$cmd' failed"; @@ -936,6 +936,15 @@ sub DoCapture($$$$) { goto out2; } + # + # Restore the startupcmd. + # Note that we need to do this after the MfsSelect call above. + # XXX we just restore the "default" startup command from virt_nodes + # + $node->SetStartupCmd(); + print STDERR "Restored startup cmd from virt_nodes for $node_id\n" + if ($self->debug()); + %args = (); $args{'name'} = $me; $args{'on'} = 0; diff --git a/utils/create_image.in b/utils/create_image.in index 27b657a8d3de5b86cd3525270ddefcf55fbbede2..aede7385170a252a65afdac94ea50e6d73ee9d4c 100644 --- a/utils/create_image.in +++ b/utils/create_image.in @@ -1672,6 +1672,15 @@ sub cleanup () return 0; } + # + # Restore the startupcmd. + # Note that we need to do this after the MfsSelect call above. + # XXX we just restore the "default" startup command from virt_nodes + # + $node->SetStartupCmd(); + print STDERR "Restored startup cmd from virt_nodes for $node_id\n" + if ($debug); + %args = (); $args{'name'} = $me; $args{'on'} = 0; diff --git a/utils/node_admin.in b/utils/node_admin.in index 15d9709893c451534756c17b9940fa2acb2d0e71..e014b5eea8e0efa3f7573460fda33160cdb245c6 100755 --- a/utils/node_admin.in +++ b/utils/node_admin.in @@ -1,6 +1,6 @@ #!/usr/bin/perl -wT # -# Copyright (c) 2000-2009 University of Utah and the Flux Group. +# Copyright (c) 2000-2018 University of Utah and the Flux Group. # # {{{EMULAB-LICENSE # @@ -212,6 +212,14 @@ if ($runcmd ne "") { " Could not turn admin mode off for @bad!\n"); } + # + # Restore the startupcmd from the virt_nodes table since MfsRunCmd() + # cleared it. We need to do this after the MfsSelect call above. + # + foreach my $node (@nodes) { + $node->SetStartupCmd(); + } + if ($reboot) { %args = (); $args{'name'} = $0; @@ -233,6 +241,16 @@ if (TBAdminMfsSelect(\%args, \@bad, @nodeids)) { die("*** $0:\n". " Could not turn admin mode $onoff for @bad!\n"); } + +# +# If turning off admin mode, reset the startupcmd. +# +if ($onoff eq "off") { + foreach my $node (@nodes) { + $node->SetStartupCmd(); + } +} + if ($reboot) { %args = (); $args{'name'} = $0;