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