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 DB2DBF3CF for ; Thu, 15 Dec 2022 11:30:43 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B2039617B for ; Thu, 15 Dec 2022 11:30:13 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 15 Dec 2022 11:30:12 +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 1573C44796 for ; Thu, 15 Dec 2022 11:30:12 +0100 (CET) Message-ID: <62764cb6-920e-3fb3-53d8-4ede38e5e037@proxmox.com> Date: Thu, 15 Dec 2022 11:30:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Content-Language: en-US, de-AT To: Wolfgang Bumiller Cc: pbs-devel@lists.proxmox.com References: <20221214094300.2061155-1-c.heiss@proxmox.com> <20221214094300.2061155-2-c.heiss@proxmox.com> <20221215092927.nvgsoptxcngd4w2k@casey.proxmox.com> From: Christoph Heiss In-Reply-To: <20221215092927.nvgsoptxcngd4w2k@casey.proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.499 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 NICE_REPLY_A -0.001 Looks like a legit reply (A) 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 10:30:43 -0000 On 12/15/22 10:29, Wolfgang Bumiller wrote: > 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? Not sure either, but if it is a finished one-shot service, systemd *should* always provide a result. That's IMHO a very reasonable assumption and was my thought while working on it too. Playing a bit with `systemctl show` and looking at some services, it really seems that the Result property is always present, even for e.g. non-existing services. But if you want, I can send a v2 and add the fallback to SubState here as well, to align it with the Perl equivalent. >> [..] >> -- >> 2.30.2