From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <a.lauterer@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id CF87A716C8
 for <pve-devel@lists.proxmox.com>; Mon,  4 Oct 2021 10:02:26 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id C29A517EAD
 for <pve-devel@lists.proxmox.com>; Mon,  4 Oct 2021 10:02:26 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 3BC2E17EA3
 for <pve-devel@lists.proxmox.com>; Mon,  4 Oct 2021 10:02:26 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 08BD84494B
 for <pve-devel@lists.proxmox.com>; Mon,  4 Oct 2021 10:02:26 +0200 (CEST)
From: Aaron Lauterer <a.lauterer@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Mon,  4 Oct 2021 10:02:25 +0200
Message-Id: <20211004080225.346654-1-a.lauterer@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -1.265 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLACK 3 Contains an URL listed in the URIBL blacklist [tools.pm]
Subject: [pve-devel] [PATCH v3 manager] ceph install: improve ceph install
 checks during installation
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 04 Oct 2021 08:02:26 -0000

Adding a flag file during the Ceph installation helps to cover the time
span in which the binary is already present but the installation not yet
done.

The most noticeable effect is that the 'Next' button in the GUI will
only become active once the installation is actually finished and not
earlier.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---

v2 -> v3 (thanks for the hints):
 - calling it a flag and moving it to /run
 - improve file opening / unlinking handling and showing errors
 - adding more / improving comments

v1 -> v3: check for plain file and not just existing file

If the flag file is created before ceph is installed, there is no
effect. If it is created after Ceph has been installed, the user is
prompted by the install dialog once more, but apt will be done right
away.

 PVE/CLI/pveceph.pm | 12 ++++++++++++
 PVE/Ceph/Tools.pm  |  4 +++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/PVE/CLI/pveceph.pm b/PVE/CLI/pveceph.pm
index 356af282..6d77f6ad 100755
--- a/PVE/CLI/pveceph.pm
+++ b/PVE/CLI/pveceph.pm
@@ -177,7 +177,16 @@ __PACKAGE__->register_method ({
 	);
 
 	print "start installation\n";
+
+	# the install flag helps to determine when apt is done installing
+	my $install_flag_file = '/run/ceph-install-flag';
+	open(my $install_flag, '>', "${install_flag_file}") or
+	     die "could not open Ceph installation flag - $!\n";
+	close $install_flag;
+
 	if (system(@apt_install, @ceph_packages) != 0) {
+	    unlink $install_flag_file or
+		warn "Could not remove Ceph installation flag - $!";
 	    die "apt failed during ceph installation ($?)\n";
 	}
 
@@ -188,6 +197,9 @@ __PACKAGE__->register_method ({
 	    'systemctl', 'try-reload-or-restart', 'pvedaemon.service', 'pveproxy.service'
 	]);
 
+	unlink $install_flag_file or
+	    warn "Could not remove Ceph installation flag - $!";
+
 	return undef;
     }});
 
diff --git a/PVE/Ceph/Tools.pm b/PVE/Ceph/Tools.pm
index f54d837a..3f0818fd 100644
--- a/PVE/Ceph/Tools.pm
+++ b/PVE/Ceph/Tools.pm
@@ -155,7 +155,9 @@ sub check_ceph_installed {
 
     $service = 'ceph_bin' if !defined($service);
 
-    if (! -x $ceph_service->{$service}) {
+    # the flag file is checked as on a new installation, the binary gets
+    # extracted by dpkg before the installation is finished
+    if (! -x $ceph_service->{$service} || -f '/run/ceph-install-flag') {
 	die "binary not installed: $ceph_service->{$service}\n" if !$noerr;
 	return undef;
     }
-- 
2.30.2