From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 C163A6AF02 for ; Wed, 17 Feb 2021 12:29:35 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B2932214E5 for ; Wed, 17 Feb 2021 12:29:05 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 35B39214DB for ; Wed, 17 Feb 2021 12:29:05 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id EDBC7461D2 for ; Wed, 17 Feb 2021 12:29:04 +0100 (CET) Date: Wed, 17 Feb 2021 12:29:03 +0100 From: Wolfgang Bumiller To: Stefan Reiter Cc: pbs-devel@lists.proxmox.com Message-ID: <20210217112903.nrs4dxfqkhpcx32f@olga.proxmox.com> References: <20210216170710.31767-1-s.reiter@proxmox.com> <20210216170710.31767-17-s.reiter@proxmox.com> <20210217105253.wfyaxp5wnj57c5yq@olga.proxmox.com> <64949c97-b8b9-01e8-8ed8-9f6c02fca94b@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <64949c97-b8b9-01e8-8ed8-9f6c02fca94b@proxmox.com> User-Agent: NeoMutt/20180716 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.045 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [watchdog.rs, api.rs, mod.rs, proxmox-restore-daemon.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup 16/22] file-restore-daemon: add watchdog module X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Feb 2021 11:29:35 -0000 On Wed, Feb 17, 2021 at 12:14:39PM +0100, Stefan Reiter wrote: > On 17/02/2021 11:52, Wolfgang Bumiller wrote: > > On Tue, Feb 16, 2021 at 06:07:04PM +0100, Stefan Reiter wrote: > > > Add a watchdog that will automatically shut down the VM after 10 > > > minutes, if no API call is received. > > > > > > This is handled using the unix 'alarm' syscall. > > > > > > Signed-off-by: Stefan Reiter > > > --- > > > src/api2/types/file_restore.rs | 3 ++ > > > src/bin/proxmox-restore-daemon.rs | 5 ++ > > > src/bin/proxmox_restore_daemon/api.rs | 22 ++++++-- > > > src/bin/proxmox_restore_daemon/mod.rs | 3 ++ > > > src/bin/proxmox_restore_daemon/watchdog.rs | 63 ++++++++++++++++++++++ > > > 5 files changed, 91 insertions(+), 5 deletions(-) > > > create mode 100644 src/bin/proxmox_restore_daemon/watchdog.rs > > > > > > diff --git a/src/api2/types/file_restore.rs b/src/api2/types/file_restore.rs > > > index cd8df16a..710c6d83 100644 > > > --- a/src/api2/types/file_restore.rs > > > +++ b/src/api2/types/file_restore.rs > > > @@ -8,5 +8,8 @@ use proxmox::api::api; > > > pub struct RestoreDaemonStatus { > > > /// VM uptime in seconds > > > pub uptime: i64, > > > + /// time left until auto-shutdown, keep in mind that this is inaccurate when 'keep-timeout' is > > > + /// not set, as then after the status call the timer will have reset > > > + pub timeout: i64, > > > } > > > diff --git a/src/bin/proxmox-restore-daemon.rs b/src/bin/proxmox-restore-daemon.rs > > > index 1ec90794..d30da563 100644 > > > --- a/src/bin/proxmox-restore-daemon.rs > > > +++ b/src/bin/proxmox-restore-daemon.rs > > > @@ -40,6 +40,9 @@ fn main() -> Result<(), Error> { > > > .write_style(env_logger::WriteStyle::Never) > > > .init(); > > > + // start watchdog, failure is a critical error as it leads to a scenario where we never exit > > > + watchdog_init()?; > > > + > > > proxmox_backup::tools::runtime::main(run()) > > > } > > > @@ -77,6 +80,8 @@ fn accept_vsock_connections( > > > Ok(stream) => { > > > if sender.send(Ok(stream)).await.is_err() { > > > error!("connection accept channel was closed"); > > > + } else { > > > + watchdog_ping(); > > > > Should the ping not also happen at every api call in case connections > > get reused? > > > > I wanted to keep as much watchdog code out of API calls, lest some new code > forgets to call a ping(), but yes, I didn't think of connection reuse (it > doesn't currently happen anywhere, but still good to be safe). So maybe the API handler should just get some kind of callback to trigger before api calls.