diff --git a/.gitignore b/.gitignore index ea8c4bf..4f6f49c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.cargo-cache diff --git a/Dockerfile.arm b/Dockerfile.arm new file mode 100644 index 0000000..a59d304 --- /dev/null +++ b/Dockerfile.arm @@ -0,0 +1,5 @@ +FROM rust:1.93.1-bullseye + +RUN rustup target add aarch64-unknown-linux-gnu \ + && apt update \ + && apt install -y gcc-aarch64-linux-gnu diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2f4919e --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ + + +build: image + podman run -it --rm -v $(PWD):/app -v $(PWD)/.cargo-cache:/usr/local/cargo/registry -w /app route-switcher-builder:latest cargo build --target aarch64-unknown-linux-gnu + +image: + podman build -f Dockerfile.arm -t route-switcher-builder:latest . diff --git a/src/api.rs b/src/api.rs index 690473e..a8f7e7f 100644 --- a/src/api.rs +++ b/src/api.rs @@ -257,7 +257,7 @@ async fn get_state( let state_str = match current_state { MachineState::Boot => "Boot", MachineState::Primary => "Primary", - MachineState::Fallback => "Fallback", + MachineState::Fallback => "Secondary", }; // Get ping statistics from state machine @@ -280,10 +280,10 @@ async fn set_state( ) -> Result, ErrorResponse> { let target_state = payload.state.to_lowercase(); - if target_state != "primary" && target_state != "fallback" { + if target_state != "primary" && target_state != "secondary" { return Err(ErrorResponse { error: "Invalid state".to_string(), - message: "State must be 'primary' or 'fallback'".to_string(), + message: "State must be 'primary' or 'secondary'".to_string(), }); } @@ -293,7 +293,7 @@ async fn set_state( let old_state = state_machine.get_state().clone(); let new_state = match target_state.as_str() { "primary" => MachineState::Primary, - "fallback" => MachineState::Fallback, + "secondary" => MachineState::Fallback, _ => unreachable!(), // Already validated above }; @@ -316,7 +316,7 @@ async fn set_state( let state_str = match new_state { MachineState::Boot => "Boot", MachineState::Primary => "Primary", - MachineState::Fallback => "Fallback", + MachineState::Fallback => "Secondary", }; let primary_stats = PingStats::from_history(&state_machine.primary_history); diff --git a/src/main.rs b/src/main.rs index 3692ac7..86b6371 100644 --- a/src/main.rs +++ b/src/main.rs @@ -189,6 +189,16 @@ async fn main_service( None }; + // Spawn the termination checker once, outside the select loop + let mut term_checker = tokio::task::spawn_blocking({ + let term = Arc::clone(&term); + move || { + while !term.load(Ordering::Relaxed) { + std::thread::sleep(Duration::from_millis(100)); + } + } + }); + // Main event loop loop { tokio::select! { @@ -228,15 +238,8 @@ async fn main_service( break; } - // Check termination flag - _ = tokio::task::spawn_blocking({ - let term = Arc::clone(&term); - move || { - while !term.load(Ordering::Relaxed) { - std::thread::sleep(Duration::from_millis(100)); - } - } - }) => { + // Check termination flag (now just waits for the already spawned task) + _ = &mut term_checker => { info!("Received termination signal"); break; }