The same lexer-based splitter as S12b, now with explicit re-exports: every moved free fn comes back to its module under its old name and old visibility (cfg attributes carried), so a name can never clash with another glob import. 162 module files of leleka-runtime (68), cuda-driver (84), deploy (10), cpu-sys, igpu and leleka-memory are split into groups of about 250 lines; types, constants, macros, nested modules and tests stay. Not touched: the files kar-off-ab edits, crate roots (lib.rs, main.rs, bin/*), and giant single impl blocks (next). This changes codegen-unit placement of engine code, so it is covered by the bitwise replay and the paired A/B on the 5090, not by a binary comparison.
172 lines
5.2 KiB
Rust
172 lines
5.2 KiB
Rust
//! Execution of the plan. Every step is idempotent and can be repeated after a crash: downloads resume
|
|
//! (`.part` files), verified assets carry a stamp (path, size, mtime) so a re-run does not hash 140 GB again,
|
|
//! generated files are rewritten only when their content changes, and secrets are never rotated.
|
|
use crate::{
|
|
config::{
|
|
ENV_HEADER, GATEWAY_TOKEN_ENV, RUNTIME_TOKEN_ENV, RunConfig, merge_env, new_token,
|
|
to_file_text,
|
|
},
|
|
facts::parse_env_file,
|
|
http,
|
|
layout::{BINARIES, MANIFEST, MTP_FILES, Paths},
|
|
plan::{
|
|
CUBLAS_SHA256, CUBLAS_URL, CUBLAS_VERSION, Context, FsState, Mode, Step, StepState,
|
|
UnitScopeTag, plan_steps,
|
|
},
|
|
profile::ARCHIVE_BYTES,
|
|
supervisor::{valid_token, write_private},
|
|
units,
|
|
};
|
|
use serde::{Deserialize, Serialize};
|
|
use sha2::{Digest, Sha256};
|
|
use std::{
|
|
io::Read,
|
|
path::{Path, PathBuf},
|
|
process::Stdio,
|
|
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
|
|
};
|
|
use tokio::{io::AsyncReadExt, io::AsyncWriteExt, process::Command};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
// stamps
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct FileStamp {
|
|
pub path: String,
|
|
pub size: u64,
|
|
pub mtime_ns: u128,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
struct StampFile {
|
|
leleka_version: String,
|
|
what: String,
|
|
files: Vec<FileStamp>,
|
|
verified_unix: u64,
|
|
}
|
|
|
|
/// Run every `Todo` step of the plan up to (not including) the start of the service. Returns the steps as
|
|
/// re-planned after the work, which the caller prints in `--json` mode.
|
|
/// What the preparation changed that a running service does not see until it restarts.
|
|
#[derive(Debug, Default, PartialEq, Eq)]
|
|
pub struct Changes {
|
|
pub binaries: usize,
|
|
pub configs: usize,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
mod say_fn;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::binaries_state;
|
|
#[allow(unused_imports)]
|
|
use say_fn::binary_digest;
|
|
#[allow(unused_imports)]
|
|
use say_fn::cublas_file;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::cublas_lib_dirs;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::desired_ld_library_path;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::file_stamp;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::gather_fs;
|
|
#[allow(unused_imports)]
|
|
use say_fn::mtp_complete;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::probe_ready;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::render_configs;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::say;
|
|
#[allow(unused_imports)]
|
|
use say_fn::secrets_ok;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::sha256_file;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::stamp_current;
|
|
#[allow(unused_imports)]
|
|
pub use say_fn::stamp_path;
|
|
#[allow(unused_imports)]
|
|
use say_fn::write_stamp;
|
|
mod probe_ready_at_fn;
|
|
#[allow(unused_imports)]
|
|
pub use probe_ready_at_fn::fetch_status;
|
|
#[allow(unused_imports)]
|
|
pub use probe_ready_at_fn::fetch_status_with_key;
|
|
#[allow(unused_imports)]
|
|
use probe_ready_at_fn::forward;
|
|
#[allow(unused_imports)]
|
|
pub use probe_ready_at_fn::install_binaries;
|
|
#[allow(unused_imports)]
|
|
pub use probe_ready_at_fn::make_dirs;
|
|
#[allow(unused_imports)]
|
|
pub use probe_ready_at_fn::probe_ready_at;
|
|
#[allow(unused_imports)]
|
|
pub use probe_ready_at_fn::probe_ready_with_key;
|
|
#[allow(unused_imports)]
|
|
pub use probe_ready_at_fn::run_tool;
|
|
#[allow(unused_imports)]
|
|
pub use probe_ready_at_fn::unit_text;
|
|
mod download_small_fn;
|
|
#[allow(unused_imports)]
|
|
use download_small_fn::download_small;
|
|
#[allow(unused_imports)]
|
|
pub use download_small_fn::init_api_key;
|
|
#[allow(unused_imports)]
|
|
pub use download_small_fn::install_cublas;
|
|
#[allow(unused_imports)]
|
|
pub use download_small_fn::provision_expert_profile;
|
|
#[allow(unused_imports)]
|
|
pub use download_small_fn::write_secrets_and_env;
|
|
mod fetch_and_verify_model_fn;
|
|
#[allow(unused_imports)]
|
|
use fetch_and_verify_model_fn::copy_dir;
|
|
#[allow(unused_imports)]
|
|
pub use fetch_and_verify_model_fn::ensure_kar;
|
|
#[allow(unused_imports)]
|
|
pub use fetch_and_verify_model_fn::extract_tokenizer;
|
|
#[allow(unused_imports)]
|
|
pub use fetch_and_verify_model_fn::fetch_and_verify_model;
|
|
#[allow(unused_imports)]
|
|
use fetch_and_verify_model_fn::find_pack_root;
|
|
#[allow(unused_imports)]
|
|
pub use fetch_and_verify_model_fn::import_mtp_pack;
|
|
#[cfg(unix)]
|
|
#[allow(unused_imports)]
|
|
pub use fetch_and_verify_model_fn::lookup_user;
|
|
#[allow(unused_imports)]
|
|
pub use fetch_and_verify_model_fn::write_configs;
|
|
mod ensure_service_user_fn;
|
|
#[cfg(unix)]
|
|
#[allow(unused_imports)]
|
|
pub use ensure_service_user_fn::chown_tree;
|
|
#[cfg(unix)]
|
|
#[allow(unused_imports)]
|
|
pub use ensure_service_user_fn::ensure_service_user;
|
|
#[cfg(unix)]
|
|
#[allow(unused_imports)]
|
|
pub use ensure_service_user_fn::hand_over_to_service_user;
|
|
#[allow(unused_imports)]
|
|
pub use ensure_service_user_fn::install_unit;
|
|
#[allow(unused_imports)]
|
|
use ensure_service_user_fn::kar_runs_tool;
|
|
#[allow(unused_imports)]
|
|
use ensure_service_user_fn::log_tail;
|
|
#[allow(unused_imports)]
|
|
pub use ensure_service_user_fn::start_unit;
|
|
#[allow(unused_imports)]
|
|
use ensure_service_user_fn::systemctl;
|
|
#[allow(unused_imports)]
|
|
use ensure_service_user_fn::systemctl_query;
|
|
#[allow(unused_imports)]
|
|
pub use ensure_service_user_fn::wait_ready;
|
|
mod prepare_fn;
|
|
#[allow(unused_imports)]
|
|
pub use prepare_fn::config_of;
|
|
#[allow(unused_imports)]
|
|
pub use prepare_fn::prepare;
|
|
#[allow(unused_imports)]
|
|
pub use prepare_fn::replan;
|