-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcli_finalize.rs
36 lines (31 loc) · 1.17 KB
/
cli_finalize.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Interface to `rpm-ostree finalize-deployment`.
use super::Release;
use failure::{bail, format_err, Fallible, ResultExt};
use prometheus::IntCounter;
lazy_static::lazy_static! {
static ref FINALIZE_ATTEMPTS: IntCounter = register_int_counter!(opts!(
"zincati_rpm_ostree_finalize_attempts_total",
"Total number of 'rpm-ostree finalize-deployment' attempts."
)).unwrap();
static ref FINALIZE_FAILURES: IntCounter = register_int_counter!(opts!(
"zincati_rpm_ostree_finalize_failures_total",
"Total number of 'rpm-ostree finalize-deployment' failures."
)).unwrap();
}
/// Unlock and finalize the new deployment.
pub fn finalize_deployment(release: Release) -> Fallible<Release> {
FINALIZE_ATTEMPTS.inc();
let cmd = std::process::Command::new("rpm-ostree")
.arg("finalize-deployment")
.arg(&release.checksum)
.output()
.with_context(|e| format_err!("failed to run rpm-ostree: {}", e))?;
if !cmd.status.success() {
FINALIZE_FAILURES.inc();
bail!(
"rpm-ostree finalize-deployment failed:\n{}",
String::from_utf8_lossy(&cmd.stderr)
);
}
Ok(release)
}