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