iroh_ssh/service/
mod.rs

1#[cfg(target_os = "linux")]
2mod linux;
3#[cfg(target_os = "linux")]
4use crate::service::linux::LinuxService;
5
6#[cfg(target_os = "windows")]
7mod windows;
8#[cfg(target_os = "windows")]
9use crate::service::windows::WindowsService;
10
11#[derive(Debug, Clone)]
12pub struct ServiceParams {
13    pub ssh_port: u16,
14}
15
16pub trait Service {
17    fn install(service_params: ServiceParams) -> impl std::future::Future<Output = anyhow::Result<()>> + Send;
18    fn info() -> impl std::future::Future<Output = anyhow::Result<()>> + Send;
19    fn uninstall() -> impl std::future::Future<Output = anyhow::Result<()>> + Send;
20}
21
22#[allow(unused)]
23pub async fn install_service(service_params: ServiceParams) -> anyhow::Result<()> {
24    match std::env::consts::OS {
25        #[cfg(target_os = "linux")]
26        "linux" => LinuxService::install(service_params).await,
27        #[cfg(target_os = "windows")]
28        "windows" => WindowsService::install(service_params).await,
29        _ => anyhow::bail!("service mode is only supported on linux and windows"),
30    }
31}
32
33pub async fn uninstall_service() -> anyhow::Result<()> {
34    match std::env::consts::OS {
35        #[cfg(target_os = "linux")]
36        "linux" => LinuxService::uninstall().await,
37        #[cfg(target_os = "windows")]
38        "windows" => WindowsService::uninstall().await,
39        _ => anyhow::bail!("service mode is only supported on linux and windows"),
40    }
41}