Expand description
§Daemon Lifecycle Management
This module provides comprehensive daemon lifecycle management for the Air daemon service, responsible for managing background processes in the Land code editor ecosystem.
§Architecture Overview
The daemon follows VSCode’s daemon architecture pattern:
- Reference: VSCode service management (Dependency/Microsoft/Editor/src/vs/base/node/processexitorutility)
- Singleton enforcement through PID file locking
- Platform-native service integration (systemd, launchd, Windows Service)
- Graceful shutdown coordination with Mountain (main editor process)
- Resource cleanup and state persistence across restarts
§Core Responsibilities
-
Process Management
- PID file creation, validation, and cleanup
- Checksum-based PID file integrity verification
- Process existence validation and stale detection
- Race condition protection for lock acquisition
- Timeout handling for all async operations
-
Service Installation
- systemd service generation and installation (Linux)
- launchd plist generation and installation (macOS)
- Windows Service registration (Windows using winsvc)
- Service validation and health checks
- Post-installation verification
-
Lifecycle Coordination
- Lock acquisition with atomic operations
- Graceful shutdown signals
- Resource cleanup on errors
- State persistence and recovery
-
Platform Integration
- Linux: systemd socket activation support
- macOS: launchd session management
- Windows: Windows Service API integration
- Cross-platform log rotation
§TODO Items
- Implement Windows winsvc integration for actual service registration
- Add systemd socket activation support
- Implement daemon auto-update notifications
- Add crash recovery and state restoration
- Implement daemon health monitoring with metrics
- Add log rotation for daemon logs
- Implement daemon upgrade path (in-place hot reload)
- Add daemon configuration reloading without restart
- Implement grace period for Mountain shutdown coordination
- Add daemon sandbox support for security isolation
§Platform-Specific Considerations
§Linux (systemd)
- PID file location:
/var/run/Air.pid - Service file:
/etc/systemd/system/Air-daemon.service - Requires root privileges for installation
- Supports socket activation and notify-ready
§macOS (launchd)
- PID file location:
/tmp/Air.pid - Service file:
/Library/LaunchDaemons/Air-daemon.plist - Requires root privileges for system daemon
- Supports launchctl unload/start/stop commands
§Windows
- PID file location:
C:\ProgramData\Air\Air.pid - Service registration via SCManager API
- Requires Administrator privileges
- Uses winsvc crate or similar for service management
§Security Considerations
- PID file protected with checksum to prevent tampering
- Directory creation with secure permissions (0700)
- SUID/SGID not used for security
- User-level isolation for multi-user systems
§Error Handling
All operations return Result<T> with comprehensive error types:
ServiceUnavailable: Daemon already running or unavailableFileSystem: PID file or directory operations failedPermissionDenied: Insufficient privileges for service operations
Structs§
- Daemon
Manager - Daemon lifecycle manager
- Daemon
Status - Daemon status information
- Platform
Info - Platform-specific daemon information