-
Notifications
You must be signed in to change notification settings - Fork 18
chore(shutdown): allow Shutdown to work on Windows #391
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
Open
zaharidichev
wants to merge
6
commits into
olix0r:main
Choose a base branch
from
zaharidichev:zd/windows-shutdown
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
02251a3
chore(shutdown): allow Shutdown to work on Windows
zaharidichev ac40c3c
install mingw with sudo
zaharidichev 80c1d2f
use unix instead of linux attr
zaharidichev 48ba3d4
deprecate `sigint_or_sigterm` in favor of `register`; use Ctrl-Shutdown
zaharidichev 664da85
Merge branch 'main' into zd/windows-shutdown
zaharidichev 7fac717
Merge branch 'main' into zd/windows-shutdown
olix0r 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
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,62 @@ | ||
| #[cfg(unix)] | ||
| pub(crate) mod unix { | ||
| use crate::shutdown::RegisterError; | ||
| use tokio::signal::unix::{signal, Signal, SignalKind}; | ||
|
|
||
| #[derive(Debug)] | ||
| #[must_use = "call `Shutdown::on_signal` to await a signal"] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "shutdown")))] | ||
| pub(crate) struct Signals { | ||
| interrupt: Signal, | ||
| terminate: Signal, | ||
| } | ||
|
|
||
| impl Signals { | ||
| pub(crate) fn new() -> Result<Self, RegisterError> { | ||
| let interrupt = signal(SignalKind::interrupt())?; | ||
| let terminate = signal(SignalKind::terminate())?; | ||
| Ok(Self { | ||
| interrupt, | ||
| terminate, | ||
| }) | ||
| } | ||
|
|
||
| pub(crate) async fn recv(&mut self) { | ||
| tokio::select! { | ||
| _ = self.interrupt.recv() => { | ||
| tracing::debug!("Received SIGINT"); | ||
|
|
||
| }, | ||
| _ = self.terminate.recv() => { | ||
| tracing::debug!("Received SIGTERM"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(windows)] | ||
| pub(crate) mod windows { | ||
| use crate::shutdown::RegisterError; | ||
| use tokio::signal::windows::{ctrl_shutdown, CtrlShutdown}; | ||
|
|
||
| #[derive(Debug)] | ||
| #[must_use = "call `Shutdown::on_signal` to await a signal"] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "shutdown")))] | ||
| pub(crate) struct Signals(CtrlShutdown); | ||
|
|
||
| impl Signals { | ||
| pub(crate) fn new() -> Result<Self, RegisterError> { | ||
| // On Windows, we use Ctrl-Shutdown as this is what Kubernetes uses to signal | ||
| // shutdown to windows containers. For reference, see: | ||
| // https://kubernetes.io/docs/concepts/windows/intro/#compatibility-v1-pod | ||
| let ctrl_shutdown = ctrl_shutdown()?; | ||
| Ok(Self(ctrl_shutdown)) | ||
| } | ||
|
|
||
| pub(crate) async fn recv(&mut self) { | ||
| self.0.recv().await; | ||
| tracing::debug!("Received Ctrl-Shutdown"); | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to make this consistent -- if we need it in clippy-all, we should have it on clippy (and check, etc)