pub trait ServiceManager {
// Required methods
fn available(&self) -> Result<bool>;
fn install(&self, ctx: ServiceInstallCtx) -> Result<()>;
fn uninstall(&self, ctx: ServiceUninstallCtx) -> Result<()>;
fn start(&self, ctx: ServiceStartCtx) -> Result<()>;
fn stop(&self, ctx: ServiceStopCtx) -> Result<()>;
fn level(&self) -> ServiceLevel;
fn set_level(&mut self, level: ServiceLevel) -> Result<()>;
fn status(&self, ctx: ServiceStatusCtx) -> Result<ServiceStatus>;
}
Expand description
Interface for a service manager
Required Methods§
Sourcefn available(&self) -> Result<bool>
fn available(&self) -> Result<bool>
Determines if the service manager exists (e.g. is launchd
available on the system?) and
can be used
Sourcefn install(&self, ctx: ServiceInstallCtx) -> Result<()>
fn install(&self, ctx: ServiceInstallCtx) -> Result<()>
Installs a new service using the manager
Sourcefn uninstall(&self, ctx: ServiceUninstallCtx) -> Result<()>
fn uninstall(&self, ctx: ServiceUninstallCtx) -> Result<()>
Uninstalls an existing service using the manager
Sourcefn start(&self, ctx: ServiceStartCtx) -> Result<()>
fn start(&self, ctx: ServiceStartCtx) -> Result<()>
Starts a service using the manager
Sourcefn stop(&self, ctx: ServiceStopCtx) -> Result<()>
fn stop(&self, ctx: ServiceStopCtx) -> Result<()>
Stops a running service using the manager
Sourcefn level(&self) -> ServiceLevel
fn level(&self) -> ServiceLevel
Returns the current target level for the manager
Sourcefn set_level(&mut self, level: ServiceLevel) -> Result<()>
fn set_level(&mut self, level: ServiceLevel) -> Result<()>
Sets the target level for the manager
Sourcefn status(&self, ctx: ServiceStatusCtx) -> Result<ServiceStatus>
fn status(&self, ctx: ServiceStatusCtx) -> Result<ServiceStatus>
Return the service status info
Implementations§
Source§impl dyn ServiceManager
impl dyn ServiceManager
Sourcepub fn target_or_native(
kind: impl Into<Option<ServiceManagerKind>>,
) -> Result<Box<dyn ServiceManager>>
pub fn target_or_native( kind: impl Into<Option<ServiceManagerKind>>, ) -> Result<Box<dyn ServiceManager>>
Creates a new service using the specified type, falling back to selecting based on native service manager for the current operating system if no type provided
Sourcepub fn target(kind: ServiceManagerKind) -> Box<dyn ServiceManager>
pub fn target(kind: ServiceManagerKind) -> Box<dyn ServiceManager>
Creates a new service manager targeting the specific service manager kind using the default service manager instance
Sourcepub fn native() -> Result<Box<dyn ServiceManager>>
pub fn native() -> Result<Box<dyn ServiceManager>>
Attempts to select a native service manager for the current operating system
- For MacOS, this will use
LaunchdServiceManager
- For Windows, this will use
ScServiceManager
- For BSD variants, this will use
RcdServiceManager
- For Linux variants, this will use either
SystemdServiceManager
orOpenRcServiceManager