mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-07 17:18:21 +00:00
add system power api
This commit is contained in:
parent
fb03a17d36
commit
1e66729e59
1 changed files with 27 additions and 0 deletions
27
src/api/system/power.rs
Normal file
27
src/api/system/power.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
use crate::api::ApiError;
|
||||
use crate::state::RpcState;
|
||||
use jsonrpsee::types::Params;
|
||||
use jsonrpsee::RpcModule;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn register_methods(module: &mut RpcModule<RpcState>) {
|
||||
module
|
||||
.register_async_method("system.power.shutdown", halt_system)
|
||||
.unwrap();
|
||||
|
||||
module
|
||||
.register_async_method("system.power.restart", reboot_system)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub async fn halt_system<'a>(_: Params<'a>, _state: Arc<RpcState>) -> Result<(), ApiError> {
|
||||
let systemd_manager = zbus_systemd::systemd1::ManagerProxy::new(&_state.dbus_conn).await?;
|
||||
systemd_manager.halt().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn reboot_system<'a>(_: Params<'a>, _state: Arc<RpcState>) -> Result<(), ApiError> {
|
||||
let systemd_manager = zbus_systemd::systemd1::ManagerProxy::new(&_state.dbus_conn).await?;
|
||||
systemd_manager.reboot().await?;
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Reference in a new issue