add systemd notify+watchdog

This commit is contained in:
Astro 2022-12-20 00:19:21 +01:00
parent 0c13db943c
commit 454799c296
4 changed files with 92 additions and 5 deletions

80
Cargo.lock generated
View file

@ -190,6 +190,12 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "build-env"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1522ac6ee801a11bf9ef3f80403f4ede6eb41291fac3dde3de09989679305f25"
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.11.1" version = "3.11.1"
@ -214,6 +220,7 @@ dependencies = [
"serde_json", "serde_json",
"serde_yaml", "serde_yaml",
"sigh", "sigh",
"systemd",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-postgres", "tokio-postgres",
@ -305,6 +312,16 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "cstr-argument"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6bd9c8e659a473bce955ae5c35b116af38af11a7acb0b480e01f3ed348aeb40"
dependencies = [
"cfg-if",
"memchr",
]
[[package]] [[package]]
name = "cxx" name = "cxx"
version = "1.0.83" version = "1.0.83"
@ -407,7 +424,28 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [ dependencies = [
"foreign-types-shared", "foreign-types-shared 0.1.1",
]
[[package]]
name = "foreign-types"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
dependencies = [
"foreign-types-macros",
"foreign-types-shared 0.3.1",
]
[[package]]
name = "foreign-types-macros"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8469d0d40519bc608ec6863f1cc88f3f1deee15913f2f3b3e573d81ed38cccc"
dependencies = [
"proc-macro2",
"quote",
"syn",
] ]
[[package]] [[package]]
@ -416,6 +454,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "foreign-types-shared"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
[[package]] [[package]]
name = "form_urlencoded" name = "form_urlencoded"
version = "1.1.0" version = "1.1.0"
@ -765,6 +809,17 @@ version = "0.2.138"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
[[package]]
name = "libsystemd-sys"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed080163caa59cc29b34bce2209b737149a4bac148cd9a8b04e4c12822798119"
dependencies = [
"build-env",
"libc",
"pkg-config",
]
[[package]] [[package]]
name = "link-cplusplus" name = "link-cplusplus"
version = "1.0.7" version = "1.0.7"
@ -938,7 +993,7 @@ checksum = "29d971fd5722fec23977260f6e81aa67d2f22cadbdc2aa049f1022d9a3be1566"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if", "cfg-if",
"foreign-types", "foreign-types 0.3.2",
"libc", "libc",
"once_cell", "once_cell",
"openssl-macros", "openssl-macros",
@ -1457,6 +1512,21 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8"
[[package]]
name = "systemd"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afec0101d9ae8ab26aedf0840109df689938ea7e538aa03df4369f1854f11562"
dependencies = [
"cstr-argument",
"foreign-types 0.5.0",
"libc",
"libsystemd-sys",
"log",
"memchr",
"utf8-cstr",
]
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.3.0" version = "3.3.0"
@ -1804,6 +1874,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "utf8-cstr"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55bcbb425141152b10d5693095950b51c3745d019363fc2929ffd8f61449b628"
[[package]] [[package]]
name = "valuable" name = "valuable"
version = "0.1.0" version = "0.1.0"

View file

@ -23,3 +23,4 @@ chrono = "0.4"
eventsource-stream = "0.2" eventsource-stream = "0.2"
futures = "0.3" futures = "0.3"
tokio-postgres = "0.7" tokio-postgres = "0.7"
systemd = "0.10"

View file

@ -255,10 +255,13 @@ async fn main() {
}); });
let addr = SocketAddr::from(([127, 0, 0, 1], config.listen_port)); let addr = SocketAddr::from(([127, 0, 0, 1], config.listen_port));
let server = axum::Server::bind(&addr)
.serve(app.into_make_service());
tracing::info!("serving on {}", addr); tracing::info!("serving on {}", addr);
axum::Server::bind(&addr) systemd::daemon::notify(false, [(systemd::daemon::STATE_READY, "1")].iter())
.serve(app.into_make_service()) .unwrap();
.await server.await
.unwrap(); .unwrap();
} }

View file

@ -122,6 +122,13 @@ pub fn spawn(
&key_id, &private_key_, body_ &key_id, &private_key_, body_
).await { ).await {
tracing::error!("relay::send {:?}", e); tracing::error!("relay::send {:?}", e);
} else {
// success
systemd::daemon::notify(
false, [
(systemd::daemon::STATE_WATCHDOG, "1")
].iter()
).unwrap();
} }
}); });
} }