Skip to content

Commit

Permalink
make azure-init fail when it met failure
Browse files Browse the repository at this point in the history
Currently azure-init does not fail, even when it should fail with error.
That's why azure-init systemd service simply keeps running even on
failure. Make it exit with exit code, so systemd unit azure-init fails
in case of failure.
  • Loading branch information
dongsupark committed Mar 15, 2024
1 parent 000a851 commit 266fc98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
description = "A reference implementation for provisioning Linux VMs on Azure."

[dependencies]
exitcode = "1.1.2"
tokio = { version = "1", features = ["full"] }

[dependencies.libazureinit]
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ async fn main() {
let query_result = imds::query_imds(&client).await;
let imds_body = match query_result {
Ok(imds_body) => imds_body,
Err(_err) => return,
Err(_err) => std::process::exit(exitcode::CONFIG),
};

let username = match get_username(imds_body.clone()) {
Ok(res) => res,
Err(_err) => return,
Err(_err) => std::process::exit(exitcode::CONFIG),
};

let mut file_path = "/home/".to_string();
Expand All @@ -79,7 +79,7 @@ async fn main() {
let get_ssh_key_result = imds::get_ssh_keys(imds_body.clone());
let keys = match get_ssh_key_result {
Ok(keys) => keys,
Err(_err) => return,
Err(_err) => std::process::exit(exitcode::CONFIG),
};

file_path.push_str("/.ssh");
Expand All @@ -89,7 +89,7 @@ async fn main() {
let get_hostname_result = imds::get_hostname(imds_body.clone());
let hostname = match get_hostname_result {
Ok(hostname) => hostname,
Err(_err) => return,
Err(_err) => std::process::exit(exitcode::CONFIG),
};

Distributions::from("ubuntu")
Expand All @@ -99,13 +99,13 @@ async fn main() {
let get_goalstate_result = goalstate::get_goalstate(&client).await;
let vm_goalstate = match get_goalstate_result {
Ok(vm_goalstate) => vm_goalstate,
Err(_err) => return,
Err(_err) => std::process::exit(exitcode::CONFIG),
};

let report_health_result =
goalstate::report_health(&client, vm_goalstate).await;
match report_health_result {
Ok(report_health) => report_health,
Err(_err) => return,
Err(_err) => std::process::exit(exitcode::CONFIG),
};
}

0 comments on commit 266fc98

Please sign in to comment.