initial commit
This commit is contained in:
70
examples/supervisor/run_supervisor.rs
Normal file
70
examples/supervisor/run_supervisor.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env cargo +nightly -Zscript
|
||||
//! ```cargo
|
||||
//! [dependencies]
|
||||
//! escargot = "0.5"
|
||||
//! tokio = { version = "1.0", features = ["full"] }
|
||||
//! log = "0.4"
|
||||
//! env_logger = "0.10"
|
||||
//! ```
|
||||
|
||||
use escargot::CargoBuild;
|
||||
use std::process::Command;
|
||||
use log::{info, error};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Initialize logging
|
||||
env_logger::init();
|
||||
|
||||
info!("Building and running Hero Supervisor with example configuration");
|
||||
|
||||
// Get the current directory (when running as cargo example, this is the crate root)
|
||||
let current_dir = std::env::current_dir()?;
|
||||
info!("Current directory: {}", current_dir.display());
|
||||
|
||||
// Path to the supervisor crate (current directory when running as example)
|
||||
let supervisor_crate_path = current_dir.clone();
|
||||
|
||||
// Path to the config file (in examples/supervisor subdirectory)
|
||||
let config_path = current_dir.join("examples/supervisor/config.toml");
|
||||
|
||||
if !config_path.exists() {
|
||||
error!("Config file not found: {}", config_path.display());
|
||||
return Err("Config file not found".into());
|
||||
}
|
||||
|
||||
info!("Using config file: {}", config_path.display());
|
||||
|
||||
// Build the supervisor binary using escargot
|
||||
info!("Building supervisor binary...");
|
||||
let supervisor_bin = CargoBuild::new()
|
||||
.bin("supervisor")
|
||||
.manifest_path(supervisor_crate_path.join("Cargo.toml"))
|
||||
.features("cli")
|
||||
.run()?;
|
||||
|
||||
info!("Supervisor binary built successfully");
|
||||
|
||||
// Run the supervisor with the config file
|
||||
info!("Starting supervisor with config: {}", config_path.display());
|
||||
|
||||
let mut cmd = Command::new(supervisor_bin.path());
|
||||
cmd.arg("--config")
|
||||
.arg(&config_path);
|
||||
|
||||
// Add environment variables for better logging
|
||||
cmd.env("RUST_LOG", "info");
|
||||
|
||||
info!("Executing: {:?}", cmd);
|
||||
|
||||
// Execute the supervisor
|
||||
let status = cmd.status()?;
|
||||
|
||||
if status.success() {
|
||||
info!("Supervisor completed successfully");
|
||||
} else {
|
||||
error!("Supervisor exited with status: {}", status);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user