MCPcopy Index your code
hub / github.com/NativeScript/SimDeck / kill_all_services

Function kill_all_services

packages/server/src/main.rs:1548–1625  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1546}
1547
1548fn kill_all_services() -> anyhow::Result<()> {
1549 let mut killed = Vec::new();
1550 let mut stale = Vec::new();
1551 let mut killed_groups = HashSet::new();
1552 for pid in service::kill_installed()? {
1553 if killed_groups.insert(pid) {
1554 killed.push(serde_json::json!({
1555 "pid": pid,
1556 "launchAgent": true,
1557 }));
1558 }
1559 }
1560 if let Some(metadata) = read_service_metadata().ok().flatten() {
1561 if process_exists(metadata.pid) {
1562 terminate_process_group(metadata.pid, Duration::from_secs(5));
1563 if killed_groups.insert(metadata.pid) {
1564 killed.push(serde_json::json!({
1565 "pid": metadata.pid,
1566 "projectRoot": metadata.project_root,
1567 "url": metadata.http_url,
1568 }));
1569 }
1570 }
1571 let _ = fs::remove_file(service_metadata_path()?);
1572 }
1573 for metadata_path in service_metadata_paths()? {
1574 let Some(metadata) = fs::read_to_string(&metadata_path)
1575 .ok()
1576 .and_then(|data| serde_json::from_str::<ServiceMetadata>(&data).ok())
1577 else {
1578 let _ = fs::remove_file(&metadata_path);
1579 stale.push(metadata_path);
1580 continue;
1581 };
1582 if process_exists(metadata.pid) {
1583 terminate_process_group(metadata.pid, Duration::from_secs(5));
1584 let _ = fs::remove_file(&metadata_path);
1585 if killed_groups.insert(metadata.pid) {
1586 killed.push(serde_json::json!({
1587 "pid": metadata.pid,
1588 "projectRoot": metadata.project_root,
1589 "url": metadata.http_url,
1590 }));
1591 }
1592 } else {
1593 let _ = fs::remove_file(&metadata_path);
1594 stale.push(metadata_path);
1595 }
1596 }
1597 for process in service_run_processes()? {
1598 if killed_groups.insert(process.pgid) {
1599 terminate_process_group(process.pgid, Duration::from_secs(5));
1600 killed.push(serde_json::json!({
1601 "pid": process.pgid,
1602 "metadataPath": process.metadata_path,
1603 "process": true,
1604 }));
1605 }

Callers 1

mainFunction · 0.85

Calls 10

kill_installedFunction · 0.85
read_service_metadataFunction · 0.85
service_metadata_pathFunction · 0.85
service_metadata_pathsFunction · 0.85
service_run_processesFunction · 0.85
println_jsonFunction · 0.85
insertMethod · 0.80
process_existsFunction · 0.70
terminate_process_groupFunction · 0.70

Tested by

no test coverage detected