diff --git a/cli/src/tunnels/service_linux.rs b/cli/src/tunnels/service_linux.rs index 3d1258a469a..b60d114dc46 100644 --- a/cli/src/tunnels/service_linux.rs +++ b/cli/src/tunnels/service_linux.rs @@ -17,7 +17,7 @@ use crate::{ constants::{APPLICATION_NAME, PRODUCT_NAME_LONG}, log, state::LauncherPaths, - util::errors::{wrap, AnyError}, + util::errors::{wrap, AnyError, DbusConnectFailedError}, }; use super::ServiceManager; @@ -40,7 +40,7 @@ impl SystemdService { async fn connect() -> Result { let connection = Connection::session() .await - .map_err(|e| wrap(e, "Error creating dbus session. This command uses systemd for managing services, you should check that systemd is installed and running as a user. If it's already installed, you may need to:\n\n- Install the `dbus-user-session` package and reboot\n- Start the user dbus session with `systemctl --user enable dbus --now`. \n\nThe error encountered was"))?; + .map_err(|e| DbusConnectFailedError(e.to_string()))?; Ok(connection) } @@ -110,6 +110,10 @@ impl ServiceManager for SystemdService { info!(self.log, "Tunnel service successfully started"); + if std::env::var("SSH_CLIENT").is_ok() || std::env::var("SSH_TTY").is_ok() { + info!(self.log, "Tip: run `sudo loginctl enable-linger $USER` to ensure the service stays running after you disconnect."); + } + Ok(()) } diff --git a/cli/src/util/errors.rs b/cli/src/util/errors.rs index f1c4cbf5c22..6f4630d0c54 100644 --- a/cli/src/util/errors.rs +++ b/cli/src/util/errors.rs @@ -442,6 +442,26 @@ macro_rules! makeAnyError { }; } +#[derive(Debug)] +pub struct DbusConnectFailedError(pub String); + +impl Display for DbusConnectFailedError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + let mut str = String::new(); + str.push_str("Error creating dbus session. This command uses systemd for managing services, you should check that systemd is installed and under your user."); + + if std::env::var("WSL_DISTRO_NAME").is_ok() { + str.push_str("\n\nTo enable systemd on WSL, check out: https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/.\n\n"); + } + + str.push_str("If running `systemctl status` works, systemd is ok, but your session dbus may not be. You might need to:\n\n- Install the `dbus-user-session` package, and reboot if it was not installed\n- Start the user dbus session with `systemctl --user enable dbus --now`.\n\nThe error encountered was: "); + str.push_str(&self.0); + str.push('\n'); + + write!(f, "{}", str) + } +} + /// Internal errors in the VS Code CLI. /// Note: other error should be migrated to this type gradually #[derive(Error, Debug)] @@ -522,7 +542,8 @@ makeAnyError!( MissingHomeDirectory, OAuthError, InvalidRpcDataError, - CodeError + CodeError, + DbusConnectFailedError ); impl From for AnyError {