Browse Source

Add a ctrl-c handler for dora-daemon that stops all connected nodes

tags/v0.2.0-candidate
Philipp Oppermann 2 years ago
parent
commit
9e687be7cd
Failed to extract signature
3 changed files with 139 additions and 7 deletions
  1. +121
    -7
      Cargo.lock
  2. +1
    -0
      binaries/daemon/Cargo.toml
  3. +17
    -0
      binaries/daemon/src/lib.rs

+ 121
- 7
Cargo.lock View File

@@ -786,6 +786,16 @@ dependencies = [
"syn",
]

[[package]]
name = "ctrlc"
version = "3.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbcf33c2a618cbe41ee43ae6e9f2e48368cd9f9db2896f10167d8d762679f639"
dependencies = [
"nix 0.26.2",
"windows-sys 0.45.0",
]

[[package]]
name = "cty"
version = "0.2.2"
@@ -999,6 +1009,7 @@ name = "dora-daemon"
version = "0.1.0"
dependencies = [
"clap 3.2.20",
"ctrlc",
"dora-core",
"dora-download",
"dora-message",
@@ -1180,6 +1191,7 @@ name = "dora-runtime"
version = "0.1.2"
dependencies = [
"clap 3.2.20",
"ctrlc",
"dora-core",
"dora-download",
"dora-message",
@@ -1941,9 +1953,9 @@ dependencies = [

[[package]]
name = "libc"
version = "0.2.121"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"

[[package]]
name = "libloading"
@@ -2303,6 +2315,18 @@ dependencies = [
"memoffset",
]

[[package]]
name = "nix"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
"libc",
"static_assertions",
]

[[package]]
name = "ntapi"
version = "0.3.7"
@@ -2312,6 +2336,16 @@ dependencies = [
"winapi",
]

[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]

[[package]]
name = "num-bigint-dig"
version = "0.7.0"
@@ -2573,6 +2607,12 @@ version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"

[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"

[[package]]
name = "parking"
version = "2.0.0"
@@ -3318,6 +3358,8 @@ version = "0.1.2"
dependencies = [
"dora-node-api",
"eyre",
"tracing",
"tracing-subscriber",
]

[[package]]
@@ -3680,9 +3722,9 @@ checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5"

[[package]]
name = "smallvec"
version = "1.8.0"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"

[[package]]
name = "socket2"
@@ -3718,6 +3760,12 @@ dependencies = [
"der",
]

[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"

[[package]]
name = "stop-token"
version = "0.7.0"
@@ -4143,11 +4191,11 @@ dependencies = [

[[package]]
name = "tracing-subscriber"
version = "0.3.15"
version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b"
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
dependencies = [
"ansi_term",
"nu-ansi-term",
"sharded-slab",
"smallvec",
"thread_local",
@@ -4626,6 +4674,36 @@ dependencies = [
"windows_x86_64_msvc 0.36.1",
]

[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets",
]

[[package]]
name = "windows-targets"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.1",
"windows_i686_gnu 0.42.1",
"windows_i686_msvc 0.42.1",
"windows_x86_64_gnu 0.42.1",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.1",
]

[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"

[[package]]
name = "windows_aarch64_msvc"
version = "0.32.0"
@@ -4638,6 +4716,12 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"

[[package]]
name = "windows_aarch64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"

[[package]]
name = "windows_i686_gnu"
version = "0.32.0"
@@ -4650,6 +4734,12 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"

[[package]]
name = "windows_i686_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"

[[package]]
name = "windows_i686_msvc"
version = "0.32.0"
@@ -4662,6 +4752,12 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"

[[package]]
name = "windows_i686_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"

[[package]]
name = "windows_x86_64_gnu"
version = "0.32.0"
@@ -4674,6 +4770,18 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"

[[package]]
name = "windows_x86_64_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"

[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"

[[package]]
name = "windows_x86_64_msvc"
version = "0.32.0"
@@ -4686,6 +4794,12 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"

[[package]]
name = "windows_x86_64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"

[[package]]
name = "winreg"
version = "0.10.1"


+ 1
- 0
binaries/daemon/Cargo.toml View File

@@ -23,3 +23,4 @@ uuid = { version = "1.1.2", features = ["v4"] }
futures = "0.3.25"
clap = { version = "3.1.8", features = ["derive"] }
shared-memory-server = { path = "../../libraries/shared-memory-server" }
ctrlc = "3.2.5"

+ 17
- 0
binaries/daemon/src/lib.rs View File

@@ -115,6 +115,15 @@ impl Daemon {
exit_when_done: Option<BTreeSet<(Uuid, NodeId)>>,
) -> eyre::Result<()> {
let (dora_events_tx, dora_events_rx) = mpsc::channel(5);
let ctrlc_tx = dora_events_tx.clone();
ctrlc::set_handler(move || {
tracing::info!("received ctrc signal");
if ctrlc_tx.blocking_send(Event::CtrlC).is_err() {
tracing::error!("failed to report ctrl-c event to dora-daemon");
}
})
.wrap_err("failed to set ctrl-c handler")?;

let (shared_memory_handler, shared_memory_daemon_rx) = flume::unbounded();
let (shared_memory_handler_node, shared_memory_node_rx) = flume::bounded(10);
let daemon = Self {
@@ -198,6 +207,13 @@ impl Daemon {
.wrap_err("received unexpected watchdog reply from coordinator")?;
}
}
Event::CtrlC => {
for dataflow in self.running.values_mut() {
for (_node_id, channel) in dataflow.subscribe_channels.drain() {
let _ = channel.send_async(daemon_messages::NodeEvent::Stop).await;
}
}
}
}

let elapsed = start.elapsed();
@@ -681,6 +697,7 @@ pub enum Event {
Dora(DoraEvent),
ShmemHandler(ShmemHandlerEvent),
WatchdogInterval,
CtrlC,
}

impl From<DoraEvent> for Event {


Loading…
Cancel
Save