summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSebastian Holmin <sebastian.holmin@mullvad.net>2025-07-04 15:00:15 +0200
committerSebastian Holmin <sebastian.holmin@mullvad.net>2025-07-11 10:15:29 +0200
commit0f25b372d7dd0c9234f4f3edc28f8a0b0eba7afa (patch)
tree11bb8233b5fca4a97d59c68d81431be815e8bf7c
parent1391bf030931ee44964702f5112e0bec5f18fea9 (diff)
downloadmullvadvpn-0f25b372d7dd0c9234f4f3edc28f8a0b0eba7afa.tar.xz
mullvadvpn-0f25b372d7dd0c9234f4f3edc28f8a0b0eba7afa.zip
Add functions to toggle service startup
-rw-r--r--test/test-rpc/src/client.rs27
-rw-r--r--test/test-rpc/src/lib.rs3
-rw-r--r--test/test-runner/src/main.rs25
-rw-r--r--test/test-runner/src/sys.rs45
4 files changed, 84 insertions, 16 deletions
diff --git a/test/test-rpc/src/client.rs b/test/test-rpc/src/client.rs
index c6593c162b..8f4833f2b9 100644
--- a/test/test-rpc/src/client.rs
+++ b/test/test-rpc/src/client.rs
@@ -301,12 +301,35 @@ impl ServiceClient {
/// Enable the daemon system service.
///
/// Does *not* start a stopped app. See [start_mullvad_daemon].
- pub async fn enable_mullvad_daemon_service(&self) -> Result<(), Error> {
+ pub async fn enable_mullvad_daemon(&self) -> Result<(), Error> {
let mut ctx = tarpc::context::current();
ctx.deadline = SystemTime::now()
.checked_add(DAEMON_RESTART_TIMEOUT)
.unwrap();
- let _ = todo!("self.client.enable_mullvad_daemon(ctx).await?;");
+ self.client
+ .enable_mullvad_daemon(ctx)
+ .await
+ .map_err(Error::Tarpc)??;
+ Ok(())
+ }
+
+ /// Disable the daemon system service. *Current only works on Windows*.
+ ///
+ /// This will not stop the daemon system service, but it will prevent it from starting
+ /// automatically on system boot.
+ ///
+ /// Note that if the daemon is also stopped, using [stop_mullvad_daemon], it will
+ /// not be possible to start it again until it is enabled again using
+ /// [enable_mullvad_daemon].
+ pub async fn disable_mullvad_daemon(&self) -> Result<(), Error> {
+ let mut ctx = tarpc::context::current();
+ ctx.deadline = SystemTime::now()
+ .checked_add(DAEMON_RESTART_TIMEOUT)
+ .unwrap();
+ self.client
+ .disable_mullvad_daemon(ctx)
+ .await
+ .map_err(Error::Tarpc)??;
Ok(())
}
diff --git a/test/test-rpc/src/lib.rs b/test/test-rpc/src/lib.rs
index 1bb8da6636..7f4d37689a 100644
--- a/test/test-rpc/src/lib.rs
+++ b/test/test-rpc/src/lib.rs
@@ -233,6 +233,9 @@ mod service {
/// Disable the Mullvad VPN system service.
async fn disable_mullvad_daemon() -> Result<(), Error>;
+ /// Enable the Mullvad VPN system service.
+ async fn enable_mullvad_daemon() -> Result<(), Error>;
+
/// Sets the log level of the daemon service, the verbosity level represents the number of
/// `-v`s passed on the command line. This will restart the daemon system service.
async fn set_daemon_log_level(
diff --git a/test/test-runner/src/main.rs b/test/test-runner/src/main.rs
index fec18255d7..843285eb33 100644
--- a/test/test-runner/src/main.rs
+++ b/test/test-runner/src/main.rs
@@ -319,19 +319,22 @@ impl Service for TestServer {
}
/// Disable the Mullvad VPN system service.
- async fn disable_mullvad_daemon_service(
- self,
- _: context::Context,
- ) -> Result<(), test_rpc::Error> {
- sys::disable_system_service_startup().await
+ async fn disable_mullvad_daemon(self, _: context::Context) -> Result<(), test_rpc::Error> {
+ #[cfg(not(target_os = "windows"))]
+ unimplemented!("disable_mullvad_daemon is only implemented on Windows");
+ #[cfg(target_os = "windows")]
+ {
+ sys::disable_system_service_startup().await
+ }
}
- /// Enable the Mullvad VPN system service.
- async fn enable_mullvad_daemon_service(
- self,
- _: context::Context,
- ) -> Result<(), test_rpc::Error> {
- sys::enable_system_service_startup().await
+ async fn enable_mullvad_daemon(self, _: context::Context) -> Result<(), test_rpc::Error> {
+ #[cfg(not(target_os = "windows"))]
+ unimplemented!("enable_mullvad_daemon is only implemented on Windows");
+ #[cfg(target_os = "windows")]
+ {
+ sys::enable_system_service_startup().await
+ }
}
async fn set_daemon_log_level(
diff --git a/test/test-runner/src/sys.rs b/test/test-runner/src/sys.rs
index 44ac2803ce..3490353b55 100644
--- a/test/test-runner/src/sys.rs
+++ b/test/test-runner/src/sys.rs
@@ -284,10 +284,49 @@ pub async fn start_app() -> Result<(), test_rpc::Error> {
Ok(())
}
-/// Disable the Mullvad VPN system service.
+/// Disable the Mullvad VPN system service startup. This will not trigger the service to stop
+/// immediately, but it will prevent it from starting on the next system boot.
#[cfg(target_os = "windows")]
-pub async fn disable_system_service() -> Result<(), test_rpc::Error> {
- todo!("sc.exe disable?")
+pub async fn disable_system_service_startup() -> Result<(), test_rpc::Error> {
+ let status = tokio::process::Command::new("powershell")
+ .args([
+ "-NoProfile",
+ "-Command",
+ "Set-Service -Name MullvadVPN -StartupType Disabled",
+ ])
+ .status()
+ .await
+ .map_err(|e| test_rpc::Error::ServiceChange(e.to_string()))?;
+
+ if !status.success() {
+ return Err(test_rpc::Error::ServiceChange(
+ "Failed to disable MullvadVPN service".to_string(),
+ ));
+ }
+
+ Ok(())
+}
+
+/// Enable the Mullvad VPN system service startup. This will configure the service to start automatically on system boot.
+#[cfg(target_os = "windows")]
+pub async fn enable_system_service_startup() -> Result<(), test_rpc::Error> {
+ let status = tokio::process::Command::new("powershell")
+ .args([
+ "-NoProfile",
+ "-Command",
+ "Set-Service -Name MullvadVPN -StartupType Automatic",
+ ])
+ .status()
+ .await
+ .map_err(|e| test_rpc::Error::ServiceChange(e.to_string()))?;
+
+ if !status.success() {
+ return Err(test_rpc::Error::ServiceChange(
+ "Failed to enable MullvadVPN service".to_string(),
+ ));
+ }
+
+ Ok(())
}
/// Restart the Mullvad VPN application.