(
options: ServiceLaunchOptions,
)
| 1266 | } |
| 1267 | |
| 1268 | fn ensure_singleton_service_with_status( |
| 1269 | options: ServiceLaunchOptions, |
| 1270 | ) -> anyhow::Result<(ServiceMetadata, bool)> { |
| 1271 | let active = service::active()?; |
| 1272 | if let Some(result) = active.as_ref() { |
| 1273 | let metadata = metadata_from_launch_agent(result.clone())?; |
| 1274 | if service_is_healthy(&metadata) |
| 1275 | && service_binary_matches_current(&metadata)? |
| 1276 | && service_matches_launch_options(&metadata, &options) |
| 1277 | { |
| 1278 | return Ok((metadata, false)); |
| 1279 | } |
| 1280 | } |
| 1281 | if let Some(metadata) = read_service_metadata().ok().flatten() { |
| 1282 | let healthy = service_is_healthy(&metadata); |
| 1283 | let same_binary = service_binary_matches_current(&metadata)?; |
| 1284 | if healthy && same_binary && service_matches_launch_options(&metadata, &options) { |
| 1285 | return Ok((metadata, false)); |
| 1286 | } |
| 1287 | let active_on_metadata_port = active |
| 1288 | .as_ref() |
| 1289 | .is_some_and(|result| result.port == metadata.port); |
| 1290 | if !active_on_metadata_port && (!healthy || same_binary) { |
| 1291 | let _ = terminate_service_metadata(&metadata); |
| 1292 | } |
| 1293 | if healthy && !same_binary && !active_on_metadata_port { |
| 1294 | warn!( |
| 1295 | existing = %metadata.binary_path.display(), |
| 1296 | "Keeping existing SimDeck service on its port because it was started by another binary" |
| 1297 | ); |
| 1298 | } |
| 1299 | } |
| 1300 | Ok((start_project_service(options)?, true)) |
| 1301 | } |
| 1302 | |
| 1303 | fn ensure_launch_agent_service(options: ServiceLaunchOptions) -> anyhow::Result<ServiceMetadata> { |
| 1304 | if let Some(metadata) = read_service_metadata().ok().flatten() { |
no test coverage detected