Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
name = "omnect-device-service"
readme = "README.md"
repository = "https://github.com/omnect/omnect-device-service.git"
version = "0.41.12"
version = "0.41.13"

[dependencies]
actix-server = { version = "2.6", default-features = false }
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ The availability of the feature might be suppressed by creating the following en
SUPPRESS_REBOOT=true
```

The reboot is executed with a configurable delay to allow the service to respond to the caller before the system shuts down. The delay can be configured via the `REBOOT_DELAY_MS` environment variable (default: 100ms).

```bash
REBOOT_DELAY_MS=1000
```

#### Trigger reboot

Direct Method Name: `reboot`
Expand Down
36 changes: 21 additions & 15 deletions src/systemd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,28 @@ pub async fn reboot(reason: &str, extra_info: &str) -> Result<()> {
_ => debug!("reboot: succeeded to execute 'journalctl --sync'"),
}

// Trigger reboot via reboot.target using unit_action
// The job may not complete as the system shuts down, so we use a timeout
let reboot_timeout = std::time::Duration::from_secs(1);
match tokio::time::timeout(
reboot_timeout,
unit::unit_action("reboot.target", unit::UnitAction::Start, unit::Mode::Replace),
)
.await
{
Ok(result) => result.context("reboot: failed to start reboot.target"),
Err(_) => {
// Timeout is expected as system is shutting down
debug!("reboot: timed out waiting for reboot.target (system likely shutting down)");
Ok(())
// Spawn reboot in background with a small delay to allow this function to return
// and the service to respond to the caller before the system shuts down
let delay_ms = std::env::var("REBOOT_DELAY_MS")
.unwrap_or("100".to_string())
.parse::<u64>()
.unwrap_or(100);

tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_millis(delay_ms)).await;
debug!("triggering reboot.target");
if let Err(e) = unit::unit_action(
"reboot.target",
unit::UnitAction::Start,
unit::Mode::Replace,
)
.await
{
error!("failed to start reboot.target: {e:#}");
}
}
});

Ok(())
}

pub async fn wait_for_system_running() -> Result<()> {
Expand Down
Loading