[pbs-devel] [PATCH v2 proxmox 01/16] rest-server: add handle_worker from backup debug cli

Lukas Wagner l.wagner at proxmox.com
Wed Jan 18 08:36:47 CET 2023


The function has now multiple users, so it is moved
here.

Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 proxmox-rest-server/src/worker_task.rs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs
index 44d8111..6263ce7 100644
--- a/proxmox-rest-server/src/worker_task.rs
+++ b/proxmox-rest-server/src/worker_task.rs
@@ -14,6 +14,7 @@ use nix::fcntl::OFlag;
 use once_cell::sync::OnceCell;
 use serde::{Deserialize, Serialize};
 use serde_json::{json, Value};
+use tokio::signal::unix::SignalKind;
 use tokio::sync::oneshot;
 
 use proxmox_lang::try_block;
@@ -1056,3 +1057,25 @@ pub fn abort_local_worker(upid: UPID) {
         worker.request_abort();
     }
 }
+
+/// Wait for locally running worker, responding to SIGINT properly
+pub async fn handle_worker(upid_str: &str) -> Result<(), Error> {
+    let upid: UPID = upid_str.parse()?;
+    let mut signal_stream = tokio::signal::unix::signal(SignalKind::interrupt())?;
+    let abort_future = async move {
+        while signal_stream.recv().await.is_some() {
+            println!("got shutdown request (SIGINT)");
+            abort_local_worker(upid.clone());
+        }
+        Ok::<_, Error>(())
+    };
+
+    let result_future = wait_for_local_worker(upid_str);
+
+    futures::select! {
+        result = result_future.fuse() => result?,
+        abort = abort_future.fuse() => abort?,
+    };
+
+    Ok(())
+}
-- 
2.30.2






More information about the pbs-devel mailing list