Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aziotctl/aziotctl-common/src/config/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ pub fn run(

aziot_identityd_config::Provisioning {
provisioning,
retry_seconds: None,
local_gateway_hostname: parent_hostname,
}
};
Expand Down
3 changes: 3 additions & 0 deletions identity/aziot-identityd-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ pub enum DpsAttestationMethod {
pub struct Provisioning {
pub local_gateway_hostname: Option<String>,

#[serde(default, skip_serializing_if = "Option::is_none")]
pub retry_seconds: Option<u64>,

#[serde(flatten)]
pub provisioning: ProvisioningType,
}
Expand Down
35 changes: 23 additions & 12 deletions identity/aziot-identityd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,31 @@ pub async fn main(
}

// Attempt to reprovision the device. Failure to reprovision on startup means that provisioning
// with IoT Hub failed and no valid backup could be loaded. Treat this as a fatal error.
// with IoT Hub failed and no valid backup could be loaded.
{
let mut api = api.lock().await;

if let Err(err) = api
.reprovision_device(auth::AuthId::LocalRoot, ReprovisionTrigger::Startup, None)
.await
{
log::error!(
"Failed to provision with IoT Hub, and no valid device backup was found: {}",
err
);

return Err(err.into());
let retry_secs = api.settings.provisioning.retry_seconds.unwrap_or(0);
loop {
match api
.reprovision_device(auth::AuthId::LocalRoot, ReprovisionTrigger::Startup, None)
.await
{
Ok(_) => break,
Err(err) => {
let retry_msg = if retry_secs == 0 {
String::new()
} else {
format!(" Retrying in {retry_secs} seconds.")
};
log::error!(
"Failed to provision with IoT Hub, and no valid device backup was found: {err}.{retry_msg}"
);
if retry_secs == 0 {
return Err(err.into());
}
tokio::time::sleep(std::time::Duration::from_secs(retry_secs)).await;
}
}
}
}

Expand Down