]>
Commit | Line | Data |
---|---|---|
4177a14d TL |
1 | package PVE::CLI::pve6to7; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::API2::APT; | |
7 | use PVE::API2::Ceph; | |
8 | use PVE::API2::LXC; | |
9 | use PVE::API2::Qemu; | |
10 | use PVE::API2::Certificates; | |
3bc032ad | 11 | use PVE::API2::Cluster::Ceph; |
4177a14d | 12 | |
5b3bad37 | 13 | use PVE::AccessControl; |
4177a14d TL |
14 | use PVE::Ceph::Tools; |
15 | use PVE::Cluster; | |
16 | use PVE::Corosync; | |
17 | use PVE::INotify; | |
18 | use PVE::JSONSchema; | |
84006d1f | 19 | use PVE::NodeConfig; |
4177a14d TL |
20 | use PVE::RPCEnvironment; |
21 | use PVE::Storage; | |
d12bbda5 | 22 | use PVE::Storage::Plugin; |
5b3bad37 | 23 | use PVE::Tools qw(run_command split_list); |
84006d1f | 24 | use PVE::QemuConfig; |
4177a14d | 25 | use PVE::QemuServer; |
e522a2db | 26 | use PVE::VZDump::Common; |
9f5f9819 SI |
27 | use PVE::LXC; |
28 | use PVE::LXC::Config; | |
29 | use PVE::LXC::Setup; | |
4177a14d TL |
30 | |
31 | use Term::ANSIColor; | |
32 | ||
33 | use PVE::CLIHandler; | |
34 | ||
35 | use base qw(PVE::CLIHandler); | |
36 | ||
37 | my $nodename = PVE::INotify::nodename(); | |
38 | ||
39 | sub setup_environment { | |
40 | PVE::RPCEnvironment->setup_default_cli_env(); | |
41 | } | |
42 | ||
43 | my $min_pve_major = 6; | |
44 | my $min_pve_minor = 4; | |
45 | my $min_pve_pkgrel = 1; | |
46 | ||
47 | my $counters = { | |
48 | pass => 0, | |
49 | skip => 0, | |
50 | warn => 0, | |
51 | fail => 0, | |
52 | }; | |
53 | ||
54 | my $log_line = sub { | |
55 | my ($level, $line) = @_; | |
56 | ||
57 | $counters->{$level}++ if defined($level) && defined($counters->{$level}); | |
58 | ||
59 | print uc($level), ': ' if defined($level); | |
60 | print "$line\n"; | |
61 | }; | |
62 | ||
63 | sub log_pass { | |
64 | print color('green'); | |
65 | $log_line->('pass', @_); | |
66 | print color('reset'); | |
67 | } | |
68 | ||
69 | sub log_info { | |
70 | $log_line->('info', @_); | |
71 | } | |
72 | sub log_skip { | |
73 | $log_line->('skip', @_); | |
74 | } | |
75 | sub log_warn { | |
76 | print color('yellow'); | |
77 | $log_line->('warn', @_); | |
78 | print color('reset'); | |
79 | } | |
80 | sub log_fail { | |
81 | print color('red'); | |
82 | $log_line->('fail', @_); | |
83 | print color('reset'); | |
84 | } | |
85 | ||
86 | my $print_header_first = 1; | |
87 | sub print_header { | |
88 | my ($h) = @_; | |
89 | print "\n" if !$print_header_first; | |
90 | print "= $h =\n\n"; | |
91 | $print_header_first = 0; | |
92 | } | |
93 | ||
94 | my $get_systemd_unit_state = sub { | |
95 | my ($unit) = @_; | |
96 | ||
97 | my $state; | |
98 | my $filter_output = sub { | |
99 | $state = shift; | |
100 | chomp $state; | |
101 | }; | |
102 | eval { | |
103 | run_command(['systemctl', 'is-enabled', "$unit"], outfunc => $filter_output, noerr => 1); | |
104 | return if !defined($state); | |
105 | run_command(['systemctl', 'is-active', "$unit"], outfunc => $filter_output, noerr => 1); | |
106 | }; | |
107 | ||
108 | return $state // 'unknown'; | |
109 | }; | |
110 | my $log_systemd_unit_state = sub { | |
111 | my ($unit, $no_fail_on_inactive) = @_; | |
112 | ||
113 | my $log_method = \&log_warn; | |
114 | ||
115 | my $state = $get_systemd_unit_state->($unit); | |
116 | if ($state eq 'active') { | |
117 | $log_method = \&log_pass; | |
118 | } elsif ($state eq 'inactive') { | |
119 | $log_method = $no_fail_on_inactive ? \&log_warn : \&log_fail; | |
120 | } elsif ($state eq 'failed') { | |
121 | $log_method = \&log_fail; | |
122 | } | |
123 | ||
124 | $log_method->("systemd unit '$unit' is in state '$state'"); | |
125 | }; | |
126 | ||
127 | my $versions; | |
128 | my $get_pkg = sub { | |
129 | my ($pkg) = @_; | |
130 | ||
131 | $versions = eval { PVE::API2::APT->versions({ node => $nodename }) } if !defined($versions); | |
132 | ||
133 | if (!defined($versions)) { | |
134 | my $msg = "unable to retrieve package version information"; | |
135 | $msg .= "- $@" if $@; | |
136 | log_fail("$msg"); | |
137 | return undef; | |
138 | } | |
139 | ||
140 | my $pkgs = [ grep { $_->{Package} eq $pkg } @$versions ]; | |
141 | if (!defined $pkgs || $pkgs == 0) { | |
142 | log_fail("unable to determine installed $pkg version."); | |
143 | return undef; | |
144 | } else { | |
145 | return $pkgs->[0]; | |
146 | } | |
147 | }; | |
148 | ||
149 | sub check_pve_packages { | |
150 | print_header("CHECKING VERSION INFORMATION FOR PVE PACKAGES"); | |
151 | ||
152 | print "Checking for package updates..\n"; | |
153 | my $updates = eval { PVE::API2::APT->list_updates({ node => $nodename }); }; | |
154 | if (!defined($updates)) { | |
155 | log_warn("$@") if $@; | |
156 | log_fail("unable to retrieve list of package updates!"); | |
157 | } elsif (@$updates > 0) { | |
158 | my $pkgs = join(', ', map { $_->{Package} } @$updates); | |
159 | log_warn("updates for the following packages are available:\n $pkgs"); | |
160 | } else { | |
161 | log_pass("all packages uptodate"); | |
162 | } | |
163 | ||
164 | print "\nChecking proxmox-ve package version..\n"; | |
165 | if (defined(my $proxmox_ve = $get_pkg->('proxmox-ve'))) { | |
166 | my $min_pve_ver = "$min_pve_major.$min_pve_minor-$min_pve_pkgrel"; | |
167 | ||
168 | my ($maj, $min, $pkgrel) = $proxmox_ve->{OldVersion} =~ m/^(\d+)\.(\d+)-(\d+)/; | |
169 | ||
170 | my $upgraded = 0; | |
171 | ||
172 | if ($maj > $min_pve_major) { | |
173 | log_pass("already upgraded to Proxmox VE " . ($min_pve_major + 1)); | |
174 | $upgraded = 1; | |
175 | } elsif ($maj >= $min_pve_major && $min >= $min_pve_minor && $pkgrel >= $min_pve_pkgrel) { | |
176 | log_pass("proxmox-ve package has version >= $min_pve_ver"); | |
177 | } else { | |
178 | log_fail("proxmox-ve package is too old, please upgrade to >= $min_pve_ver!"); | |
179 | } | |
180 | ||
181 | my ($krunning, $kinstalled) = (qr/5\.11/, 'pve-kernel-5.11'); | |
182 | if (!$upgraded) { | |
183 | ($krunning, $kinstalled) = (qr/5\.(?:4|11)/, 'pve-kernel-4.15'); | |
184 | } | |
185 | ||
186 | print "\nChecking running kernel version..\n"; | |
187 | my $kernel_ver = $proxmox_ve->{RunningKernel}; | |
188 | if (!defined($kernel_ver)) { | |
189 | log_fail("unable to determine running kernel version."); | |
190 | } elsif ($kernel_ver =~ /^$krunning/) { | |
191 | log_pass("expected running kernel '$kernel_ver'."); | |
192 | } elsif ($get_pkg->($kinstalled)) { | |
193 | log_warn("expected kernel '$kinstalled' intalled but not yet rebooted!"); | |
194 | } else { | |
195 | log_warn("unexpected running and installed kernel '$kernel_ver'."); | |
196 | } | |
197 | } else { | |
198 | log_fail("proxmox-ve package not found!"); | |
199 | } | |
200 | } | |
201 | ||
202 | ||
203 | sub check_storage_health { | |
204 | print_header("CHECKING CONFIGURED STORAGES"); | |
205 | my $cfg = PVE::Storage::config(); | |
206 | ||
207 | my $ctime = time(); | |
208 | ||
209 | my $info = PVE::Storage::storage_info($cfg); | |
210 | ||
23315349 | 211 | foreach my $storeid (sort keys %$info) { |
4177a14d TL |
212 | my $d = $info->{$storeid}; |
213 | if ($d->{enabled}) { | |
214 | if ($d->{type} eq 'sheepdog') { | |
215 | log_fail("storage '$storeid' of type 'sheepdog' is enabled - experimental sheepdog support dropped in PVE 6") | |
216 | } elsif ($d->{active}) { | |
217 | log_pass("storage '$storeid' enabled and active."); | |
218 | } else { | |
219 | log_warn("storage '$storeid' enabled but not active!"); | |
220 | } | |
221 | } else { | |
222 | log_skip("storage '$storeid' disabled."); | |
223 | } | |
224 | } | |
225 | } | |
226 | ||
227 | sub check_cluster_corosync { | |
228 | print_header("CHECKING CLUSTER HEALTH/SETTINGS"); | |
229 | ||
230 | if (!PVE::Corosync::check_conf_exists(1)) { | |
231 | log_skip("standalone node."); | |
232 | return; | |
233 | } | |
234 | ||
235 | $log_systemd_unit_state->('pve-cluster.service'); | |
236 | $log_systemd_unit_state->('corosync.service'); | |
237 | ||
238 | if (PVE::Cluster::check_cfs_quorum(1)) { | |
239 | log_pass("Cluster Filesystem is quorate."); | |
240 | } else { | |
241 | log_fail("Cluster Filesystem readonly, lost quorum?!"); | |
242 | } | |
243 | ||
244 | my $conf = PVE::Cluster::cfs_read_file('corosync.conf'); | |
245 | my $conf_nodelist = PVE::Corosync::nodelist($conf); | |
246 | my $node_votes = 0; | |
247 | ||
248 | print "\nAnalzying quorum settings and state..\n"; | |
249 | if (!defined($conf_nodelist)) { | |
250 | log_fail("unable to retrieve nodelist from corosync.conf"); | |
251 | } else { | |
252 | if (grep { $conf_nodelist->{$_}->{quorum_votes} != 1 } keys %$conf_nodelist) { | |
253 | log_warn("non-default quorum_votes distribution detected!"); | |
254 | } | |
255 | map { $node_votes += $conf_nodelist->{$_}->{quorum_votes} // 0 } keys %$conf_nodelist; | |
256 | } | |
257 | ||
258 | my ($expected_votes, $total_votes); | |
259 | my $filter_output = sub { | |
260 | my $line = shift; | |
261 | ($expected_votes) = $line =~ /^Expected votes:\s*(\d+)\s*$/ | |
262 | if !defined($expected_votes); | |
263 | ($total_votes) = $line =~ /^Total votes:\s*(\d+)\s*$/ | |
264 | if !defined($total_votes); | |
265 | }; | |
266 | eval { | |
267 | run_command(['corosync-quorumtool', '-s'], outfunc => $filter_output, noerr => 1); | |
268 | }; | |
269 | ||
270 | if (!defined($expected_votes)) { | |
271 | log_fail("unable to get expected number of votes, setting to 0."); | |
272 | $expected_votes = 0; | |
273 | } | |
274 | if (!defined($total_votes)) { | |
275 | log_fail("unable to get expected number of votes, setting to 0."); | |
276 | $total_votes = 0; | |
277 | } | |
278 | ||
279 | my $cfs_nodelist = PVE::Cluster::get_clinfo()->{nodelist}; | |
280 | my $offline_nodes = grep { $cfs_nodelist->{$_}->{online} != 1 } keys %$cfs_nodelist; | |
281 | if ($offline_nodes > 0) { | |
282 | log_fail("$offline_nodes nodes are offline!"); | |
283 | } | |
284 | ||
285 | my $qdevice_votes = 0; | |
286 | if (my $qdevice_setup = $conf->{main}->{quorum}->{device}) { | |
287 | $qdevice_votes = $qdevice_setup->{votes} // 1; | |
288 | } | |
289 | ||
290 | log_info("configured votes - nodes: $node_votes"); | |
291 | log_info("configured votes - qdevice: $qdevice_votes"); | |
292 | log_info("current expected votes: $expected_votes"); | |
293 | log_info("current total votes: $total_votes"); | |
294 | ||
295 | log_warn("expected votes set to non-standard value '$expected_votes'.") | |
296 | if $expected_votes != $node_votes + $qdevice_votes; | |
297 | log_warn("total votes < expected votes: $total_votes/$expected_votes!") | |
298 | if $total_votes < $expected_votes; | |
299 | ||
300 | my $conf_nodelist_count = scalar(keys %$conf_nodelist); | |
301 | my $cfs_nodelist_count = scalar(keys %$cfs_nodelist); | |
302 | log_warn("cluster consists of less than three quorum-providing nodes!") | |
303 | if $conf_nodelist_count < 3 && $conf_nodelist_count + $qdevice_votes < 3; | |
304 | ||
305 | log_fail("corosync.conf ($conf_nodelist_count) and pmxcfs ($cfs_nodelist_count) don't agree about size of nodelist.") | |
306 | if $conf_nodelist_count != $cfs_nodelist_count; | |
307 | ||
308 | print "\nChecking nodelist entries..\n"; | |
23db33ca | 309 | my $nodelist_pass = 1; |
4177a14d TL |
310 | for my $cs_node (sort keys %$conf_nodelist) { |
311 | my $entry = $conf_nodelist->{$cs_node}; | |
23db33ca FG |
312 | if (!defined($entry->{name})) { |
313 | $nodelist_pass = 0; | |
314 | log_fail("$cs_node: no name entry in corosync.conf."); | |
315 | } | |
316 | if (!defined($entry->{nodeid})) { | |
317 | $nodelist_pass = 0; | |
318 | log_fail("$cs_node: no nodeid configured in corosync.conf."); | |
319 | } | |
4177a14d TL |
320 | my $gotLinks = 0; |
321 | for my $link (0..7) { | |
322 | $gotLinks++ if defined($entry->{"ring${link}_addr"}); | |
323 | } | |
23db33ca FG |
324 | if ($gotLinks <= 0) { |
325 | $nodelist_pass = 0; | |
326 | log_fail("$cs_node: no ringX_addr (0 <= X <= 7) link defined in corosync.conf."); | |
327 | } | |
4177a14d TL |
328 | |
329 | my $verify_ring_ip = sub { | |
330 | my $key = shift; | |
331 | if (defined(my $ring = $entry->{$key})) { | |
332 | my ($resolved_ip, undef) = PVE::Corosync::resolve_hostname_like_corosync($ring, $conf); | |
333 | if (defined($resolved_ip)) { | |
334 | if ($resolved_ip ne $ring) { | |
23db33ca | 335 | $nodelist_pass = 0; |
4177a14d | 336 | log_warn("$cs_node: $key '$ring' resolves to '$resolved_ip'.\n Consider replacing it with the currently resolved IP address."); |
4177a14d TL |
337 | } |
338 | } else { | |
23db33ca | 339 | $nodelist_pass = 0; |
4177a14d TL |
340 | log_fail("$cs_node: unable to resolve $key '$ring' to an IP address according to Corosync's resolve strategy - cluster will potentially fail with Corosync 3.x/kronosnet!"); |
341 | } | |
342 | } | |
343 | }; | |
344 | for my $link (0..7) { | |
345 | $verify_ring_ip->("ring${link}_addr"); | |
346 | } | |
347 | } | |
23db33ca | 348 | log_pass("nodelist settings OK") if $nodelist_pass; |
4177a14d TL |
349 | |
350 | print "\nChecking totem settings..\n"; | |
351 | my $totem = $conf->{main}->{totem}; | |
23db33ca FG |
352 | my $totem_pass = 1; |
353 | ||
4177a14d TL |
354 | my $transport = $totem->{transport}; |
355 | if (defined($transport)) { | |
356 | if ($transport ne 'knet') { | |
23db33ca | 357 | $totem_pass = 0; |
4177a14d | 358 | log_fail("Corosync transport explicitly set to '$transport' instead of implicit default!"); |
4177a14d | 359 | } |
4177a14d TL |
360 | } |
361 | ||
362 | # TODO: are those values still up-to-date? | |
363 | if ((!defined($totem->{secauth}) || $totem->{secauth} ne 'on') && (!defined($totem->{crypto_cipher}) || $totem->{crypto_cipher} eq 'none')) { | |
23db33ca | 364 | $totem_pass = 0; |
4177a14d | 365 | log_fail("Corosync authentication/encryption is not explicitly enabled (secauth / crypto_cipher / crypto_hash)!"); |
23db33ca FG |
366 | } elsif (defined($totem->{crypto_cipher}) && $totem->{crypto_cipher} eq '3des') { |
367 | $totem_pass = 0; | |
368 | log_fail("Corosync encryption cipher set to '3des', no longer supported in Corosync 3.x!"); # FIXME: can be removed? | |
4177a14d TL |
369 | } |
370 | ||
23db33ca | 371 | log_pass("totem settings OK") if $totem_pass; |
4177a14d TL |
372 | print "\n"; |
373 | log_info("run 'pvecm status' to get detailed cluster status.."); | |
374 | ||
4177a14d TL |
375 | if (defined(my $corosync = $get_pkg->('corosync'))) { |
376 | if ($corosync->{OldVersion} =~ m/^2\./) { | |
23db33ca FG |
377 | log_fail("\ncorosync 2.x installed, cluster-wide upgrade to 3.x needed!"); |
378 | } elsif ($corosync->{OldVersion} !~ m/^3\./) { | |
379 | log_fail("\nunexpected corosync version installed: $corosync->{OldVersion}!"); | |
4177a14d TL |
380 | } |
381 | } | |
382 | } | |
383 | ||
384 | sub check_ceph { | |
385 | print_header("CHECKING HYPER-CONVERGED CEPH STATUS"); | |
386 | ||
387 | if (PVE::Ceph::Tools::check_ceph_inited(1)) { | |
388 | log_info("hyper-converged ceph setup detected!"); | |
389 | } else { | |
390 | log_skip("no hyper-converged ceph setup detected!"); | |
391 | return; | |
392 | } | |
393 | ||
394 | log_info("getting Ceph status/health information.."); | |
395 | my $ceph_status = eval { PVE::API2::Ceph->status({ node => $nodename }); }; | |
3bc032ad FG |
396 | my $noout = eval { PVE::API2::Cluster::Ceph->get_flag({ flag => "noout" }); }; |
397 | if ($@) { | |
398 | log_fail("failed to get 'noout' flag status - $@"); | |
399 | } | |
400 | ||
4177a14d | 401 | my $noout_wanted = 1; |
4177a14d TL |
402 | |
403 | if (!$ceph_status || !$ceph_status->{health}) { | |
404 | log_fail("unable to determine Ceph status!"); | |
405 | } else { | |
406 | my $ceph_health = $ceph_status->{health}->{status}; | |
407 | if (!$ceph_health) { | |
408 | log_fail("unable to determine Ceph health!"); | |
409 | } elsif ($ceph_health eq 'HEALTH_OK') { | |
410 | log_pass("Ceph health reported as 'HEALTH_OK'."); | |
411 | } elsif ($ceph_health eq 'HEALTH_WARN' && $noout && (keys %{$ceph_status->{health}->{checks}} == 1)) { | |
412 | log_pass("Ceph health reported as 'HEALTH_WARN' with a single failing check and 'noout' flag set."); | |
413 | } else { | |
414 | log_warn("Ceph health reported as '$ceph_health'.\n Use the PVE ". | |
415 | "dashboard or 'ceph -s' to determine the specific issues and try to resolve them."); | |
416 | } | |
417 | } | |
418 | ||
4177a14d TL |
419 | # TODO: check OSD min-required version, if to low it breaks stuff! |
420 | ||
421 | log_info("getting Ceph daemon versions.."); | |
422 | my $ceph_versions = eval { PVE::Ceph::Tools::get_cluster_versions(undef, 1); }; | |
423 | if (!$ceph_versions) { | |
424 | log_fail("unable to determine Ceph daemon versions!"); | |
425 | } else { | |
426 | my $services = [ | |
427 | { 'key' => 'mon', 'name' => 'monitor' }, | |
428 | { 'key' => 'mgr', 'name' => 'manager' }, | |
429 | { 'key' => 'mds', 'name' => 'MDS' }, | |
430 | { 'key' => 'osd', 'name' => 'OSD' }, | |
431 | ]; | |
432 | ||
433 | foreach my $service (@$services) { | |
434 | my $name = $service->{name}; | |
435 | if (my $service_versions = $ceph_versions->{$service->{key}}) { | |
436 | if (keys %$service_versions == 0) { | |
437 | log_skip("no running instances detected for daemon type $name."); | |
438 | } elsif (keys %$service_versions == 1) { | |
439 | log_pass("single running version detected for daemon type $name."); | |
440 | } else { | |
441 | log_warn("multiple running versions detected for daemon type $name!"); | |
442 | } | |
443 | } else { | |
444 | log_skip("unable to determine versions of running Ceph $name instances."); | |
445 | } | |
446 | } | |
447 | ||
448 | my $overall_versions = $ceph_versions->{overall}; | |
449 | if (!$overall_versions) { | |
450 | log_warn("unable to determine overall Ceph daemon versions!"); | |
451 | } elsif (keys %$overall_versions == 1) { | |
452 | log_pass("single running overall version detected for all Ceph daemon types."); | |
6d451a4b | 453 | $noout_wanted = 0; # off post-upgrade, on pre-upgrade |
4177a14d TL |
454 | } else { |
455 | log_warn("overall version mismatch detected, check 'ceph versions' output for details!"); | |
456 | } | |
457 | } | |
458 | ||
459 | if ($noout) { | |
460 | if ($noout_wanted) { | |
461 | log_pass("'noout' flag set to prevent rebalancing during cluster-wide upgrades."); | |
462 | } else { | |
463 | log_warn("'noout' flag set, Ceph cluster upgrade seems finished."); | |
464 | } | |
465 | } elsif ($noout_wanted) { | |
466 | log_warn("'noout' flag not set - recommended to prevent rebalancing during upgrades."); | |
467 | } | |
468 | ||
469 | log_info("checking Ceph config.."); | |
470 | my $conf = PVE::Cluster::cfs_read_file('ceph.conf'); | |
471 | if (%$conf) { | |
472 | my $global = $conf->{global}; | |
473 | ||
474 | my $global_monhost = $global->{mon_host} // $global->{"mon host"} // $global->{"mon-host"}; | |
475 | if (!defined($global_monhost)) { | |
476 | log_warn("No 'mon_host' entry found in ceph config.\n It's recommended to add mon_host with all monitor addresses (without ports) to the global section."); | |
4177a14d TL |
477 | } |
478 | ||
479 | my $ipv6 = $global->{ms_bind_ipv6} // $global->{"ms bind ipv6"} // $global->{"ms-bind-ipv6"}; | |
480 | if ($ipv6) { | |
481 | my $ipv4 = $global->{ms_bind_ipv4} // $global->{"ms bind ipv4"} // $global->{"ms-bind-ipv4"}; | |
482 | if ($ipv6 eq 'true' && (!defined($ipv4) || $ipv4 ne 'false')) { | |
483 | log_warn("'ms_bind_ipv6' is enabled but 'ms_bind_ipv4' is not disabled.\n Make sure to disable 'ms_bind_ipv4' for ipv6 only clusters, or add an ipv4 network to public/cluster network."); | |
4177a14d | 484 | } |
4177a14d TL |
485 | } |
486 | ||
487 | if (defined($global->{keyring})) { | |
488 | log_warn("[global] config section contains 'keyring' option, which will prevent services from starting with Nautilus.\n Move 'keyring' option to [client] section instead."); | |
4177a14d TL |
489 | } |
490 | ||
491 | } else { | |
492 | log_warn("Empty ceph config found"); | |
493 | } | |
494 | ||
495 | my $local_ceph_ver = PVE::Ceph::Tools::get_local_version(1); | |
496 | if (defined($local_ceph_ver)) { | |
a2e5da3f FG |
497 | if ($local_ceph_ver <= 14) { |
498 | log_fail("local Ceph version too low, at least Octopus required.."); | |
4177a14d TL |
499 | } |
500 | } else { | |
501 | log_fail("unable to determine local Ceph version."); | |
502 | } | |
503 | } | |
504 | ||
e522a2db FE |
505 | sub check_backup_retention_settings { |
506 | log_info("Checking backup retention settings.."); | |
507 | ||
508 | my $pass = 1; | |
509 | ||
510 | my $node_has_retention; | |
511 | ||
512 | my $maxfiles_msg = "parameter 'maxfiles' is deprecated with PVE 7.x and will be removed in a " . | |
513 | "future version, use 'prune-backups' instead."; | |
514 | ||
515 | eval { | |
516 | my $confdesc = PVE::VZDump::Common::get_confdesc(); | |
517 | ||
518 | my $fn = "/etc/vzdump.conf"; | |
519 | my $raw = PVE::Tools::file_get_contents($fn); | |
520 | ||
521 | my $conf_schema = { type => 'object', properties => $confdesc, }; | |
522 | my $param = PVE::JSONSchema::parse_config($conf_schema, $fn, $raw); | |
523 | ||
524 | if (defined($param->{maxfiles})) { | |
525 | $pass = 0; | |
526 | log_warn("$fn - $maxfiles_msg"); | |
527 | } | |
528 | ||
529 | $node_has_retention = defined($param->{maxfiles}) || defined($param->{'prune-backups'}); | |
530 | }; | |
531 | if (my $err = $@) { | |
532 | $pass = 0; | |
533 | log_warn("unable to parse node's VZDump configuration - $err"); | |
534 | } | |
535 | ||
536 | my $storage_cfg = PVE::Storage::config(); | |
537 | ||
538 | for my $storeid (keys $storage_cfg->{ids}->%*) { | |
539 | my $scfg = $storage_cfg->{ids}->{$storeid}; | |
540 | ||
541 | if (defined($scfg->{maxfiles})) { | |
542 | $pass = 0; | |
543 | log_warn("storage '$storeid' - $maxfiles_msg"); | |
544 | } | |
545 | ||
546 | next if !$scfg->{content}->{backup}; | |
547 | next if defined($scfg->{maxfiles}) || defined($scfg->{'prune-backups'}); | |
548 | next if $node_has_retention; | |
549 | ||
550 | log_info("storage '$storeid' - no backup retention settings defined - by default, PVE " . | |
551 | "7.x will no longer keep only the last backup, but all backups"); | |
552 | } | |
553 | ||
437ade60 FG |
554 | eval { |
555 | my $vzdump_cron = PVE::Cluster::cfs_read_file('vzdump.cron'); | |
e522a2db | 556 | |
437ade60 FG |
557 | # only warn once, there might be many jobs... |
558 | if (scalar(grep { defined($_->{maxfiles}) } $vzdump_cron->{jobs}->@*)) { | |
559 | $pass = 0; | |
560 | log_warn("/etc/pve/vzdump.cron - $maxfiles_msg"); | |
561 | } | |
562 | }; | |
563 | if (my $err = $@) { | |
e522a2db | 564 | $pass = 0; |
437ade60 | 565 | log_warn("unable to parse node's VZDump configuration - $err"); |
e522a2db FE |
566 | } |
567 | ||
568 | log_pass("no problems found.") if $pass; | |
569 | } | |
570 | ||
5df8b555 FE |
571 | sub check_cifs_credential_location { |
572 | log_info("checking CIFS credential location.."); | |
573 | ||
574 | my $regex = qr/^(.*)\.cred$/; | |
575 | ||
576 | my $found; | |
577 | ||
578 | PVE::Tools::dir_glob_foreach('/etc/pve/priv/', $regex, sub { | |
579 | my ($filename) = @_; | |
580 | ||
581 | my ($basename) = $filename =~ $regex; | |
582 | ||
583 | log_warn("CIFS credentials '/etc/pve/priv/$filename' will be moved to " . | |
584 | "'/etc/pve/priv/storage/$basename.pw' during the update"); | |
585 | ||
586 | $found = 1; | |
587 | }); | |
588 | ||
589 | log_pass("no CIFS credentials at outdated location found.") if !$found; | |
590 | } | |
591 | ||
5b3bad37 LS |
592 | sub check_custom_pool_roles { |
593 | log_info("Checking custom roles for pool permissions.."); | |
594 | ||
97723d76 DC |
595 | if (! -f "/etc/pve/user.cfg") { |
596 | log_skip("user.cfg does not exist"); | |
597 | return; | |
598 | } | |
599 | ||
055b6967 FG |
600 | my $raw = eval { PVE::Tools::file_get_contents('/etc/pve/user.cfg'); }; |
601 | if ($@) { | |
602 | log_fail("Failed to read '/etc/pve/user.cfg' - $@"); | |
603 | return; | |
604 | } | |
5b3bad37 LS |
605 | |
606 | my $roles = {}; | |
65b46cad FG |
607 | while ($raw =~ /^\s*(.+?)\s*$/gm) { |
608 | my $line = $1; | |
609 | my @data; | |
610 | ||
611 | foreach my $d (split (/:/, $line)) { | |
612 | $d =~ s/^\s+//; | |
613 | $d =~ s/\s+$//; | |
614 | push @data, $d | |
615 | } | |
616 | ||
617 | my $et = shift @data; | |
618 | next if $et ne 'role'; | |
5b3bad37 | 619 | |
65b46cad | 620 | my ($role, $privlist) = @data; |
5b3bad37 LS |
621 | if (!PVE::AccessControl::verify_rolename($role, 1)) { |
622 | warn "user config - ignore role '$role' - invalid characters in role name\n"; | |
623 | next; | |
624 | } | |
625 | ||
626 | $roles->{$role} = {} if !$roles->{$role}; | |
627 | foreach my $priv (split_list($privlist)) { | |
628 | $roles->{$role}->{$priv} = 1; | |
629 | } | |
630 | } | |
631 | ||
632 | foreach my $role (sort keys %{$roles}) { | |
633 | if (PVE::AccessControl::role_is_special($role)) { | |
634 | next; | |
635 | } | |
636 | ||
637 | if ($role eq "PVEPoolUser") { | |
638 | # the user created a custom role named PVEPoolUser | |
639 | log_fail("Custom role '$role' has a restricted name - a built-in role 'PVEPoolUser' will be available with the upgrade"); | |
640 | } else { | |
641 | log_pass("Custom role '$role' has no restricted name"); | |
642 | } | |
643 | ||
644 | my $perms = $roles->{$role}; | |
645 | if ($perms->{'Pool.Allocate'} && $perms->{'Pool.Audit'}) { | |
646 | log_pass("Custom role '$role' contains updated pool permissions"); | |
647 | } elsif ($perms->{'Pool.Allocate'}) { | |
648 | log_warn("Custom role '$role' contains permission 'Pool.Allocate' - to ensure same behavior add 'Pool.Audit' to this role"); | |
649 | } else { | |
650 | log_pass("Custom role '$role' contains no permissions that need to be updated"); | |
651 | } | |
652 | } | |
653 | } | |
654 | ||
08dd6ed8 TL |
655 | my sub check_max_length { |
656 | my ($raw, $max_length, $warning) = @_; | |
657 | log_warn($warning) if defined($raw) && length($raw) > $max_length; | |
658 | } | |
659 | ||
84006d1f LS |
660 | sub check_description_lengths { |
661 | log_info("Checking node and guest description/note legnth.."); | |
662 | ||
08dd6ed8 TL |
663 | my @affected_nodes = grep { |
664 | my $desc = PVE::NodeConfig::load_config($_)->{desc}; | |
665 | defined($desc) && length($desc) > 64 * 1024 | |
666 | } PVE::Cluster::get_nodelist(); | |
84006d1f | 667 | |
08dd6ed8 TL |
668 | if (scalar(@affected_nodes) > 0) { |
669 | log_warn("Node config description of the following nodes too long for new limit of 64 KiB:\n " | |
670 | . join(', ', @affected_nodes)); | |
671 | } else { | |
672 | log_pass("All node config descriptions fit in the new limit of 64 KiB"); | |
84006d1f LS |
673 | } |
674 | ||
08dd6ed8 TL |
675 | my $affected_guests = []; |
676 | ||
677 | my $cts = PVE::LXC::config_list(); | |
678 | for my $vmid (sort { $a <=> $b } keys %$cts) { | |
679 | my $desc = PVE::LXC::Config->load_config($vmid)->{description}; | |
680 | push @$affected_guests, "CT $vmid" if defined($desc) && length($desc) > 8 * 1024; | |
681 | } | |
84006d1f | 682 | my $vms = PVE::QemuServer::config_list(); |
08dd6ed8 TL |
683 | for my $vmid (sort { $a <=> $b } keys %$vms) { |
684 | my $desc = PVE::QemuConfig->load_config($vmid)->{description}; | |
685 | push @$affected_guests, "VM $vmid" if defined($desc) && length($desc) > 8 * 1024; | |
686 | } | |
687 | if (scalar($affected_guests->@*) > 0) { | |
37208950 | 688 | log_warn("Guest config description of the following virtual-guests too long for new limit of 64 KiB:\n" |
08dd6ed8 TL |
689 | ." * " . join("\n * ", $affected_guests->@*)); |
690 | } else { | |
691 | log_pass("All guest config descriptions fit in the new limit of 8 KiB"); | |
84006d1f LS |
692 | } |
693 | } | |
694 | ||
6f361f80 | 695 | sub check_storage_content { |
d12bbda5 | 696 | log_info("Checking storage content type configuration.."); |
6f361f80 | 697 | |
1126b8cd FE |
698 | my $found_referenced; |
699 | my $found_unreferenced; | |
f68689bb | 700 | my $pass = 1; |
6f361f80 FE |
701 | |
702 | my $storage_cfg = PVE::Storage::config(); | |
703 | ||
1126b8cd FE |
704 | my $potentially_affected = {}; |
705 | my $referenced_volids = {}; | |
706 | ||
23315349 | 707 | for my $storeid (sort keys $storage_cfg->{ids}->%*) { |
6f361f80 FE |
708 | my $scfg = $storage_cfg->{ids}->{$storeid}; |
709 | ||
710 | next if !PVE::Storage::storage_check_enabled($storage_cfg, $storeid, undef, 1); | |
711 | ||
d12bbda5 FE |
712 | my $valid_content = PVE::Storage::Plugin::valid_content_types($scfg->{type}); |
713 | ||
714 | if (scalar(keys $scfg->{content}->%*) == 0 && !$valid_content->{none}) { | |
f68689bb | 715 | $pass = 0; |
d12bbda5 FE |
716 | log_fail("storage '$storeid' does not support configured content type 'none'"); |
717 | delete $scfg->{content}->{none}; # scan for guest images below | |
718 | } | |
719 | ||
1126b8cd | 720 | next if $scfg->{content}->{images} && $scfg->{content}->{rootdir}; |
6f361f80 FE |
721 | |
722 | # Skip 'iscsi(direct)' (and foreign plugins with potentially similiar behavior) with 'none', | |
723 | # because that means "use LUNs directly" and vdisk_list() in PVE 6.x still lists those. | |
724 | # It's enough to *not* skip 'dir', because it is the only other storage that supports 'none' | |
725 | # and 'images' or 'rootdir', hence being potentially misconfigured. | |
726 | next if $scfg->{type} ne 'dir' && $scfg->{content}->{none}; | |
727 | ||
1126b8cd FE |
728 | eval { PVE::Storage::activate_storage($storage_cfg, $storeid) }; |
729 | if (my $err = $@) { | |
730 | log_warn("activating '$storeid' failed - $err"); | |
731 | next; | |
732 | } | |
733 | ||
734 | my $res = eval { PVE::Storage::vdisk_list($storage_cfg, $storeid); }; | |
735 | if (my $err = $@) { | |
736 | log_warn("listing images on '$storeid' failed - $err"); | |
737 | next; | |
738 | } | |
739 | my @volids = map { $_->{volid} } $res->{$storeid}->@*; | |
740 | ||
741 | for my $volid (@volids) { | |
742 | $potentially_affected->{$volid} = 1; | |
743 | } | |
744 | ||
745 | my $number = scalar(@volids); | |
746 | if ($number > 0 && !$scfg->{content}->{images} && !$scfg->{content}->{rootdir}) { | |
747 | log_info("storage '$storeid' - neither content type 'images' nor 'rootdir' configured" | |
748 | .", but found $number guest volume(s)"); | |
749 | } | |
750 | } | |
751 | ||
752 | my $check_volid = sub { | |
753 | my ($volid, $vmid, $vmtype, $reference) = @_; | |
754 | ||
755 | $referenced_volids->{$volid} = 1 if $reference ne 'unreferenced'; | |
756 | ||
757 | my $guesttext = $vmtype eq 'qemu' ? 'VM' : 'CT'; | |
758 | my $prefix = "$guesttext $vmid - volume '$volid' ($reference)"; | |
6f361f80 | 759 | |
1126b8cd FE |
760 | my ($storeid) = PVE::Storage::parse_volume_id($volid, 1); |
761 | return if !defined($storeid); | |
6f361f80 | 762 | |
1126b8cd FE |
763 | my $scfg = $storage_cfg->{ids}->{$storeid}; |
764 | if (!$scfg) { | |
f68689bb | 765 | $pass = 0; |
1126b8cd FE |
766 | log_warn("$prefix - storage does not exist!"); |
767 | return; | |
768 | } | |
769 | ||
770 | # cannot use parse_volname for containers, as it can return 'images' | |
771 | # but containers cannot have ISO images attached, so assume 'rootdir' | |
772 | my $vtype = 'rootdir'; | |
773 | if ($vmtype eq 'qemu') { | |
774 | ($vtype) = eval { PVE::Storage::parse_volname($storage_cfg, $volid); }; | |
775 | return if $@; | |
6f361f80 | 776 | } |
1126b8cd FE |
777 | |
778 | if (!$scfg->{content}->{$vtype}) { | |
779 | $found_referenced = 1 if $reference ne 'unreferenced'; | |
780 | $found_unreferenced = 1 if $reference eq 'unreferenced'; | |
781 | $pass = 0; | |
782 | log_warn("$prefix - storage does not have content type '$vtype' configured."); | |
783 | } | |
784 | }; | |
785 | ||
786 | my $guests = {}; | |
787 | ||
788 | my $cts = PVE::LXC::config_list(); | |
789 | for my $vmid (sort { $a <=> $b } keys %$cts) { | |
790 | $guests->{$vmid} = 'lxc'; | |
791 | ||
792 | my $conf = PVE::LXC::Config->load_config($vmid); | |
793 | ||
794 | my $volhash = {}; | |
795 | ||
796 | my $check = sub { | |
797 | my ($ms, $mountpoint, $reference) = @_; | |
798 | ||
799 | my $volid = $mountpoint->{volume}; | |
800 | return if !$volid || $mountpoint->{type} ne 'volume'; | |
801 | ||
802 | return if $volhash->{$volid}; # volume might be referenced multiple times | |
803 | ||
804 | $volhash->{$volid} = 1; | |
805 | ||
806 | $check_volid->($volid, $vmid, 'lxc', $reference); | |
807 | }; | |
808 | ||
809 | my $opts = { include_unused => 1 }; | |
810 | PVE::LXC::Config->foreach_volume_full($conf, $opts, $check, 'in config'); | |
811 | for my $snapname (keys $conf->{snapshots}->%*) { | |
812 | my $snap = $conf->{snapshots}->{$snapname}; | |
813 | PVE::LXC::Config->foreach_volume_full($snap, $opts, $check, "in snapshot '$snapname'"); | |
814 | } | |
815 | } | |
816 | ||
817 | my $vms = PVE::QemuServer::config_list(); | |
818 | for my $vmid (sort { $a <=> $b } keys %$vms) { | |
819 | $guests->{$vmid} = 'qemu'; | |
820 | ||
821 | my $conf = PVE::QemuConfig->load_config($vmid); | |
822 | ||
823 | my $volhash = {}; | |
824 | ||
825 | my $check = sub { | |
826 | my ($key, $drive, $reference) = @_; | |
827 | ||
828 | my $volid = $drive->{file}; | |
829 | return if $volid =~ m|^/|; | |
830 | ||
831 | return if $volhash->{$volid}; # volume might be referenced multiple times | |
832 | ||
833 | $volhash->{$volid} = 1; | |
834 | ||
835 | $check_volid->($volid, $vmid, 'qemu', $reference); | |
836 | }; | |
837 | ||
838 | my $opts = { | |
839 | extra_keys => ['vmstate'], | |
840 | include_unused => 1, | |
841 | }; | |
842 | # startup from a suspended state works even without 'images' content type on the | |
843 | # state storage, so do not check 'vmstate' for $conf | |
844 | PVE::QemuConfig->foreach_volume_full($conf, { include_unused => 1 }, $check, 'in config'); | |
845 | for my $snapname (keys $conf->{snapshots}->%*) { | |
846 | my $snap = $conf->{snapshots}->{$snapname}; | |
847 | PVE::QemuConfig->foreach_volume_full($snap, $opts, $check, "in snapshot '$snapname'"); | |
848 | } | |
849 | } | |
850 | ||
851 | if ($found_referenced) { | |
852 | log_warn("Proxmox VE 7.0 enforces stricter content type checks. The guests above " . | |
853 | "might not work until the storage configuration is fixed."); | |
854 | } | |
855 | ||
856 | for my $volid (sort keys $potentially_affected->%*) { | |
857 | next if $referenced_volids->{$volid}; # already checked | |
858 | ||
859 | my (undef, undef, $vmid) = PVE::Storage::parse_volname($storage_cfg, $volid); | |
860 | my $vmtype = $guests->{$vmid}; | |
861 | next if !$vmtype; | |
862 | ||
863 | $check_volid->($volid, $vmid, $vmtype, 'unreferenced'); | |
6f361f80 FE |
864 | } |
865 | ||
1126b8cd FE |
866 | if ($found_unreferenced) { |
867 | log_warn("When migrating, Proxmox VE 7.0 only scans storages with the appropriate " . | |
868 | "content types for unreferenced guest volumes."); | |
f68689bb FE |
869 | } |
870 | ||
871 | if ($pass) { | |
d12bbda5 | 872 | log_pass("no problems found"); |
6f361f80 FE |
873 | } |
874 | } | |
875 | ||
9f5f9819 SI |
876 | sub check_containers_cgroup_compat { |
877 | ||
878 | my $kernel_cli = PVE::Tools::file_get_contents('/proc/cmdline'); | |
879 | if ($kernel_cli =~ /systemd.unified_cgroup_hierarchy=0/){ | |
880 | log_skip("System explicitly configured for legacy hybrid cgroup hierarchy."); | |
881 | return; | |
882 | } | |
883 | ||
884 | my $supports_cgroupv2 = sub { | |
ca0c50a1 | 885 | my ($conf, $rootdir, $ctid) = @_; |
9f5f9819 SI |
886 | |
887 | my $get_systemd_version = sub { | |
888 | my ($self) = @_; | |
889 | ||
890 | my $sd_lib_dir = -d "/lib/systemd" ? "/lib/systemd" : "/usr/lib/systemd"; | |
891 | my $libsd = PVE::Tools::dir_glob_regex($sd_lib_dir, "libsystemd-shared-.+\.so"); | |
892 | if (defined($libsd) && $libsd =~ /libsystemd-shared-(\d+)\.so/) { | |
893 | return $1; | |
894 | } | |
895 | ||
896 | return undef; | |
897 | }; | |
898 | ||
899 | my $unified_cgroupv2_support = sub { | |
900 | my ($self) = @_; | |
901 | ||
902 | # https://www.freedesktop.org/software/systemd/man/systemd.html | |
903 | # systemd is installed as symlink to /sbin/init | |
904 | my $systemd = CORE::readlink('/sbin/init'); | |
905 | ||
906 | # assume non-systemd init will run with unified cgroupv2 | |
907 | if (!defined($systemd) || $systemd !~ m@/systemd$@) { | |
908 | return 1; | |
909 | } | |
910 | ||
911 | # systemd version 232 (e.g. debian stretch) supports the unified hierarchy | |
912 | my $sdver = $get_systemd_version->(); | |
913 | if (!defined($sdver) || $sdver < 232) { | |
914 | return 0; | |
915 | } | |
916 | ||
917 | return 1; | |
918 | }; | |
919 | ||
920 | my $ostype = $conf->{ostype}; | |
ca0c50a1 TL |
921 | if (!defined($ostype)) { |
922 | log_warn("Found CT ($ctid) without 'ostype' set!"); | |
923 | } elsif ($ostype eq 'devuan' || $ostype eq 'alpine') { | |
924 | return 1; # no systemd, no cgroup problems | |
9f5f9819 SI |
925 | } |
926 | ||
927 | my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir); | |
928 | return $lxc_setup->protected_call($unified_cgroupv2_support); | |
929 | }; | |
930 | ||
931 | my $log_problem = sub { | |
932 | my ($ctid) = @_; | |
1d552961 TL |
933 | log_warn("Found at least one CT ($ctid) which does not support running in a unified cgroup v2" . |
934 | " layout.\n Either upgrade the Container distro or set systemd.unified_cgroup_hierarchy=0 " . | |
935 | "in the Proxmox VE hosts' kernel cmdline! Skipping further CT compat checks." | |
9f5f9819 SI |
936 | ); |
937 | }; | |
938 | ||
939 | my $cts = eval { PVE::API2::LXC->vmlist({ node => $nodename }) }; | |
940 | if ($@) { | |
941 | log_warn("Failed to retrieve information about this node's CTs - $@"); | |
942 | return; | |
943 | } | |
944 | ||
945 | if (!defined($cts) || !scalar(@$cts)) { | |
946 | log_skip("No containers on node detected."); | |
947 | return; | |
948 | } | |
949 | ||
23315349 TL |
950 | my @running_cts = sort { $a <=> $b } grep { $_->{status} eq 'running' } @$cts; |
951 | my @offline_cts = sort { $a <=> $b } grep { $_->{status} ne 'running' } @$cts; | |
9f5f9819 SI |
952 | |
953 | for my $ct (@running_cts) { | |
954 | my $ctid = $ct->{vmid}; | |
955 | my $pid = eval { PVE::LXC::find_lxc_pid($ctid) }; | |
956 | if (my $err = $@) { | |
957 | log_warn("Failed to get PID for running CT $ctid - $err"); | |
958 | next; | |
959 | } | |
960 | my $rootdir = "/proc/$pid/root"; | |
961 | my $conf = PVE::LXC::Config->load_config($ctid); | |
962 | ||
ca0c50a1 | 963 | my $ret = eval { $supports_cgroupv2->($conf, $rootdir, $ctid) }; |
9f5f9819 SI |
964 | if (my $err = $@) { |
965 | log_warn("Failed to get cgroup support status for CT $ctid - $err"); | |
966 | next; | |
967 | } | |
968 | if (!$ret) { | |
969 | $log_problem->($ctid); | |
970 | return; | |
971 | } | |
972 | } | |
973 | ||
974 | my $storage_cfg = PVE::Storage::config(); | |
975 | for my $ct (@offline_cts) { | |
976 | my $ctid = $ct->{vmid}; | |
977 | my ($conf, $rootdir, $ret); | |
978 | eval { | |
979 | $conf = PVE::LXC::Config->load_config($ctid); | |
980 | $rootdir = PVE::LXC::mount_all($ctid, $storage_cfg, $conf); | |
ca0c50a1 | 981 | $ret = $supports_cgroupv2->($conf, $rootdir, $ctid); |
9f5f9819 SI |
982 | }; |
983 | if (my $err = $@) { | |
984 | log_warn("Failed to load config and mount CT $ctid - $err"); | |
985 | eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) }; | |
986 | next; | |
987 | } | |
988 | if (!$ret) { | |
989 | $log_problem->($ctid); | |
990 | eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) }; | |
991 | last; | |
992 | } | |
993 | ||
994 | eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) }; | |
995 | } | |
996 | }; | |
997 | ||
4177a14d TL |
998 | sub check_misc { |
999 | print_header("MISCELLANEOUS CHECKS"); | |
1000 | my $ssh_config = eval { PVE::Tools::file_get_contents('/root/.ssh/config') }; | |
1001 | if (defined($ssh_config)) { | |
1002 | log_fail("Unsupported SSH Cipher configured for root in /root/.ssh/config: $1") | |
1003 | if $ssh_config =~ /^Ciphers .*(blowfish|arcfour|3des).*$/m; | |
1004 | } else { | |
1005 | log_skip("No SSH config file found."); | |
1006 | } | |
1007 | ||
1008 | log_info("Checking common daemon services.."); | |
1009 | $log_systemd_unit_state->('pveproxy.service'); | |
1010 | $log_systemd_unit_state->('pvedaemon.service'); | |
1011 | $log_systemd_unit_state->('pvestatd.service'); | |
1012 | ||
1013 | my $root_free = PVE::Tools::df('/', 10); | |
64074357 TL |
1014 | log_warn("Less than 4 GiB free space on root file system.") |
1015 | if defined($root_free) && $root_free->{avail} < 4*1024*1024*1024; | |
4177a14d TL |
1016 | |
1017 | log_info("Checking for running guests.."); | |
1018 | my $running_guests = 0; | |
1019 | ||
1020 | my $vms = eval { PVE::API2::Qemu->vmlist({ node => $nodename }) }; | |
1021 | log_warn("Failed to retrieve information about this node's VMs - $@") if $@; | |
1022 | $running_guests += grep { $_->{status} eq 'running' } @$vms if defined($vms); | |
1023 | ||
1024 | my $cts = eval { PVE::API2::LXC->vmlist({ node => $nodename }) }; | |
1025 | log_warn("Failed to retrieve information about this node's CTs - $@") if $@; | |
1026 | $running_guests += grep { $_->{status} eq 'running' } @$cts if defined($cts); | |
1027 | ||
1028 | if ($running_guests > 0) { | |
1029 | log_warn("$running_guests running guest(s) detected - consider migrating or stopping them.") | |
1030 | } else { | |
1031 | log_pass("no running guest detected.") | |
1032 | } | |
1033 | ||
1034 | log_info("Checking if the local node's hostname '$nodename' is resolvable.."); | |
1035 | my $local_ip = eval { PVE::Network::get_ip_from_hostname($nodename) }; | |
1036 | if ($@) { | |
1037 | log_warn("Failed to resolve hostname '$nodename' to IP - $@"); | |
1038 | } else { | |
1039 | log_info("Checking if resolved IP is configured on local node.."); | |
1040 | my $cidr = Net::IP::ip_is_ipv6($local_ip) ? "$local_ip/128" : "$local_ip/32"; | |
1041 | my $configured_ips = PVE::Network::get_local_ip_from_cidr($cidr); | |
1042 | my $ip_count = scalar(@$configured_ips); | |
1043 | ||
1044 | if ($ip_count <= 0) { | |
1045 | log_fail("Resolved node IP '$local_ip' not configured or active for '$nodename'"); | |
1046 | } elsif ($ip_count > 1) { | |
1047 | log_warn("Resolved node IP '$local_ip' active on multiple ($ip_count) interfaces!"); | |
1048 | } else { | |
1049 | log_pass("Resolved node IP '$local_ip' configured and active on single interface."); | |
1050 | } | |
1051 | } | |
1052 | ||
1053 | log_info("Check node certificate's RSA key size"); | |
1054 | my $certs = PVE::API2::Certificates->info({ node => $nodename }); | |
1055 | my $certs_check = { | |
1056 | 'rsaEncryption' => { | |
1057 | minsize => 2048, | |
1058 | name => 'RSA', | |
1059 | }, | |
1060 | 'id-ecPublicKey' => { | |
1061 | minsize => 224, | |
1062 | name => 'ECC', | |
1063 | }, | |
1064 | }; | |
1065 | ||
1066 | my $certs_check_failed = 0; | |
1067 | foreach my $cert (@$certs) { | |
1068 | my ($type, $size, $fn) = $cert->@{qw(public-key-type public-key-bits filename)}; | |
1069 | ||
1070 | if (!defined($type) || !defined($size)) { | |
1071 | log_warn("'$fn': cannot check certificate, failed to get it's type or size!"); | |
1072 | } | |
1073 | ||
1074 | my $check = $certs_check->{$type}; | |
1075 | if (!defined($check)) { | |
1076 | log_warn("'$fn': certificate's public key type '$type' unknown, check Debian Busters release notes"); | |
1077 | next; | |
1078 | } | |
1079 | ||
1080 | if ($size < $check->{minsize}) { | |
1081 | log_fail("'$fn', certificate's $check->{name} public key size is less than 2048 bit"); | |
1082 | $certs_check_failed = 1; | |
1083 | } else { | |
1084 | log_pass("Certificate '$fn' passed Debian Busters security level for TLS connections ($size >= 2048)"); | |
1085 | } | |
1086 | } | |
e522a2db FE |
1087 | |
1088 | check_backup_retention_settings(); | |
5df8b555 | 1089 | check_cifs_credential_location(); |
5b3bad37 | 1090 | check_custom_pool_roles(); |
84006d1f | 1091 | check_description_lengths(); |
6f361f80 | 1092 | check_storage_content(); |
4177a14d TL |
1093 | } |
1094 | ||
1095 | __PACKAGE__->register_method ({ | |
1096 | name => 'checklist', | |
1097 | path => 'checklist', | |
1098 | method => 'GET', | |
1099 | description => 'Check (pre-/post-)upgrade conditions.', | |
1100 | parameters => { | |
1101 | additionalProperties => 0, | |
1102 | properties => { | |
3d779b12 SI |
1103 | full => { |
1104 | description => 'perform additional, expensive checks.', | |
1105 | type => 'boolean', | |
1106 | optional => 1, | |
1107 | default => 0, | |
1108 | }, | |
4177a14d TL |
1109 | }, |
1110 | }, | |
1111 | returns => { type => 'null' }, | |
1112 | code => sub { | |
1113 | my ($param) = @_; | |
1114 | ||
1115 | check_pve_packages(); | |
1116 | check_cluster_corosync(); | |
1117 | check_ceph(); | |
1118 | check_storage_health(); | |
1119 | check_misc(); | |
1120 | ||
3d779b12 SI |
1121 | if ($param->{full}) { |
1122 | check_containers_cgroup_compat(); | |
1123 | } else { | |
222db0f5 | 1124 | log_skip("NOTE: Expensive checks, like CT cgroupv2 compat, not performed without '--full' parameter"); |
3d779b12 SI |
1125 | } |
1126 | ||
4177a14d TL |
1127 | print_header("SUMMARY"); |
1128 | ||
1129 | my $total = 0; | |
1130 | $total += $_ for values %$counters; | |
1131 | ||
1132 | print "TOTAL: $total\n"; | |
1133 | print colored("PASSED: $counters->{pass}\n", 'green'); | |
1134 | print "SKIPPED: $counters->{skip}\n"; | |
1135 | print colored("WARNINGS: $counters->{warn}\n", 'yellow'); | |
1136 | print colored("FAILURES: $counters->{fail}\n", 'red'); | |
1137 | ||
1138 | if ($counters->{warn} > 0 || $counters->{fail} > 0) { | |
1139 | my $color = $counters->{fail} > 0 ? 'red' : 'yellow'; | |
1140 | print colored("\nATTENTION: Please check the output for detailed information!\n", $color); | |
1141 | print colored("Try to solve the problems one at a time and then run this checklist tool again.\n", $color) if $counters->{fail} > 0; | |
1142 | } | |
1143 | ||
1144 | return undef; | |
1145 | }}); | |
1146 | ||
1147 | our $cmddef = [ __PACKAGE__, 'checklist', [], {}]; | |
1148 | ||
4177a14d | 1149 | 1; |