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 A2DAEF366 for ; Thu, 15 Dec 2022 10:29:59 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 805BC5908 for ; Thu, 15 Dec 2022 10:29:29 +0100 (CET) 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 for ; Thu, 15 Dec 2022 10:29:28 +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 A78F4443A6 for ; Thu, 15 Dec 2022 10:29:28 +0100 (CET) Date: Thu, 15 Dec 2022 10:29:27 +0100 From: Wolfgang Bumiller To: Christoph Heiss Cc: pbs-devel@lists.proxmox.com Message-ID: <20221215092927.nvgsoptxcngd4w2k@casey.proxmox.com> References: <20221214094300.2061155-1-c.heiss@proxmox.com> <20221214094300.2061155-2-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221214094300.2061155-2-c.heiss@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL -0.280 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 KAM_EVIL_NUMBERS4 1 Phone Numbers used by scammers 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. [services.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup] api2/node/services: Handle optional services and expose unit-state 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: Thu, 15 Dec 2022 09:29:59 -0000 On Wed, Dec 14, 2022 at 10:42:59AM +0100, Christoph Heiss wrote: > .. in the same way the PVE api does, esp. regarding the logic to handle > oneshot and missing services. > > This then allows re-using the GUI parts from there as well, so that the > services page in PVE and PBS looks the same. > > Signed-off-by: Christoph Heiss > --- > src/api2/node/services.rs | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > > diff --git a/src/api2/node/services.rs b/src/api2/node/services.rs > index 0cc1857e..534c41e8 100644 > --- a/src/api2/node/services.rs > +++ b/src/api2/node/services.rs > @@ -76,12 +76,27 @@ fn get_full_service_state(service: &str) -> Result { > fn json_service_state(service: &str, status: Value) -> Value { > if let Some(desc) = status["Description"].as_str() { > let name = status["Name"].as_str().unwrap_or(service); > - let state = status["SubState"].as_str().unwrap_or("unknown"); > + > + let state = if status["Type"] == "oneshot" && status["SubState"] == "dead" { > + &status["Result"] Reading the perl equivalent, if we end up here but `Result` does not exist we'd see 'dead' in perl as it falls back to SubState (which at this point is known to be 'dead'), while we'd show 'unknown' in this case from the 'unwrap_or' below. Not sure if this can happen though? > + } else { > + &status["SubState"] > + } > + .as_str() > + .unwrap_or("unknown"); > + > + let unit_state = if status["LoadState"] == "not-found" { > + "not-found" > + } else { > + status["UnitFileState"].as_str().unwrap_or("unknown") > + }; > + > return json!({ > "service": service, > "name": name, > "desc": desc, > "state": state, > + "unit-state": unit_state, > }); > } > > @@ -117,6 +132,10 @@ fn json_service_state(service: &str, status: Value) -> Value { > type: String, > description: "systemd service 'SubState'.", > }, > + "unit-state": { > + type: String, > + description: "systemd service unit state.", > + }, > }, > }, > }, > -- > 2.30.2