MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / ensure_singleton_service_with_status

Function ensure_singleton_service_with_status

packages/server/src/main.rs:1268–1301  ·  view source on GitHub ↗
(
    options: ServiceLaunchOptions,
)

Source from the content-addressed store, hash-verified

1266}
1267
1268fn 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
1303fn ensure_launch_agent_service(options: ServiceLaunchOptions) -> anyhow::Result<ServiceMetadata> {
1304 if let Some(metadata) = read_service_metadata().ok().flatten() {

Callers 3

ensure_singleton_serviceFunction · 0.85
run_default_serviceFunction · 0.85

Calls 9

activeFunction · 0.85
service_is_healthyFunction · 0.85
read_service_metadataFunction · 0.85
start_project_serviceFunction · 0.85
cloneMethod · 0.65

Tested by

no test coverage detected