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 D416A9194E for ; Thu, 22 Dec 2022 13:06:26 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B242F1AFFF for ; Thu, 22 Dec 2022 13:06:26 +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, 22 Dec 2022 13:06:25 +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 562A644D11 for ; Thu, 22 Dec 2022 13:06:25 +0100 (CET) From: Christoph Heiss To: pbs-devel@lists.proxmox.com Date: Thu, 22 Dec 2022 13:05:49 +0100 Message-Id: <20221222120549.3958127-2-c.heiss@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221222120549.3958127-1-c.heiss@proxmox.com> References: <20221222120549.3958127-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.083 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH v2 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, 22 Dec 2022 12:06:26 -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 | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/api2/node/services.rs b/src/api2/node/services.rs index 0cc1857e..3d3b8501 100644 --- a/src/api2/node/services.rs +++ b/src/api2/node/services.rs @@ -76,12 +76,26 @@ 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"].as_str().or(status["SubState"].as_str()) + } 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 +131,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