Embedded Server Lifecycle
Radium includes automatic server lifecycle management that embeds the gRPC server within client applications, eliminating the need for manual server management.
Overviewβ
The embedded server automatically starts and stops as needed, providing a seamless experience across all Radium interfaces:
- Desktop App: Server automatically starts when the app launches
- CLI/TUI: Server starts on-demand when commands require it
- Standalone: Still available as a separate binary for advanced use cases
How It Worksβ
Automatic Lifecycle Managementβ
The embedded server manager (EmbeddedServer) handles:
- Automatic Startup: Server starts in a background task when needed
- Readiness Detection: Waits for server to be ready before accepting connections
- Graceful Shutdown: Properly shuts down when the application exits
- Health Monitoring: Monitors server health and handles failures
Server Configurationβ
The embedded server uses the same configuration as the standalone server:
[server]
address = "127.0.0.1:50051"
grpc_web_enabled = true
grpc_web_address = "127.0.0.1:50052"
Client Integrationβ
Clients automatically connect to the embedded server:
- Desktop App: Connects to embedded server on startup
- CLI/TUI: Server starts automatically when first command is executed
- External Clients: Can connect to embedded server if address is known
Benefitsβ
Simplified Deploymentβ
- No separate server process to manage
- No manual server startup required
- Automatic resource cleanup on exit
Better User Experienceβ
- Faster startup times (server starts in background)
- Seamless integration with client applications
- No configuration needed for basic usage
Development Flexibilityβ
- Can still run standalone server for testing
- Embedded server can be disabled if needed
- Same configuration works for both modes
Architectureβ
The embedded server runs in a separate Tokio task:
let mut server = EmbeddedServer::new(config);
server.start().await?;
server.wait_for_ready(timeout).await?;
// Server is now ready to accept connections
Lifecycle Statesβ
- Initialized: Server created but not started
- Starting: Server task spawned, binding to address
- Ready: Server accepting connections
- Shutting Down: Graceful shutdown in progress
- Stopped: Server task completed
Standalone Modeβ
For advanced use cases, you can still run the server standalone:
# Run standalone server
cargo run --bin radium-core
# Or via npm
npm run server
The standalone server provides:
- Manual control over server lifecycle
- Easier debugging and monitoring
- Integration with external process managers
Troubleshootingβ
Server Fails to Startβ
If the embedded server fails to start:
- Check if the port is already in use
- Verify server configuration
- Check application logs for errors
Server Not Readyβ
If the server doesn't become ready:
- Increase the readiness timeout
- Check network configuration
- Verify server logs for binding errors
Connection Issuesβ
If clients can't connect:
- Verify server address configuration
- Check firewall settings
- Ensure server is in "Ready" state
Related Documentationβ
- Architecture Overview - System architecture
- Configuration Guide - Server configuration
- CLI Reference - CLI usage and commands