feat(daemon): entrypoint with single-instance lock and lazy socket bind
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
pub fn install_agent() -> Result<()> {
|
||||||
|
anyhow::bail!("install-agent implemented in Task 16")
|
||||||
|
}
|
||||||
@@ -1,8 +1,35 @@
|
|||||||
|
mod launchd;
|
||||||
mod lifecycle;
|
mod lifecycle;
|
||||||
mod registry;
|
mod registry;
|
||||||
mod server;
|
mod server;
|
||||||
mod surface;
|
mod surface;
|
||||||
|
|
||||||
fn main() {
|
use anyhow::Result;
|
||||||
println!("spaceshd skeleton");
|
|
||||||
|
#[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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user