aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / spark-supervisor / src / main.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | fn default_supervisor_config_path() -> PathBuf { |
| 17 | let home = std::env::var("HOME") |
| 18 | .or_else(|_| std::env::var("USERPROFILE")) |
| 19 | .unwrap_or_else(|_| ".".to_string()); |
| 20 | PathBuf::from(home).join(".config/aien/supervisor.toml") |
| 21 | } |
| 22 | |
| 23 | use clap::{Parser, Subcommand}; |
| 24 | use std::path::PathBuf; |
| 25 | use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; |
| 26 | |
| 27 | use spark_supervisor::config::SupervisorConfig; |
| 28 | use spark_supervisor::supervisor::Supervisor; |
| 29 | |
| 30 | /// Exit code for `status`: live state is only held inside the running daemon. |
| 31 | const EXIT_STATUS_UNAVAILABLE: i32 = 2; |
| 32 | |
| 33 | const STATUS_UNAVAILABLE_MSG: &str = "spark-supervisor status: live status is not available from a separate process. \ |
| 34 | The supervisor keeps service state in the memory of the `run` process and exposes no IPC or status endpoint, \ |
| 35 | so a new process cannot see it. Check the daemon's log output instead."; |
| 36 | |
| 37 | #[derive(Parser, Debug)] |
| 38 | #[command( |
| 39 | name = "spark-supervisor", |
| 40 | about = "Sovereign Native Process Supervisor for SparkOS" |
| 41 | )] |
| 42 | struct Cli { |
| 43 | #[arg(long, default_value_os_t = default_supervisor_config_path())] |
| 44 | config: PathBuf, |
| 45 | |
| 46 | #[command(subcommand)] |
| 47 | command: Option<Commands>, |
| 48 | } |
| 49 | |
| 50 | #[derive(Subcommand, Debug)] |
| 51 | enum Commands { |
| 52 | Run, |
| 53 | /// Refuses with a non-zero exit: there is no channel to a running daemon. |
| 54 | Status, |
| 55 | Check, |
| 56 | } |
| 57 | |
| 58 | #[tokio::main] |
| 59 | async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 60 | let cli = Cli::parse(); |
| 61 | let command = cli.command.unwrap_or(Commands::Run); |
| 62 | |
| 63 | // Refuse before touching the config so `status` never writes a default file. |
| 64 | if matches!(command, Commands::Status) { |
| 65 | eprintln!("{}", STATUS_UNAVAILABLE_MSG); |
| 66 | std::process::exit(EXIT_STATUS_UNAVAILABLE); |
| 67 | } |
| 68 | |
| 69 | tracing_subscriber::registry() |
| 70 | .with( |
| 71 | tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()), |
| 72 | ) |
| 73 | .with(tracing_subscriber::fmt::layer()) |
| 74 | .init(); |
| 75 | |
| 76 | if !cli.config.exists() { |
| 77 | eprintln!( |
| 78 | "Config file not found at {:?}. Generating default supervisor.toml...", |
| 79 | cli.config |
| 80 | ); |
| 81 | if let Some(p) = cli.config.parent() { |
| 82 | let _ = std::fs::create_dir_all(p); |
| 83 | } |
| 84 | let home = std::env::var("HOME") |
| 85 | .or_else(|_| std::env::var("USERPROFILE")) |
| 86 | .unwrap_or_else(|_| ".".to_string()); |
| 87 | let default_toml = format!( |
| 88 | "[services.cortex]\ncommand = \"{}/.local/bin/cortex-rs\"\nargs = [\"--port\", \"18080\"]\nrestart = \"always\"\nhealth_url = \"http://127.0.0.1:18080/health\"\n\n[services.cockpit]\ncommand = \"{}/.local/bin/spark-cockpit-rs\"\nrestart = \"always\"\nhealth_url = \"http://127.0.0.1:18095/health\"\n", |
| 89 | home, home |
| 90 | ); |
| 91 | std::fs::write(&cli.config, default_toml)?; |
| 92 | } |
| 93 | |
| 94 | let config = SupervisorConfig::load_from_file(&cli.config)?; |
| 95 | |
| 96 | match command { |
| 97 | Commands::Run => { |
| 98 | Supervisor::new(config).run_daemon().await?; |
| 99 | } |
| 100 | Commands::Status => unreachable!("handled above"), |
| 101 | Commands::Check => { |
| 102 | println!("Configuration {:?} is valid.", cli.config); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | Ok(()) |
| 107 | } |