Skip to content

Commit

Permalink
APPENG-1147: Log shutdown signal received with signal handler (#48)
Browse files Browse the repository at this point in the history
* APPENG-1147: Log shutdown signal received with signal handler

* APPENG-1147: Remove signals that cannot be overriden by application

* APPENG-1147: additional log for registering signal handlers
  • Loading branch information
normanma-tw authored Feb 19, 2025
1 parent a16e3a4 commit 33fdb47
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.15.2] - 2025-02-19

### Added
* Added logging for shutdown signals received.

## [2.15.1] - 2024-12-05

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.context.SmartLifecycle;
import org.springframework.context.support.DefaultLifecycleProcessor;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import sun.misc.Signal;

@Slf4j
public class GracefulShutdowner implements SmartLifecycle, InitializingBean {
Expand Down Expand Up @@ -46,6 +47,7 @@ public void afterPropertiesSet() {
@Override
public void start() {
running = true;
initShutdownSignalLogging(new Signal("INT"), new Signal("TERM"));

validateStrategies();

Expand All @@ -61,6 +63,13 @@ public void start() {
}
}

protected void initShutdownSignalLogging(Signal... signals) {
for (var signal : signals) {
log.info("Registering shutdown signal handler for signal '{}'", signal.toString());
Signal.handle(signal, sig -> log.info("Received signal {}", sig.toString()));
}
}

protected void validateStrategies() {
var registeredStrategies = ImmutableSet.copyOf(gracefulShutdownStrategiesRegistry.getStrategies());
var strategiesInAppContext = ImmutableSet.copyOf(applicationContext.getBeansOfType(GracefulShutdownStrategy.class).values());
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.15.1
version=2.15.2

0 comments on commit 33fdb47

Please sign in to comment.