-
Notifications
You must be signed in to change notification settings - Fork 324
feat(server,mcp): add systemd watchdog integration #3233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hubcio
merged 5 commits into
apache:master
from
jpds:feat/systemd-service-notifications
May 13, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
044f47a
chore(deps): add sd-notify workspace dependency
jpds 0b4312b
feat(server): add systemd service notifications
jpds 3bc0727
feat(mcp): add systemd service notifications
jpds b012815
docs(server): document systemd integration
jpds 575b29e
docs(mcp): document systemd integration
jpds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| use tokio_util::sync::CancellationToken; | ||
| use tracing::{info, warn}; | ||
|
|
||
| pub fn notify_ready() { | ||
| if let Err(e) = sd_notify::notify(&[sd_notify::NotifyState::Ready]) { | ||
| warn!("Failed to send systemd READY=1 notification: {e}"); | ||
| } | ||
| } | ||
|
|
||
| pub fn notify_stopping() { | ||
| let _ = sd_notify::notify(&[sd_notify::NotifyState::Stopping]); | ||
| } | ||
|
|
||
| /// Spawn the watchdog keep-alive task. It stops cooperatively when `cancel` | ||
| /// fires (driven by the SIGINT/SIGTERM handler in `main`). | ||
| pub fn spawn_watchdog(cancel: CancellationToken) { | ||
| let Some(timeout) = sd_notify::watchdog_enabled() else { | ||
| return; | ||
| }; | ||
|
|
||
| let interval = timeout / 2; | ||
| info!( | ||
| "Systemd watchdog enabled, pinging every {}s (timeout: {}s).", | ||
| interval.as_secs(), | ||
| timeout.as_secs() | ||
| ); | ||
|
|
||
| tokio::spawn(async move { | ||
| loop { | ||
| tokio::select! { | ||
| _ = cancel.cancelled() => break, | ||
| _ = tokio::time::sleep(interval) => { | ||
| if let Err(e) = sd_notify::notify(&[sd_notify::NotifyState::Watchdog]) { | ||
| warn!("Failed to send systemd watchdog ping: {e}"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| //! Thin wrappers around `sd_notify` so every systemd interaction on the server | ||
| //! side lives in one place (mirrors `core/ai/mcp/src/systemd.rs`). | ||
|
|
||
| use tracing::warn; | ||
|
|
||
| /// Tell systemd the service has finished start-up (`READY=1`). | ||
| pub fn notify_ready() { | ||
| if let Err(e) = sd_notify::notify(&[sd_notify::NotifyState::Ready]) { | ||
| warn!("Failed to send systemd READY=1 notification: {e}"); | ||
| } | ||
| } | ||
|
|
||
| /// Tell systemd the service has begun shutting down (`STOPPING=1`). | ||
| pub fn notify_stopping() { | ||
| let _ = sd_notify::notify(&[sd_notify::NotifyState::Stopping]); | ||
| } | ||
|
|
||
| /// Surface a non-fatal shutdown problem in `systemctl status` / journald. | ||
| pub fn notify_status(status: &str) { | ||
| let _ = sd_notify::notify(&[sd_notify::NotifyState::Status(status)]); | ||
| } | ||
|
|
||
| /// Send a single watchdog keep-alive ping (`WATCHDOG=1`). | ||
| pub fn ping_watchdog() { | ||
| if let Err(e) = sd_notify::notify(&[sd_notify::NotifyState::Watchdog]) { | ||
| warn!("Failed to send systemd watchdog ping: {e}"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| use crate::shard::IggyShard; | ||
| use crate::shard::systemd; | ||
| use iggy_common::IggyError; | ||
| use std::rc::Rc; | ||
| use tracing::info; | ||
|
|
||
| pub fn spawn_systemd_watchdog(shard: Rc<IggyShard>) { | ||
| let Some(timeout) = sd_notify::watchdog_enabled() else { | ||
| return; | ||
| }; | ||
|
|
||
| let interval = timeout / 2; | ||
| info!( | ||
| "Systemd watchdog enabled, pinging every {}s (timeout: {}s).", | ||
| interval.as_secs(), | ||
| timeout.as_secs() | ||
| ); | ||
|
|
||
| shard | ||
| .task_registry | ||
| .periodic("systemd_watchdog") | ||
| .every(interval) | ||
| .tick(move |_shutdown| ping_watchdog()) | ||
| .spawn(); | ||
| } | ||
|
|
||
| async fn ping_watchdog() -> Result<(), IggyError> { | ||
| systemd::ping_watchdog(); | ||
| Ok(()) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.