Skip to content

Commit

Permalink
feat: check running services when using paid tunnel (#113)
Browse files Browse the repository at this point in the history
When we run free tunnels, we check if there is any local service already
running to warn the user about it. We are currently not doing this for
paid tunnels as well.

This PR adds the same check for paid tunnels.
  • Loading branch information
augustoccesar authored Oct 30, 2024
1 parent 9b8614e commit 6342977
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion linkup-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "linkup-cli"
version = "1.2.0"
version = "1.2.1"
edition = "2021"

[[bin]]
Expand Down
22 changes: 16 additions & 6 deletions linkup-cli/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::{
path::{Path, PathBuf},
};

use colored::Colorize;

use crate::{
background_booting::{BackgroundServices, RealBackgroundServices},
env_files::write_to_env_file,
Expand Down Expand Up @@ -108,6 +110,8 @@ fn start_paid_tunnel(
boot.boot_local_dns(state.domain_strings(), state.linkup.session_name.clone())?;
}

check_local_not_started(&state)?;

Ok(())
}

Expand All @@ -121,9 +125,10 @@ fn start_free_tunnel(state: LocalState, no_tunnel: bool) -> Result<(), CliError>
}

let background_service = RealBackgroundServices {};
background_service.boot_background_services(state)?;
let state = background_service.boot_background_services(state)?;

check_local_not_started(&state)?;

check_local_not_started()?;
Ok(())
}

Expand Down Expand Up @@ -195,14 +200,19 @@ fn set_service_env(directory: String, config_path: String) -> Result<(), CliErro
Ok(())
}

fn check_local_not_started() -> Result<(), CliError> {
let state = LocalState::load()?;
for service in state.services {
fn check_local_not_started(state: &LocalState) -> Result<(), CliError> {
for service in &state.services {
if service.local == service.remote {
continue;
}

if server_status(service.local.to_string(), None) == ServerStatus::Ok {
println!("⚠️ Service {} is already running locally!! You need to restart it for linkup's environment variables to be loaded.", service.name);
let warning = format!(
"⚠️ Service {} is already running locally!! You need to restart it for linkup's environment variables to be loaded.",
service.name
).yellow();

println!("{}", warning);
}
}
Ok(())
Expand Down

0 comments on commit 6342977

Please sign in to comment.