pub trait ServiceControl: Sync {
// Required methods
fn create_service_user(&self, username: &str) -> Result<()>;
fn get_available_port(&self) -> Result<u16>;
fn install(
&self,
install_ctx: ServiceInstallCtx,
user_mode: bool,
) -> Result<()>;
fn get_process_pid(&self, path: &Path) -> Result<u32>;
fn get_process_version(&self, pid: u32) -> Result<Option<String>>;
fn start(&self, service_name: &str, user_mode: bool) -> Result<()>;
fn stop(&self, service_name: &str, user_mode: bool) -> Result<()>;
fn uninstall(&self, service_name: &str, user_mode: bool) -> Result<()>;
fn verify_process_by_pid(
&self,
pid: u32,
expected_name: &str,
) -> Result<bool>;
fn wait(&self, delay: u64);
}Expand description
A thin wrapper around the service_manager::ServiceManager, which makes our own testing
easier.
We can make an assumption that this external component works correctly, so our own tests only need assert that the service manager is used. Testing code that used the real service manager would result in real services on the machines we are testing on; that can leave a bit of a mess to clean up, especially if the tests fail.
Required Methods§
fn create_service_user(&self, username: &str) -> Result<()>
fn get_available_port(&self) -> Result<u16>
fn install(&self, install_ctx: ServiceInstallCtx, user_mode: bool) -> Result<()>
fn get_process_pid(&self, path: &Path) -> Result<u32>
Sourcefn get_process_version(&self, pid: u32) -> Result<Option<String>>
fn get_process_version(&self, pid: u32) -> Result<Option<String>>
Get the version of a running process by its PID.
Attempts to extract version by executing --version on the process’s binary.
This works even when the binary has been replaced on disk during upgrades,
by using cross-platform process information from sysinfo.
Returns None if version cannot be determined (not an error condition).
Errors only on system-level failures.