- fix: when shutting down a docker container, the services would not deregister from consul correctly
This commit is contained in:
@@ -67,8 +67,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
info!("Starting REST API on {}:{}", addr, port);
|
info!("Starting REST API on {}:{}", addr, port);
|
||||||
tokio::spawn(axum_gateway::serve_rest_api(grpc_client));
|
tokio::spawn(axum_gateway::serve_rest_api(grpc_client));
|
||||||
|
|
||||||
|
let mut sigterm_stream = signal::unix::signal(signal::unix::SignalKind::terminate())?;
|
||||||
select! {
|
select! {
|
||||||
_ = signal::ctrl_c() => {},
|
_ = signal::ctrl_c() => {
|
||||||
|
info!("Received SIGINT (Ctrl+C), shutting down...");
|
||||||
|
},
|
||||||
|
_ = sigterm_stream.recv() => {
|
||||||
|
info!("Received SIGTERM, shutting down...");
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
consul_registration::deregister_service(&consul_url, service_id.as_str())
|
consul_registration::deregister_service(&consul_url, service_id.as_str())
|
||||||
|
|||||||
@@ -77,9 +77,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
tokio::spawn(Server::builder()
|
tokio::spawn(Server::builder()
|
||||||
.add_service(AuthServiceServer::new(auth_service))
|
.add_service(AuthServiceServer::new(auth_service))
|
||||||
.serve(address));
|
.serve(address));
|
||||||
|
|
||||||
|
let mut sigterm_stream = signal::unix::signal(signal::unix::SignalKind::terminate())?;
|
||||||
select! {
|
select! {
|
||||||
_ = signal::ctrl_c() => {},
|
_ = signal::ctrl_c() => {
|
||||||
|
info!("Received SIGINT (Ctrl+C), shutting down...");
|
||||||
|
},
|
||||||
|
_ = sigterm_stream.recv() => {
|
||||||
|
info!("Received SIGTERM, shutting down...");
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tokio::{select, signal};
|
use tokio::{select, signal};
|
||||||
use tracing::Level;
|
use tracing::{info, Level};
|
||||||
use utils::consul_registration;
|
use utils::consul_registration;
|
||||||
use utils::service_discovery::get_service_address;
|
use utils::service_discovery::get_service_address;
|
||||||
|
|
||||||
@@ -50,8 +50,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let db_address = db_nodes.get(0).unwrap();
|
let db_address = db_nodes.get(0).unwrap();
|
||||||
let db_url = format!("http://{}:{}", db_address.ServiceAddress, db_address.ServicePort);
|
let db_url = format!("http://{}:{}", db_address.ServiceAddress, db_address.ServicePort);
|
||||||
|
|
||||||
|
let mut sigterm_stream = signal::unix::signal(signal::unix::SignalKind::terminate())?;
|
||||||
select! {
|
select! {
|
||||||
_ = signal::ctrl_c() => {},
|
_ = signal::ctrl_c() => {
|
||||||
|
info!("Received SIGINT (Ctrl+C), shutting down...");
|
||||||
|
},
|
||||||
|
_ = sigterm_stream.recv() => {
|
||||||
|
info!("Received SIGTERM, shutting down...");
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
||||||
|
|||||||
@@ -73,8 +73,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.add_service(CharacterServiceServer::new(my_service))
|
.add_service(CharacterServiceServer::new(my_service))
|
||||||
.serve(address));
|
.serve(address));
|
||||||
|
|
||||||
|
let mut sigterm_stream = signal::unix::signal(signal::unix::SignalKind::terminate())?;
|
||||||
select! {
|
select! {
|
||||||
_ = signal::ctrl_c() => {},
|
_ = signal::ctrl_c() => {
|
||||||
|
info!("Received SIGINT (Ctrl+C), shutting down...");
|
||||||
|
},
|
||||||
|
_ = sigterm_stream.recv() => {
|
||||||
|
info!("Received SIGTERM, shutting down...");
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ async fn handle_connection(stream: &mut TcpStream, pool: Arc<BufferPool>, auth_c
|
|||||||
|
|
||||||
pool.release(buffer).await;
|
pool.release(buffer).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(state) = connection_service.get_connection(&connection_id) {
|
if let Some(state) = connection_service.get_connection(&connection_id) {
|
||||||
let session_id = state.session_id.unwrap();
|
let session_id = state.session_id.unwrap();
|
||||||
let mut auth_client = auth_client.lock().await;
|
let mut auth_client = auth_client.lock().await;
|
||||||
@@ -148,8 +148,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut sigterm_stream = signal::unix::signal(signal::unix::SignalKind::terminate())?;
|
||||||
select! {
|
select! {
|
||||||
_ = signal::ctrl_c() => {},
|
_ = signal::ctrl_c() => {
|
||||||
|
info!("Received SIGINT (Ctrl+C), shutting down...");
|
||||||
|
},
|
||||||
|
_ = sigterm_stream.recv() => {
|
||||||
|
info!("Received SIGTERM, shutting down...");
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use std::sync::Arc;
|
|||||||
use tokio::{select, signal};
|
use tokio::{select, signal};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tonic::transport::Server;
|
use tonic::transport::Server;
|
||||||
use tracing::Level;
|
use tracing::{info, Level};
|
||||||
use utils::consul_registration;
|
use utils::consul_registration;
|
||||||
use utils::redis_cache::RedisCache;
|
use utils::redis_cache::RedisCache;
|
||||||
use utils::service_discovery::get_service_address;
|
use utils::service_discovery::get_service_address;
|
||||||
@@ -68,8 +68,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.add_service(SessionServiceServer::new(session_service))
|
.add_service(SessionServiceServer::new(session_service))
|
||||||
.serve(address));
|
.serve(address));
|
||||||
|
|
||||||
|
let mut sigterm_stream = signal::unix::signal(signal::unix::SignalKind::terminate())?;
|
||||||
select! {
|
select! {
|
||||||
_ = signal::ctrl_c() => {},
|
_ = signal::ctrl_c() => {
|
||||||
|
info!("Received SIGINT (Ctrl+C), shutting down...");
|
||||||
|
},
|
||||||
|
_ = sigterm_stream.recv() => {
|
||||||
|
info!("Received SIGTERM, shutting down...");
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tokio::{select, signal};
|
use tokio::{select, signal};
|
||||||
use tracing::Level;
|
use tracing::{info, Level};
|
||||||
use utils::consul_registration;
|
use utils::consul_registration;
|
||||||
use utils::service_discovery::get_service_address;
|
use utils::service_discovery::get_service_address;
|
||||||
|
|
||||||
@@ -50,8 +50,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let db_address = db_nodes.get(0).unwrap();
|
let db_address = db_nodes.get(0).unwrap();
|
||||||
let db_url = format!("http://{}:{}", db_address.ServiceAddress, db_address.ServicePort);
|
let db_url = format!("http://{}:{}", db_address.ServiceAddress, db_address.ServicePort);
|
||||||
|
|
||||||
|
let mut sigterm_stream = signal::unix::signal(signal::unix::SignalKind::terminate())?;
|
||||||
select! {
|
select! {
|
||||||
_ = signal::ctrl_c() => {},
|
_ = signal::ctrl_c() => {
|
||||||
|
info!("Received SIGINT (Ctrl+C), shutting down...");
|
||||||
|
},
|
||||||
|
_ = sigterm_stream.recv() => {
|
||||||
|
info!("Received SIGTERM, shutting down...");
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
|
||||||
|
|||||||
Reference in New Issue
Block a user