From 4b1a544923b5ab1bf44268d08bb7b502ba130274 Mon Sep 17 00:00:00 2001 From: Vassiliy Yegorov Date: Tue, 9 Jun 2026 20:00:41 +0700 Subject: [PATCH] feat(daemon): entrypoint with single-instance lock and lazy socket bind Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/spaceshd/src/launchd.rs | 4 ++++ crates/spaceshd/src/main.rs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 crates/spaceshd/src/launchd.rs diff --git a/crates/spaceshd/src/launchd.rs b/crates/spaceshd/src/launchd.rs new file mode 100644 index 0000000..46ae93d --- /dev/null +++ b/crates/spaceshd/src/launchd.rs @@ -0,0 +1,4 @@ +use anyhow::Result; +pub fn install_agent() -> Result<()> { + anyhow::bail!("install-agent implemented in Task 16") +} diff --git a/crates/spaceshd/src/main.rs b/crates/spaceshd/src/main.rs index 4950730..5ac916a 100644 --- a/crates/spaceshd/src/main.rs +++ b/crates/spaceshd/src/main.rs @@ -1,8 +1,35 @@ +mod launchd; mod lifecycle; mod registry; mod server; mod surface; -fn main() { - println!("spaceshd skeleton"); +use anyhow::Result; + +#[tokio::main] +async fn main() -> Result<()> { + let arg = std::env::args().nth(1); + match arg.as_deref() { + Some("install-agent") => { + launchd::install_agent()?; + println!("launchd agent installed"); + Ok(()) + } + Some("--help") | Some("-h") => { + println!("spaceshd [install-agent]"); + Ok(()) + } + _ => run_daemon().await, + } +} + +async fn run_daemon() -> Result<()> { + let Some(_lock) = lifecycle::acquire_instance_lock()? else { + eprintln!("another spaceshd is already running"); + return Ok(()); + }; + lifecycle::clear_stale_socket()?; + let sock = lifecycle::socket_path()?; + eprintln!("spaceshd listening on {}", sock.display()); + server::serve(&sock).await }