mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-12 11:18:21 +00:00
27 lines
871 B
Rust
27 lines
871 B
Rust
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(())
|
|
}
|