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")]
9pub(crate) use crate::service::windows::WindowsService;
10
11#[cfg(target_os = "windows")]
12pub async fn run_service(ssh_port: u16) -> anyhow::Result<()> {
13 WindowsService::run_service(ServiceParams { ssh_port }).await
14}
15
16#[cfg(not(target_os = "windows"))]
17pub async fn run_service(_ssh_port: u16) -> anyhow::Result<()> {
18 anyhow::bail!("service run is only supported on windows");
19}
20
21#[derive(Debug, Clone)]
22pub struct ServiceParams {
23 pub ssh_port: u16,
24}
25
26pub trait Service {
27 fn install(
28 service_params: ServiceParams,
29 ) -> impl std::future::Future<Output = anyhow::Result<()>> + Send;
30 fn info() -> impl std::future::Future<Output = anyhow::Result<()>> + Send;
31 fn uninstall() -> impl std::future::Future<Output = anyhow::Result<()>> + Send;
32}
33
34pub async fn install_service(_service_params: ServiceParams) -> anyhow::Result<()> {
35 match std::env::consts::OS {
36 #[cfg(target_os = "linux")]
37 "linux" => LinuxService::install(_service_params).await,
38 #[cfg(target_os = "windows")]
39 "windows" => WindowsService::install(_service_params).await,
40 _ => anyhow::bail!("service mode is only supported on linux and windows"),
41 }
42}
43
44pub async fn uninstall_service() -> anyhow::Result<()> {
45 match std::env::consts::OS {
46 #[cfg(target_os = "linux")]
47 "linux" => LinuxService::uninstall().await,
48 #[cfg(target_os = "windows")]
49 "windows" => WindowsService::uninstall().await,
50 _ => anyhow::bail!("service mode is only supported on linux and windows"),
51 }
52}