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 7079BF0CD for ; Wed, 14 Dec 2022 10:45:03 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5A19E2849F for ; Wed, 14 Dec 2022 10:45:03 +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 ; Wed, 14 Dec 2022 10:45:02 +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 82E4F4438D for ; Wed, 14 Dec 2022 10:45:02 +0100 (CET) From: Christoph Heiss To: pbs-devel@lists.proxmox.com Date: Wed, 14 Dec 2022 10:42:59 +0100 Message-Id: <20221214094300.2061155-2-c.heiss@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221214094300.2061155-1-c.heiss@proxmox.com> References: <20221214094300.2061155-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 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_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: [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: Wed, 14 Dec 2022 09:45:03 -0000 .. 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"] + } 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