Skip to content

Commit fe2c1d7

Browse files
committed
feat: Add sd_notify support
1 parent 4919cf5 commit fe2c1d7

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/http/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ rkyv = { version = "0.8.10", features = ["little_endian"] }
4545
form-data = { version = "0.6.0", features = ["sync"], default-features = false }
4646
mime = "0.3.17"
4747
compact_str = "0.9.0"
48+
sd-notify = "0.4.5"
4849

4950
[dev-dependencies]
5051

crates/http/src/management/reload.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use common::{
1010
ipc::{BroadcastEvent, HousekeeperEvent},
1111
};
1212
use directory::Permission;
13+
use http_proto::*;
1314
use hyper::Method;
15+
use sd_notify;
1416
use serde_json::json;
1517
use std::future::Future;
1618
use utils::url_params::UrlParams;
1719

18-
use http_proto::*;
19-
2020
pub trait ManageReload: Sync + Send {
2121
fn handle_manage_reload(
2222
&self,
@@ -43,7 +43,9 @@ impl ManageReload for Server {
4343
// Validate the access token
4444
access_token.assert_has_permission(Permission::SettingsReload)?;
4545

46-
match (path.get(1).copied(), req.method()) {
46+
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Reloading]);
47+
48+
let response = match (path.get(1).copied(), req.method()) {
4749
(Some("lookup"), &Method::GET) => {
4850
let result = self.reload_lookups().await?;
4951
// Update core
@@ -117,7 +119,11 @@ impl ManageReload for Server {
117119
.into_http_response())
118120
}
119121
_ => Err(trc::ResourceEvent::NotFound.into_err()),
120-
}
122+
};
123+
124+
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Ready]);
125+
126+
response
121127
}
122128

123129
async fn handle_manage_update(

crates/main/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ trc = { path = "../trc" }
3535
utils = { path = "../utils" }
3636
migration = { path = "../migration" }
3737
tokio = { version = "1.47", features = ["full"] }
38+
sd-notify = "0.4.5"
3839

3940
[target.'cfg(not(target_env = "msvc"))'.dependencies]
4041
jemallocator = "0.5.0"

crates/main/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use http::HttpSessionManager;
1414
use imap::core::ImapSessionManager;
1515
use managesieve::core::ManageSieveSessionManager;
1616
use pop3::Pop3SessionManager;
17+
use sd_notify;
1718
use services::{StartServices, broadcast::subscriber::spawn_broadcast_subscriber};
1819
use smtp::{StartQueueManager, core::SmtpSessionManager};
1920
use std::time::Duration;
@@ -97,9 +98,13 @@ async fn main() -> std::io::Result<()> {
9798
// Start broadcast subscriber
9899
spawn_broadcast_subscriber(init.inner, shutdown_rx);
99100

101+
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Ready]);
102+
100103
// Wait for shutdown signal
101104
wait_for_shutdown().await;
102105

106+
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]);
107+
103108
// Shutdown collector
104109
Collector::shutdown();
105110

0 commit comments

Comments
 (0)