| 267 | } |
| 268 | |
| 269 | async fn do_main() { |
| 270 | debug!("Starting"); |
| 271 | let Config { |
| 272 | cache_size, |
| 273 | cache_path, |
| 274 | bind_addr, |
| 275 | durable_fs, |
| 276 | } = Config::from_args(); |
| 277 | |
| 278 | let addr = match net::SocketAddr::from_str(&bind_addr) { |
| 279 | Ok(a) => a, |
| 280 | Err(e) => { |
| 281 | error!( |
| 282 | "Could not parse redis server address {} -> {:?}", |
| 283 | bind_addr, e |
| 284 | ); |
| 285 | return; |
| 286 | } |
| 287 | }; |
| 288 | |
| 289 | let (shutdown_tx, shutdown_rx) = oneshot::channel(); |
| 290 | |
| 291 | let mut handle = tokio::spawn(async move { |
| 292 | run_server(cache_size, cache_path, durable_fs, addr, shutdown_rx).await; |
| 293 | }); |
| 294 | |
| 295 | tokio::select! { |
| 296 | Some(()) = async move { |
| 297 | let sigterm = tokio::signal::unix::SignalKind::terminate(); |
| 298 | tokio::signal::unix::signal(sigterm).unwrap().recv().await |
| 299 | } => {} |
| 300 | Ok(()) = tokio::signal::ctrl_c() => { |
| 301 | } |
| 302 | _ = &mut handle => { |
| 303 | warn!("Server has unexpectedly stopped!"); |
| 304 | return; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | info!("Starting shutdown process ..."); |
| 309 | shutdown_tx |
| 310 | .send(()) |
| 311 | .expect("Could not send shutdown signal!"); |
| 312 | // Ignore if there is an error from the handler on return. |
| 313 | let _ = handle.await; |
| 314 | info!("Server has stopped!"); |
| 315 | } |
| 316 | |
| 317 | #[tokio::main] |
| 318 | async fn main() { |