node-app-build 6.2.0

Mini app developer CLI: scaffold, validate, package node-app-* Debian packages
//! {{name}} — a standalone Rust daemon scaffolded by
//! `node-app new --profile standalone-native`.
//!
//! Lifecycle:
//!   - systemd starts this process via `node-app-{{name}}.service`.
//!   - We bind a Unix socket at `NODE_APP_SOCKET` (default
//!     `/run/node-app-{{name}}.sock`) and speak JSON-RPC 2.0. Wire your
//!     dispatcher in `run_service()` below.
//!   - The platform routes inbound `{{name}}.*` capability invocations to
//!     that socket. Outbound capability calls dial `/run/node/control.sock`
//!     (use the `Group=node` systemd unit so the SO_PEERCRED check passes).
//!
//! This app is NOT eligible for the shared Bun runtime (#810) — see
//! AGENTS.md for the rationale.

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt()
        .with_env_filter(
            tracing_subscriber::EnvFilter::try_from_env("NODE_APP_LOG")
                .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
        )
        .init();

    let socket = std::env::var("NODE_APP_SOCKET")
        .unwrap_or_else(|_| "/run/node-app-{{name}}.sock".to_string());

    tracing::info!(socket = %socket, "starting service");

    run_service(&socket).await?;

    // Graceful shutdown on SIGTERM / Ctrl-C.
    tokio::signal::ctrl_c().await?;
    tracing::info!("shutting down");
    Ok(())
}

/// Wire your UDS JSON-RPC dispatcher here. Skeleton intentionally minimal —
/// real implementations bind the socket, accept connections, and read
/// line-delimited JSON-RPC 2.0 frames.
async fn run_service(_socket_path: &str) -> anyhow::Result<()> {
    // TODO: implement your service logic.
    // Example structure (see the bun standalone profile for a working
    // line-delimited JSON-RPC dispatcher):
    //
    //   if Path::new(_socket_path).exists() {
    //       std::fs::remove_file(_socket_path)?;
    //   }
    //   let listener = tokio::net::UnixListener::bind(_socket_path)?;
    //   loop {
    //       let (stream, _) = listener.accept().await?;
    //       tokio::spawn(handle_connection(stream));
    //   }
    Ok(())
}