Main

Function Main 

Source
pub(crate) async fn Main() -> Result<(), Box<dyn Error + Send + Sync>>
Expand description

The main asynchronous function that sets up and runs the Air daemon

This is the primary entry point for the Air background service. It coordinates all initialization, starts the gRPC server, manages the daemon lifecycle, and handles graceful shutdown.

§Startup Sequence

  1. Initialize logging and observability (metrics, tracing)
  2. Parse command-line arguments (for CLI commands or daemon config)
  3. Load configuration (with validation)
  4. Acquire daemon lock (ensure single instance)
  5. Initialize application state
  6. Create and register core services
  7. Start gRPC server (Vine protocol)
  8. Start background tasks and monitoring
  9. Wait for shutdown signal
  10. Graceful shutdown sequence

§Defensive Coding

All operations include:

  • Input validation and sanitization
  • Timeout handling for async operations
  • Error recovery and logging
  • Resource cleanup on errors
  • Panic handling in critical sections

§TODO

  • Implement configuration hot-reload signal handling (SIGHUP)
  • Add startup timeout and failure recovery
  • Implement daemon mode forking (Unix)
  • Add Windows service integration
  • Implement crash recovery and restart
  • Add pre-flight environment checks
  • Implement feature flag system