Files
Legatus/crates/linux/examples/deploy.rs
T
mnovak 5fcae1d152 [repo] Licence: CPAL-1.0 file headers instead of the MPL-2.0 notice
Each source file's three-line MPL-2.0 notice becomes an SPDX CPAL-1.0 header with the copyright
line; the Exhibit A notice itself is in LICENSE (CPAL 3.5). Shell scripts' SPDX ids follow.
Comments only: no code changes.
2026-11-23 00:19:33 +01:00

50 lines
1.8 KiB
Rust

// SPDX-License-Identifier: CPAL-1.0
// Copyright (c) 2026 Marek Novák. Exhibit A notice: LICENSE at the repository root.
//! TEST ONLY: drives the Linux backend with real systemd for tests/linux (the container test).
//! It skips the signature check on purpose, so it is an example, never part of a release.
//!
//! deploy <root> <app> <version> <unit> <health-url|-> <archive.tar.gz>
#![allow(clippy::unwrap_used, clippy::expect_used)]
use std::time::Duration;
use legatus_linux::{HttpHealth, Layout, LinuxBackend, Outcome, Plan, Systemctl};
fn main() {
let a: Vec<String> = std::env::args().skip(1).collect();
let [root, app, version, unit, health, archive] = a.as_slice() else {
eprintln!("usage: deploy <root> <app> <version> <unit> <health-url|-> <archive.tar.gz>");
std::process::exit(2);
};
let bytes = std::fs::read(archive).expect("the archive");
let sha = legatus_protocol::sha256_hex(&bytes);
let backend = LinuxBackend::new(Layout::new(root), Systemctl, HttpHealth);
let plan = Plan {
app,
version,
unit,
health_url: (health != "-").then_some(health.as_str()),
health_timeout: Duration::from_secs(15),
keep: 3,
};
match backend.deploy(&plan, &bytes[..], &sha) {
Ok(Outcome::Succeeded { previous }) => {
println!(
"succeeded previous={}",
previous.unwrap_or_else(|| "-".into())
)
}
Ok(Outcome::RolledBack {
to,
healthy,
reason,
}) => {
println!("rolled_back to={to} healthy={healthy} reason={reason}")
}
Ok(Outcome::Failed { reason }) => println!("failed reason={reason}"),
Err(e) => println!("error {e}"),
}
}