# Running the Application
Once you've configured your routes and your HttpServer, you must run it. In Actix Web, this is done by calling .run() and .awaiting the result within the #[actix_web::main] context.
##The actix_web::main macro
Rust's main function cannot be async by default. To execute an async runtime, you need an executor. Actix Web provides a custom executor macro, #[actix_web::main], which sets up a Tokio-based runtime optimized for Actix Web's architecture.
##Graceful Shutdown
When running a production server, it's crucial to handle shutdowns gracefully. Actix Web's HttpServer automatically listens for standard OS signals (like SIGINT and SIGTERM). When it receives one, it will stop accepting new connections and give existing connections time to finish processing before exiting completely.
You can configure the shutdown timeout using .shutdown_timeout(seconds):
HttpServer::new(|| {
App::new().service(hello)
})
.bind("127.0.0.1:8080")?
.shutdown_timeout(30) // Wait up to 30 seconds for active requests to finish
.run()
.await##Hot Reloading in Development
While developing, it can be tedious to manually stop and start the server every time you make a change. A common pattern in the Rust ecosystem is to use cargo-watch.
Install it:
cargo install cargo-watchThen run your application with:
cargo watch -x runThis will automatically recompile and restart your Actix Web server whenever you save a Rust file.