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