use crate::markers::DaemonMarkers;
use crate::state::DaemonState;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ServiceIdentity {
binary_name: String,
launchd_prefix: String,
instance: String,
}
impl ServiceIdentity {
#[must_use]
pub fn new(
binary_name: impl Into<String>,
launchd_prefix: impl Into<String>,
instance: impl Into<String>,
) -> Self {
Self {
binary_name: binary_name.into(),
launchd_prefix: launchd_prefix.into(),
instance: instance.into(),
}
}
#[must_use]
pub fn launchd_label(&self) -> String {
format!("{}.{}", self.launchd_prefix, self.instance)
}
#[must_use]
pub fn systemd_unit_name(&self) -> String {
format!("{}@{}.service", self.binary_name, self.instance)
}
#[must_use]
pub fn windows_service_name(&self) -> String {
format!("{}-{}", self.binary_name, self.instance)
}
#[must_use]
pub fn service_label(&self) -> String {
if cfg!(target_os = "macos") {
self.launchd_label()
} else if cfg!(windows) {
self.windows_service_name()
} else {
self.systemd_unit_name()
}
}
#[must_use]
pub fn detect(&self, markers: &DaemonMarkers) -> DaemonState {
crate::platform::detect_impl(self, markers)
}
}