MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / connect_or_start

Method connect_or_start

atomic-client/src/lib.rs:113–150  ·  view source on GitHub ↗

Connect, starting the daemon when it is down (D4: a local client may start/restart the daemon and retry — never open storage itself).

()

Source from the content-addressed store, hash-verified

111 /// Connect, starting the daemon when it is down (D4: a local client may
112 /// start/restart the daemon and retry — never open storage itself).
113 pub async fn connect_or_start() -> Result<Self, String> {
114 if let Ok(client) = Self::connect_existing().await {
115 return Ok(client);
116 }
117
118 let binary = std::env::var_os(ENV_DAEMON_BIN)
119 .map(PathBuf::from)
120 .unwrap_or_else(|| PathBuf::from("atomicd"));
121 let socket = socket_path();
122 if let Some(parent) = socket.parent() {
123 std::fs::create_dir_all(parent).map_err(|error| {
124 format!(
125 "failed to create daemon runtime dir {}: {error}",
126 parent.display()
127 )
128 })?;
129 }
130 Command::new(&binary)
131 .arg("serve")
132 .stdin(Stdio::null())
133 .stdout(Stdio::null())
134 .stderr(Stdio::null())
135 .spawn()
136 .map_err(|error| {
137 format!(
138 "failed to start the atomic daemon ({}): {error}",
139 binary.display()
140 )
141 })?;
142
143 for _ in 0..200 {
144 if let Ok(client) = Self::connect_existing().await {
145 return Ok(client);
146 }
147 tokio::time::sleep(Duration::from_millis(25)).await;
148 }
149 Err("atomicd did not become healthy before timeout".to_string())
150 }
151
152 /// Liveness probe (the negotiation pair's first half).
153 pub async fn health(&self) -> Result<HealthResponse, tonic::Status> {

Callers

nothing calls this directly

Calls 3

socket_pathFunction · 0.85
parentMethod · 0.80
spawnMethod · 0.80

Tested by

no test coverage detected