ant_service_management/
lib.rs1#![allow(clippy::unwrap_used)]
11#![allow(clippy::expect_used)]
12
13pub mod control;
14pub mod daemon;
15pub mod error;
16pub mod node;
17pub mod registry;
18pub mod rpc;
19
20#[macro_use]
21extern crate tracing;
22
23pub mod antctl_proto {
24 #![allow(clippy::clone_on_ref_ptr)]
25 tonic::include_proto!("antctl_proto");
26}
27
28use std::path::PathBuf;
29
30use async_trait::async_trait;
31use semver::Version;
32use serde::{Deserialize, Serialize};
33use service_manager::ServiceInstallCtx;
34
35pub use daemon::{DaemonService, DaemonServiceData};
36pub use error::{Error, Result};
37pub use node::{NodeService, NodeServiceData};
38pub use registry::{NodeRegistryManager, StatusSummary, get_local_node_registry_path};
39
40#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
41pub enum ServiceStatus {
42 Added,
44 Running,
46 Stopped,
48 Removed,
50}
51
52#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
53pub enum NatDetectionStatus {
54 Public,
55 UPnP,
56 Private,
57}
58
59#[derive(Clone, Debug, PartialEq)]
60pub enum UpgradeResult {
61 Forced(String, String),
62 NotRequired,
63 Upgraded(String, String),
64 UpgradedButNotStarted(String, String, String),
65 Error(String),
66}
67
68#[derive(Clone, Debug, Eq, PartialEq)]
69pub struct UpgradeOptions {
70 pub auto_restart: bool,
71 pub env_variables: Option<Vec<(String, String)>>,
72 pub force: bool,
73 pub start_service: bool,
74 pub target_bin_path: PathBuf,
75 pub target_version: Version,
76}
77
78#[async_trait]
79pub trait ServiceStateActions {
80 async fn bin_path(&self) -> PathBuf;
81 async fn build_upgrade_install_context(
82 &self,
83 options: UpgradeOptions,
84 ) -> Result<ServiceInstallCtx>;
85 async fn data_dir_path(&self) -> PathBuf;
86 async fn is_user_mode(&self) -> bool;
87 async fn log_dir_path(&self) -> PathBuf;
88 async fn name(&self) -> String;
89 async fn pid(&self) -> Option<u32>;
90 async fn on_remove(&self);
91 async fn on_start(&self, pid: Option<u32>, full_refresh: bool) -> Result<()>;
92 async fn on_stop(&self) -> Result<()>;
93 async fn set_version(&self, version: &str);
94 async fn status(&self) -> ServiceStatus;
95 async fn version(&self) -> String;
96}