Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
93 lines
2.9 KiB
Rust
93 lines
2.9 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 downloads;
|
|
mod model_assets;
|
|
mod preparation;
|
|
mod host_actions;
|
|
mod service_unit;
|
|
mod state_records;
|
|
pub use downloads::{
|
|
init_api_key, install_cublas, provision_expert_profile, write_secrets_and_env,
|
|
};
|
|
#[cfg(unix)]
|
|
pub use model_assets::lookup_user;
|
|
pub use model_assets::{
|
|
ensure_kar, extract_tokenizer, fetch_and_verify_model, import_mtp_pack, write_configs,
|
|
};
|
|
pub use preparation::{config_of, prepare, replan};
|
|
pub use host_actions::{
|
|
fetch_status, fetch_status_with_key, install_binaries, make_dirs, probe_ready_at,
|
|
probe_ready_with_key, run_tool, unit_text,
|
|
};
|
|
use service_unit::kar_runs_tool;
|
|
#[cfg(unix)]
|
|
pub use service_unit::{chown_tree, ensure_service_user, hand_over_to_service_user};
|
|
pub use service_unit::{install_unit, start_unit, wait_ready};
|
|
pub use state_records::{
|
|
binaries_state, cublas_lib_dirs, desired_ld_library_path, file_stamp, gather_fs, probe_ready,
|
|
render_configs, say, sha256_file, stamp_current, stamp_path,
|
|
};
|
|
use state_records::{mtp_complete, write_stamp};
|
|
|
|
#[cfg(test)]
|
|
use downloads::download_small;
|
|
#[cfg(test)]
|
|
use model_assets::find_pack_root;
|