[pve-devel] [PATCH manager v2] fix #844: allow to pre-delay start-all-marked guests on boot

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Nov 19 13:25:29 CET 2019


Add a simple ExecStartPre command which reads the local node config,
and if a delay is set the helper sleeps that long then exists.

The systemd-unit approach was chosen as this ensures that we really
only delay when doing the startall on node boot. The pve-guests
service does not allows manual stops, starts or restarts, it can only
be pulled in by the multi-user.target

Mark this command with "-" to tell systemd that errors of it should
not cause an abort, it's a best-effort approach.

The journal from a 2 second delay would look like:
> Nov 19 13:13:48 dev6 systemd[1]: Starting PVE guests...
> Nov 19 13:13:48 dev6 pve-startall-delay[2318]: Delaying on-boot 'startall' command for 2 second(s).
> ...
> Nov 19 13:13:50 dev6 pve-guests[2339]: <root at pam> starting task UPID:dev6:00000924:00000529:5DD3DC7E:startall::root at pam:

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

changes v1 -> v2:
* actually send the sleep helper along ...

 PVE/NodeConfig.pm           |  8 ++++++++
 bin/Makefile                |  2 ++
 bin/pve-startall-delay      | 18 ++++++++++++++++++
 defines.mk                  |  1 +
 services/pve-guests.service |  1 +
 5 files changed, 30 insertions(+)
 create mode 100755 bin/pve-startall-delay

diff --git a/PVE/NodeConfig.pm b/PVE/NodeConfig.pm
index b52868e2..627f6a33 100644
--- a/PVE/NodeConfig.pm
+++ b/PVE/NodeConfig.pm
@@ -67,6 +67,14 @@ my $confdesc = {
 	format => 'mac-addr',
 	optional => 1,
     },
+    startall_onboot_predelay => {
+	description => 'Initial delay in seconds, before starting all the Virtual Guests with on-boot enabled.',
+	type => 'integer',
+	minimum => 0,
+	maximum => 300,
+	default => 0,
+	optional => 1,
+    },
 };
 
 my $acmedesc = {
diff --git a/bin/Makefile b/bin/Makefile
index 8ea0c115..ac4fbd7f 100644
--- a/bin/Makefile
+++ b/bin/Makefile
@@ -66,6 +66,8 @@ check: $(addsuffix .service-api-verified, ${SERVICES}) $(addsuffix .api-verified
 install: ${SCRIPTS} ${CLI_MANS} ${SERVICE_MANS} pvemailforward ${BASH_COMPLETIONS} ${ZSH_COMPLETIONS}
 	install -d ${BINDIR}
 	install -m 0755 ${SCRIPTS} ${BINDIR}
+	install -d ${USRSHARE}/helpers
+	install -m 0755 pve-startall-delay ${USRSHARE}/helpers
 	install -s -m 2755 -g www-data pvemailforward ${BINDIR}
 	install -d ${MAN1DIR}
 	install -m 0644 ${CLI_MANS} ${MAN1DIR}
diff --git a/bin/pve-startall-delay b/bin/pve-startall-delay
new file mode 100755
index 00000000..f3402a11
--- /dev/null
+++ b/bin/pve-startall-delay
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use PVE::INotify;
+use PVE::NodeConfig;
+
+my $local_node = PVE::INotify::nodename();
+
+my $node_config = eval { PVE::NodeConfig::load_config($local_node) } // {};
+
+if (my $delay = $node_config->{startall_onboot_predelay}) {
+    warn "Delaying on-boot 'startall' command for $delay second(s).\n";
+    sleep($delay);
+}
+
+exit 0;
diff --git a/defines.mk b/defines.mk
index ab77b4ba..3a5792ad 100644
--- a/defines.mk
+++ b/defines.mk
@@ -12,6 +12,7 @@ ZSHCOMPLDIR=${DESTDIR}/usr/share/zsh/vendor-completions/
 HARADIR=${DESTDIR}/usr/share/cluster
 DOCDIR=${DESTDIR}/usr/share/doc/${PACKAGE}
 PODDIR=${DESTDIR}/usr/share/doc/${PACKAGE}/pod
+USRSHARE=${DESTDIR}/usr/share/${PACKAGE}
 WWWBASEDIR=${DESTDIR}/usr/share/${PACKAGE}
 WWWIMAGEDIR=${WWWBASEDIR}/images
 WWWTOUCHDIR=${WWWBASEDIR}/touch
diff --git a/services/pve-guests.service b/services/pve-guests.service
index 15b8cd05..6b044a5f 100644
--- a/services/pve-guests.service
+++ b/services/pve-guests.service
@@ -17,6 +17,7 @@ After=pve-ha-crm.service pve-ha-lrm.service
 
 [Service]
 Environment="PVE_LOG_ID=pve-guests"
+ExecStartPre=-/usr/share/pve-manager/helpers/pve-startall-delay
 ExecStart=/usr/bin/pvesh --nooutput create /nodes/localhost/startall
 ExecStop=-/usr/bin/vzdump -stop
 ExecStop=/usr/bin/pvesh --nooutput create /nodes/localhost/stopall
-- 
2.20.1





More information about the pve-devel mailing list