my $clusterconf = "/etc/pve/corosync.conf";
my $authfile = "/etc/corosync/authkey";
+my $local_cluster_lock = "/var/lock/pvecm.lock";
my $ring0_desc = {
type => 'string', format => 'address',
my $rpcenv = PVE::RPCEnvironment::get();
my $authuser = $rpcenv->get_user();
- my $worker = sub {
+ my $code = sub {
PVE::Cluster::setup_sshd_config(1);
PVE::Cluster::setup_rootsshconfig();
PVE::Cluster::setup_ssh_keys();
PVE::Tools::run_command('systemctl restart corosync pve-cluster');
};
+ my $worker = sub {
+ PVE::Tools::lock_file($local_cluster_lock, 10, $code);
+ die $@ if $@;
+ };
+
return $rpcenv->fork_worker('clustercreate', '', $authuser, $worker);
}});
my $config_change_lock = sub {
my ($code) = @_;
- my $local_lock_fn = "/var/lock/pvecm.lock";
- PVE::Tools::lock_file($local_lock_fn, 10, sub {
+ PVE::Tools::lock_file($local_cluster_lock, 10, sub {
PVE::Cluster::cfs_update(1);
my $members = PVE::Cluster::get_members();
if (scalar(keys %$members) > 1) {
my $authuser = $rpcenv->get_user();
my $worker = sub {
- PVE::Cluster::join($param);
+ PVE::Tools::lock_file($local_cluster_lock, 10, \&PVE::Cluster::join, $param);
+ die $@ if $@;
};
return $rpcenv->fork_worker('clusterjoin', '', $authuser, $worker);
delete $param->{use_ssh};
$param->{password} = $password;
- eval { PVE::Cluster::join($param) };
+ my $local_cluster_lock = "/var/lock/pvecm.lock";
+ PVE::Tools::lock_file($local_cluster_lock, 10, \&PVE::Cluster::join, $param);
if (my $err = $@) {
if (ref($err) eq 'PVE::APIClient::Exception' && $err->{code} == 501) {