diff --git a/examples/zinit/zinit_basic.rhai b/examples/zinit/zinit_basic.rhai index b89b862..492bca1 100644 --- a/examples/zinit/zinit_basic.rhai +++ b/examples/zinit/zinit_basic.rhai @@ -1,7 +1,7 @@ // Basic example of using the Zinit client in Rhai // Socket path for Zinit -let socket_path = "/var/run/zinit.sock"; +let socket_path = "/tmp/zinit.sock"; // List all services print("Listing all services:"); diff --git a/installers/base.rhai b/installers/base.rhai index 705ca20..225c8ec 100644 --- a/installers/base.rhai +++ b/installers/base.rhai @@ -17,13 +17,31 @@ fn zinit(){ let name="zinit"; let url="https://github.com/threefoldtech/zinit/releases/download/v0.2.25/zinit-linux-x86_64"; download_file(url,`/tmp/${name}`,5000); + screen_kill("zinit"); copy_bin(`/tmp/${name}`); delete(`/tmp/${name}`); screen_new("zinit", "zinit init"); + sleep(1); + let socket_path = "/tmp/zinit.sock"; + + // List all services + print("Listing all services:"); + let services = zinit_list(socket_path); + + if services.is_empty() { + print("No services found."); + } else { + // Iterate over the keys of the map + for name in services.keys() { + let state = services[name]; + print(`${name}: ${state}`); + } + } + } platform_check_linux_x86(); -// mycelium(); zinit(); +// mycelium(); "done" diff --git a/src/process/screen.rs b/src/process/screen.rs index b6a8de0..b8091e3 100644 --- a/src/process/screen.rs +++ b/src/process/screen.rs @@ -44,5 +44,6 @@ pub fn new(name: &str, cmd: &str) -> Result<()> { pub fn kill(name: &str) -> Result<()> { let cmd = format!("screen -S {} -X quit", name); run_command(&cmd)?; + std::thread::sleep(std::time::Duration::from_millis(500)); Ok(()) } \ No newline at end of file diff --git a/src/rhai/zinit.rs b/src/rhai/zinit.rs index 2167281..a84c1b3 100644 --- a/src/rhai/zinit.rs +++ b/src/rhai/zinit.rs @@ -5,6 +5,7 @@ use crate::rhai::error::ToRhaiError; use crate::zinit_client as client; use rhai::{Array, Dynamic, Engine, EvalAltResult, Map}; +use std::path::Path; use serde_json::{json, Value}; use tokio::runtime::Runtime; @@ -55,6 +56,12 @@ fn get_runtime() -> Result> { /// /// Lists all services managed by Zinit. pub fn zinit_list(socket_path: &str) -> Result> { + if !Path::new(socket_path).exists() { + return Err(Box::new(EvalAltResult::ErrorRuntime( + format!("Zinit socket not found at '{}'", socket_path).into(), + rhai::Position::NONE, + ))); + } let rt = get_runtime()?; let result = rt.block_on(async { client::list(socket_path).await });