actr_cli/commands/
restart.rs1use crate::commands::run::RunCommand;
4use crate::commands::runtime_state::{RuntimeStateStore, resolve_hyper_dir};
5use crate::commands::stop::StopCommand;
6use crate::core::{Command, CommandContext, CommandResult, ComponentType};
7use anyhow::Result;
8use async_trait::async_trait;
9use clap::Args;
10use std::path::PathBuf;
11
12#[derive(Args, Debug)]
13pub struct RestartCommand {
14 #[arg(value_name = "WID")]
16 pub wid: String,
17
18 #[arg(short = 'c', long = "config", value_name = "FILE")]
20 pub config: Option<PathBuf>,
21
22 #[arg(long = "hyper-dir", value_name = "DIR")]
24 pub hyper_dir: Option<PathBuf>,
25
26 #[arg(long = "timeout", default_value_t = 5)]
28 pub timeout: u64,
29
30 #[arg(long = "force")]
32 pub force: bool,
33}
34
35#[async_trait]
36impl Command for RestartCommand {
37 async fn execute(&self, ctx: &CommandContext) -> Result<CommandResult> {
38 let hyper_dir = resolve_hyper_dir(self.config.as_deref(), self.hyper_dir.as_deref())?;
39 let store = RuntimeStateStore::new(hyper_dir);
40 let entry = store.resolve_wid_prefix(&self.wid).await?;
41
42 let full_wid = entry.record.wid.clone();
43 let config_path = self
44 .config
45 .clone()
46 .unwrap_or_else(|| entry.record.config_path.clone());
47
48 println!("Stopping runtime: {}", entry.wid_short());
49 StopCommand {
50 wid: full_wid.clone(),
51 config: self.config.clone(),
52 hyper_dir: self.hyper_dir.clone(),
53 timeout: self.timeout,
54 force: self.force,
55 }
56 .execute(ctx)
57 .await?;
58
59 println!("Starting runtime with config: {}", config_path.display());
60 RunCommand {
61 config: Some(config_path),
62 hyper_dir: self.hyper_dir.clone(),
63 detach: true,
64 internal_detached_child: false,
65 internal_wid: Some(full_wid),
66 web: false,
67 port: None,
68 }
69 .execute(ctx)
70 .await
71 }
72
73 fn required_components(&self) -> Vec<ComponentType> {
74 vec![]
75 }
76
77 fn name(&self) -> &str {
78 "restart"
79 }
80
81 fn description(&self) -> &str {
82 "Restart a detached runtime instance"
83 }
84}