1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 18:09:22 +02:00

add support for unix signals

This commit is contained in:
Nikolay Kim
2017-12-28 11:36:20 -08:00
parent 02b37570f4
commit d80a0c9f94
5 changed files with 109 additions and 5 deletions

View File

@ -0,0 +1,17 @@
[package]
name = "signals"
version = "0.1.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
[[bin]]
name = "server"
path = "src/main.rs"
[dependencies]
env_logger = "*"
futures = "0.1"
actix = "^0.3.5"
#actix-web = { git = "https://github.com/actix/actix-web.git" }
actix-web = { path="../../", features=["signal"] }

View File

@ -0,0 +1,4 @@
# Signals
This example shows how to handle unix signals and properly stop http server

View File

@ -0,0 +1,30 @@
extern crate actix;
extern crate actix_web;
extern crate futures;
extern crate env_logger;
use actix_web::*;
use actix::Arbiter;
use actix::actors::signal::{ProcessSignals, Subscribe};
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
let _ = env_logger::init();
let sys = actix::System::new("signals-example");
let addr = HttpServer::new(|| {
Application::new()
// enable logger
.middleware(middleware::Logger::default())
.resource("/", |r| r.h(httpcodes::HTTPOk))})
.bind("127.0.0.1:8080").unwrap()
.start();
// Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber()));
println!("Started http server: 127.0.0.1:8080");
let _ = sys.run();
}