use crate::markers::DaemonMarkers;
use crate::state::DaemonState;
use crate::values::{
BinaryName,
LaunchdLabelPrefix,
ServiceInstance,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ServiceIdentity {
binary_name: BinaryName,
launchd_prefix: LaunchdLabelPrefix,
instance: ServiceInstance,
}
impl ServiceIdentity {
#[must_use]
pub fn new(
binary_name: BinaryName,
launchd_prefix: LaunchdLabelPrefix,
instance: impl Into<ServiceInstance>,
) -> Self {
Self {
binary_name,
launchd_prefix,
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)
}
}