hematite/agent/
searx_lifecycle.rs1use crate::agent::config::HematiteConfig;
2use std::process::Command;
3use tokio::time::{timeout, Duration};
4
5pub async fn is_searx_responding(url: &str) -> bool {
7 let client = reqwest::Client::builder()
8 .timeout(Duration::from_millis(500))
9 .build()
10 .unwrap_or_default();
11
12 match timeout(Duration::from_millis(600), client.get(url).send()).await {
13 Ok(Ok(resp)) => resp.status().is_success() || resp.status().as_u16() == 403, _ => false,
15 }
16}
17
18pub async fn boot_searx_if_needed(config: &HematiteConfig) {
20 if !config.auto_start_searx {
21 return;
22 }
23
24 let url = config
25 .searx_url
26 .as_deref()
27 .unwrap_or("http://localhost:8080");
28
29 if is_searx_responding(url).await {
31 return;
32 }
33
34 let script_path = "scripts/setup-searxng.ps1";
37 if std::path::Path::new(script_path).exists() {
38 let _ = Command::new("powershell")
39 .arg("-ExecutionPolicy")
40 .arg("Bypass")
41 .arg("-File")
42 .arg(script_path)
43 .spawn();
44 }
45}