| Crates.io | sal-service-manager |
| lib.rs | sal-service-manager |
| version | 0.1.0 |
| created_at | 2025-07-02 09:44:39.206191+00 |
| updated_at | 2025-07-02 09:44:39.206191+00 |
| description | SAL Service Manager - Cross-platform service management for dynamic worker deployment |
| homepage | |
| repository | https://git.threefold.info/herocode/sal |
| max_upload_size | |
| id | 1734838 |
| size | 151,628 |
A cross-platform service management library for the System Abstraction Layer (SAL). This crate provides a unified interface for managing system services across different platforms, enabling dynamic deployment of workers and services.
launchctl with plist managementzinit for lightweight service management (systemd also available)Add this to your Cargo.toml:
[dependencies]
sal-service-manager = "0.1.0"
Or use it as part of the SAL ecosystem:
[dependencies]
sal = { version = "0.1.0", features = ["service_manager"] }
This service manager was designed specifically for dynamic deployment of circle workers in freezone environments. When a new resident registers, you can instantly launch a dedicated circle worker:
use sal_service_manager::{create_service_manager, ServiceConfig};
use std::collections::HashMap;
// New resident registration triggers worker creation
fn deploy_circle_worker(resident_id: &str) -> Result<(), Box<dyn std::error::Error>> {
let manager = create_service_manager();
let mut env = HashMap::new();
env.insert("RESIDENT_ID".to_string(), resident_id.to_string());
env.insert("WORKER_TYPE".to_string(), "circle".to_string());
let config = ServiceConfig {
name: format!("circle-worker-{}", resident_id),
binary_path: "/usr/bin/circle-worker".to_string(),
args: vec!["--resident".to_string(), resident_id.to_string()],
working_directory: Some("/var/lib/circle-workers".to_string()),
environment: env,
auto_restart: true,
};
// Deploy the worker
manager.start(&config)?;
println!("✅ Circle worker deployed for resident: {}", resident_id);
Ok(())
}
Here is an example of the core service management API:
use sal_service_manager::{create_service_manager, ServiceConfig};
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let service_manager = create_service_manager();
let config = ServiceConfig {
name: "my-service".to_string(),
binary_path: "/usr/local/bin/my-service-executable".to_string(),
args: vec!["--config".to_string(), "/etc/my-service.conf".to_string()],
working_directory: Some("/var/tmp".to_string()),
environment: HashMap::new(),
auto_restart: true,
};
// Start a new service
service_manager.start(&config)?;
// Get the status of the service
let status = service_manager.status("my-service")?;
println!("Service status: {:?}", status);
// Stop the service
service_manager.stop("my-service")?;
Ok(())
}
Comprehensive examples are available in the SAL examples directory:
The primary use case - dynamically launching circle workers for new freezone residents:
# Run the circle worker management example
herodo examples/service_manager/circle_worker_manager.rhai
This example demonstrates:
A simpler example showing the core API:
# Run the basic usage example
herodo examples/service_manager/basic_usage.rhai
See examples/service_manager/README.md for detailed documentation.
Run the test suite:
cargo test -p sal-service-manager
For Rhai integration tests:
cargo test -p sal-service-manager --features rhai
To test the service manager with real Rhai scripts using herodo, first build herodo:
./build_herodo.sh
Then run Rhai scripts that use the service manager:
herodo your_service_script.rhai
Make sure zinit is installed and running:
# Start zinit with default socket
zinit -s /tmp/zinit.sock init
No additional setup required - uses the built-in launchctl system.
launchctl for service managementzinit for service management (systemd also available as alternative)