Line 26... |
Line 26... |
26 |
#
|
26 |
#
|
27 |
# v1.2.0 20240826 RWR
|
27 |
# v1.2.0 20240826 RWR
|
28 |
# Added some code to migrate domains if node placed in maintenance mode
|
28 |
# Added some code to migrate domains if node placed in maintenance mode
|
29 |
# Added a lot of 'verbose' print lines, and modified for new flag structure
|
29 |
# Added a lot of 'verbose' print lines, and modified for new flag structure
|
30 |
#
|
30 |
#
|
- |
|
31 |
# v1.2.1 20240828 RWR
|
- |
|
32 |
# Fixed node maintenance, adding scanning and fixing some bugs with
|
- |
|
33 |
# the migration code
|
31 |
|
34 |
|
32 |
package node;
|
35 |
package node;
|
33 |
|
36 |
|
34 |
use warnings;
|
37 |
use warnings;
|
35 |
use strict;
|
38 |
use strict;
|
36 |
|
39 |
|
37 |
# define the version number
|
40 |
# define the version number
|
38 |
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
|
41 |
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
|
39 |
use version;
|
42 |
use version;
|
40 |
our $VERSION = version->declare("1.2.0");
|
43 |
our $VERSION = version->declare("1.2.1");
|
41 |
|
44 |
|
42 |
|
45 |
|
43 |
use Data::Dumper;
|
46 |
use Data::Dumper;
|
44 |
|
47 |
|
45 |
use Exporter;
|
48 |
use Exporter;
|
Line 158... |
Line 161... |
158 |
&update( @_ );
|
161 |
&update( @_ );
|
159 |
}
|
162 |
}
|
160 |
|
163 |
|
161 |
# put node in maintenance mode
|
164 |
# put node in maintenance mode
|
162 |
# if there are running domains on it, migrate them off first
|
165 |
# if there are running domains on it, migrate them off first
|
- |
|
166 |
# If we migrate, we must then do a force scan, which locks
|
- |
|
167 |
# the database. So, we must read the database shared first, then
|
- |
|
168 |
# only read exclusive when we are actually changing the maintenance
|
- |
|
169 |
# flag. The solution here is a kludge, but it at least works
|
- |
|
170 |
# we do the exclusive read only just before we change then write
|
163 |
sub maintenance {
|
171 |
sub maintenance {
|
164 |
my ( $node, $action ) = @_;
|
172 |
my ( $node, $action ) = @_;
|
165 |
&main::readDB(1);
|
173 |
&main::readDB();
|
166 |
my @return;
|
174 |
my @return;
|
167 |
if ( $action ) {
|
175 |
if ( $action ) {
|
- |
|
176 |
print "Found action [$action] in node.pm:maintenance\n" if $main::config->{'flags'}->{'debug'} > 1;
|
168 |
if ( lc ( $action ) eq 'on' ) {
|
177 |
if ( lc ( $action ) eq 'on' ) {
|
169 |
if ( $main::statusDB->{'nodePopulation'}->{$node}->{'running'} ) {
|
178 |
if ( keys %{$main::statusDB->{'nodePopulation'}->{$node}->{'running'} } ) {
|
170 |
# we've requested maintenance mode, but there are domains running on the node
|
179 |
# we've requested maintenance mode, but there are domains running on the node
|
- |
|
180 |
print "Found domains on $node in node.pm:maintenance\n" if $main::config->{'flags'}->{'debug'} > 1;
|
171 |
print "Trying to migrate domains off of $node before doing maintenance\n" if $main::config->{'flags'}->{'verbose'};
|
181 |
print "Trying to migrate domains off of $node before doing maintenance\n" if $main::config->{'flags'}->{'verbose'} || $main::config->{'flags'}->{'debug'} > 1;
|
172 |
push @return, &migrateAllDomains( $node, $main::config->{'flags'}->{'target'}, keys %{$main::statusDB->{'nodePopulation'}->{$node}->{'running'}} );
|
182 |
push @return, &migrateAllDomains( $node, $main::config->{'flags'}->{'target'}, keys %{$main::statusDB->{'nodePopulation'}->{$node}->{'running'}} );
|
- |
|
183 |
print "Finished migration attempt, forcing a scan\n" if $main::config->{'flags'}->{'debug'} > 1;
|
- |
|
184 |
&main::forceScan();
|
173 |
}
|
185 |
}
|
174 |
if ( $main::statusDB->{'nodePopulation'}->{$node}->{'running'} ) {
|
186 |
if ( keys %{ $main::statusDB->{'nodePopulation'}->{$node}->{'running'} } ) {
|
- |
|
187 |
print "Still found running domains on $node, aborting\n" if $main::config->{'flags'}->{'debug'} > 1;
|
175 |
push @return, "Can not mark $node in maintenance mode with running domains";
|
188 |
push @return, "Can not mark $node in maintenance mode with running domains";
|
176 |
} else {
|
189 |
} else {
|
177 |
print "Marking $node as under maintenance\n" if $main::config->{'flags'}->{'verbose'};
|
190 |
print "Marking $node as under maintenance\n" if $main::config->{'flags'}->{'verbose'} || $main::config->{'flags'}->{'debug'};
|
- |
|
191 |
&main::readDB(1);
|
178 |
$main::statusDB->{'node'}->{$node}->{'maintenance'} = 1;
|
192 |
$main::statusDB->{'node'}->{$node}->{'maintenance'} = 1;
|
- |
|
193 |
&main::writeDB();
|
179 |
}
|
194 |
}
|
180 |
} else {
|
195 |
} else {
|
181 |
print "Marking $node as Online\n" if $main::config->{'flags'}->{'verbose'};
|
196 |
print "Marking $node as Online\n" if $main::config->{'flags'}->{'verbose'} || $main::config->{'flags'}->{'debug'};
|
- |
|
197 |
&main::readDB(1);
|
182 |
$main::statusDB->{'node'}->{$node}->{'maintenance'} = 0;
|
198 |
$main::statusDB->{'node'}->{$node}->{'maintenance'} = 0;
|
- |
|
199 |
&main::writeDB();
|
183 |
}
|
200 |
}
|
184 |
}
|
201 |
}
|
185 |
&main::writeDB();
|
202 |
&main::readDB();
|
- |
|
203 |
print Dumper( $main::statusDB ) if $main::config->{'flags'}->{'debug'} > 2;
|
- |
|
204 |
# return "Maintenance set to " . ( $main::statusDB->{'node'}->{$node}->{'maintenance'} ) . "\n" .
|
186 |
return "Maintenance set to " . ( $main::statusDB->{'node'}->{$node}->{'maintenance'} ? 'On' : 'Off' ) . "\n" .
|
205 |
return "Maintenance set to " . ( $main::statusDB->{'node'}->{$node}->{'maintenance'} ? 'On' : 'Off' ) . "\n" .
|
187 |
( @return ? join( "\n", @return ) . "\n" : '');
|
206 |
( @return ? join( "\n", @return ) . "\n" : '');
|
188 |
}
|
207 |
}
|
189 |
|
208 |
|
190 |
|
209 |
|