feat: Adaptervertrag mit Dienststeuerung und Version (Studio, Ollama, llama.cpp, Attrappe; #1198)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -475,6 +475,44 @@ impl Engine for StudioEngine {
|
||||
self.ensure_up_impl().await
|
||||
}
|
||||
|
||||
fn dienst(&self) -> crate::types::Dienst {
|
||||
match self.config.systemd_unit.as_deref() {
|
||||
Some(einheit) if !einheit.is_empty() => crate::types::Dienst::Systemd {
|
||||
einheit: einheit.to_string(),
|
||||
},
|
||||
_ => crate::types::Dienst::Keiner,
|
||||
}
|
||||
}
|
||||
|
||||
async fn dienst_stoppen(&self) -> Result<()> {
|
||||
if self.config.systemd_unit.is_none() {
|
||||
return Err(AdapterError::Stop(
|
||||
"Für das Studio ist keine systemd-Einheit eingestellt.".to_string(),
|
||||
));
|
||||
}
|
||||
self.systemctl("stop").await
|
||||
}
|
||||
|
||||
async fn dienst_neustarten(&self) -> Result<()> {
|
||||
if self.config.systemd_unit.is_none() {
|
||||
return Err(AdapterError::Stop(
|
||||
"Für das Studio ist keine systemd-Einheit eingestellt.".to_string(),
|
||||
));
|
||||
}
|
||||
self.systemctl("restart").await?;
|
||||
let ende = std::time::Instant::now() + Duration::from_secs(self.config.start_timeout_secs);
|
||||
while std::time::Instant::now() < ende {
|
||||
if self.reachable(Duration::from_secs(3)).await {
|
||||
return Ok(());
|
||||
}
|
||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||
}
|
||||
Err(AdapterError::NotReady {
|
||||
seconds: self.config.start_timeout_secs,
|
||||
log_tail: format!("{} antwortet nach dem Neustart nicht", self.base()),
|
||||
})
|
||||
}
|
||||
|
||||
async fn voices_reachable(&self) -> bool {
|
||||
self.reachable(Duration::from_secs(3)).await
|
||||
}
|
||||
@ -1017,6 +1055,32 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dienststeuerung_gibt_es_nur_mit_einheit() {
|
||||
use crate::engine::Engine;
|
||||
assert_eq!(engine(9).dienst(), crate::types::Dienst::Keiner);
|
||||
assert!(engine(9).dienst_stoppen().await.is_err());
|
||||
let e = mit_systemctl(9, "true");
|
||||
assert_eq!(
|
||||
e.dienst(),
|
||||
crate::types::Dienst::Systemd {
|
||||
einheit: "qwen-studio.service".to_string()
|
||||
}
|
||||
);
|
||||
// „true“ meldet Erfolg: Stopp gelingt, Neustart scheitert nach der Wartezeit (kein Studio auf Port 9).
|
||||
assert!(e.dienst_stoppen().await.is_ok());
|
||||
assert!(matches!(
|
||||
e.dienst_neustarten().await.unwrap_err(),
|
||||
AdapterError::NotReady { .. }
|
||||
));
|
||||
// Scheitert systemctl, steht das in der Meldung.
|
||||
let err = mit_systemctl(9, "false")
|
||||
.dienst_stoppen()
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(err.to_string().contains("schlug fehl"), "{err}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn laeuft_das_studio_wird_systemctl_nicht_gerufen() {
|
||||
let port = fake_studio().await;
|
||||
|
||||
Reference in New Issue
Block a user