6 use List
::Util
qw(first);
11 use PVE
::RPCEnvironment
;
13 my $ceph_cfg_file = 'ceph.conf';
14 my $keyring_value = '/etc/pve/ceph/$cluster.$name.keyring';
20 my $entity = 'client.crash';
23 print("Checking whether the configuration for '$entity' needs to be updated.\n");
25 my $add_keyring = sub {
26 print("Setting keyring path to '$keyring_value'.\n");
27 $cfg->{$entity}->{keyring
} = $keyring_value;
30 if (!exists($cfg->{$entity})) {
31 print("Adding missing section for '$entity'.\n");
36 if (exists($cfg->{$entity}->{key
})) {
37 print("Removing existing usage of key.\n");
38 delete($cfg->{$entity}->{key
});
42 if (!exists($cfg->{$entity}->{keyring
})) {
43 print("Keyring path is missing from configuration.\n");
48 my $current_keyring_value = $cfg->{$entity}->{keyring
};
49 if ($current_keyring_value ne $keyring_value) {
50 print("Current keyring path differs from expected path.\n");
60 # PVE::RADOS expects an active RPC Environment because it forks itself
61 # and may want to clean up after
62 my $rpcenv = PVE
::RPCEnvironment-
>setup_default_cli_env();
64 if (!PVE
::Ceph
::Tools
::check_ceph_installed
('ceph_bin', 1)) {
65 print("Ceph is not installed. No action required.\n");
69 my $ceph_cfg_path = PVE
::Ceph
::Tools
::get_config
('pve_ceph_cfgpath');
70 if (PVE
::Ceph
::Tools
::check_ceph_installed
('ceph_mon', 1) && -f
$ceph_cfg_path) {
71 my $pve_ceph_cfgdir = PVE
::Ceph
::Tools
::get_config
('pve_ceph_cfgdir');
72 if (! -d
$pve_ceph_cfgdir) {
73 File
::Path
::make_path
($pve_ceph_cfgdir);
78 PVE
::Ceph
::Tools
::check_ceph_inited
();
81 print("Ceph is not initialized. No action required.\n");
85 my $rados = eval { PVE
::RADOS-
>new() };
86 my $ceph_crash_key_path = PVE
::Ceph
::Tools
::get_config
('pve_ceph_crash_key_path');
90 my $rval = PVE
::Cluster
::cfs_lock_file
($ceph_cfg_file, undef, sub {
92 my $cfg = PVE
::Cluster
::cfs_read_file
($ceph_cfg_file);
94 if (!defined($rados)) {
95 my $has_mon_host = defined($cfg->{global
}) && defined($cfg->{global
}->{mon_host
});
96 if ($has_mon_host && $cfg->{global
}->{mon_host
} ne '') {
97 die "Connection to RADOS failed even though a monitor is configured.\n" .
98 "Please verify whether your configuration in '$ceph_cfg_file' is correct.\n"
102 "Connection to RADOS failed and no monitor is configured in '$ceph_cfg_file'.\n".
103 "Assuming that things are fine. No action required.\n"
108 my $updated_keyring = PVE
::Ceph
::Tools
::create_or_update_crash_keyring_file
($rados);
110 if ($updated_keyring) {
111 print("Keyring file '$ceph_crash_key_path' was updated.\n");
114 my $changed = try_adapt_cfg
($cfg);
117 print("Committing updated configuration to '$ceph_cfg_file'.\n");
118 PVE
::Cluster
::cfs_write_file
($ceph_cfg_file, $cfg);
119 print("Successfully updated configuration for 'ceph-crash.service'.\n");
121 print("Configuration in '$ceph_cfg_file' does not need to be updated.\n");
129 # cfs_lock_file sets $@ explicitly to undef
132 my $has_err = !defined($rval) || $inner_err || $err;
136 $inner_err =~ s/\n*$//;
138 if (!defined($rval)) {
139 warn("Error while acquiring or releasing lock for '$ceph_cfg_file'.\n");
140 warn("Error: $err\n") if $err ne '';
143 warn("Failed to configure keyring for 'ceph-crash.service'.\nError: $inner_err\n")