• This repository has been archived on 24/Jun/2024
  • Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Springboot Graceful Shutdown Hook for a container environment like Openshift

Springboot-Graceful-Shutdown for OpenShift/Kubernetes

The Springboot-Graceful-Shutdown enables your spring boot application to do a rolling deployment without any downtime on OpenShift. We (SBB) use this in a dockerized Cloud environment on OpenShift - it should also work on Kubernetes. We use here the terminology of OpenShift/Kubernetes: Pods (roughly containers) and Services (logical load balancers that combine N containers). OpenShift needs to know when a Pod is ready to respond to requests. That is done via the readiness probe. As soon as the readiness probe of a Pod fails, OpenShift takes the Pod off the service, so user requests are no longer sent to this Pod.

Gracefulshutdown in Springboot 2.3

In Springboot Version 2.3 Graceful shutdown is implemented out of the box. We didn't test it yet, but suggest you to at least try it out, because it wouldn't need the dependency to this project: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#new-and-noteworthy

Graceful Shutdown Workflow

Here is an example of how the graceful shutdown workflow works:

  1. OpenShift sends the Pod the SIGTERM signal which tells the Docker instance to shutdown all its processes. This can happen when scaling down a Pod by hand or automatically during a rolling deployment of OpenShift.
  2. The JVM receives the SIGTERM signal and the graceful shutdown hook sets the readiness probe to false
  3. The process waits for a defined time to initiate the shutdown of the spring context, e.g. for 20 seconds. This time is needed for OpenShift to detect that the Pod is no longer ready and to remove the pod from the service. The readiness probe check interval must in this case be configured to be less than 20 seconds.
  4. OpenShift removes the Pod from the Service.
  5. After the configured wait time, for example 20 seconds, the spring context will be shut down. Open transactions will be properly finished.
  6. After the Spring Boot application is shutdown, the liveness probe will automatically be set to false.
  7. Pod is shutdown and removed.

How to use it

  1. Add the maven dependency for Spring Boot actuator and this graceful shutdown starters:
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <version>X.X.X</version>
    </dependency>
    <dependency>
        <groupId>ch.sbb</groupId>
        <artifactId>springboot-graceful-shutdown</artifactId>
        <version>X.X</version>
    </dependency>
  1. Start your application with the alternative method GracefulshutdownSpringApplication.run instead of SpringApplication.run, e.g.
@SpringBootApplication
public class EstaGracefullshutdownTesterApp {

    public static void main(String[] args) {
        GracefulshutdownSpringApplication.run(EstaGracefullshutdownTesterApp.class, args);
    }
}
  1. Optionally, adapt the shutdown delay (in your yaml, properties or system property) - the default is 20 seconds:
  • Yaml or Properties: estaGracefulShutdownWaitSeconds: 30
  • System Property: -DestaGracefulShutdownWaitSeconds=30

Start now your application and point your readiness probe to http://yourhost:8282/health and set the check interval lower than the shutdown delay, for example, to 10 seconds. In your developement environment (Eclipse or IntelliJ) you can simulate a SIGTERM: For this use the exit operation (do not terminate it via the stop icon). Then check what happens with the health check and the shutdown of the spring context.

If you want to implement your own readiness check implement your RestController with the ch.sbb.esta.openshift.gracefullshutdown.IProbeController interface.

Other Graceful Shutdown implementation for Spring Boot:

Good to know

If you do a rolling deployment, the risk of having failing service calls is minimized with this strategy. It is still possible that service calls fail because of the OpenShift internal routing, network issues, or other components between service caller and service host.

Releasing (internal)

If you want to create a new release, you need to do following steps:

  1. Generate your PGP Keys with Gnugpg: gpg --gen-key
  2. Publish your PGP Key to a public server: gpg --keyserver keyserver.ubuntu.com --send-key YOURKEYID
  3. Copy the prepared Maven settings.xml from this repo to your Maven home directory
  4. Adjust all the user and password configurations in the settings.xml
  5. You find the sonatype credentials on the protected password page of the SBB ESTA Team
  6. Adjust the version in the pom.xml -SNAPSHOT for a snapshot deployment, without the -SNAPSHOT for a release deployment.
  7. Execute mvn clean deploy
  8. If the build was successful, check on oss.sonatype.org whether your version was published
  9. In case of troubles contact the owner of the repository

Be aware that releasing behind the proxy might not work as the URL is blocked. Publishing a SNAPSHOT publishing worked fine from behind the proxy.

Credits

This Shutdownhook was created, maintained and used by the SBB ESTA team in Switzerland.

More Repositories

1

scion-workbench

SCION Workbench enables the creation of Angular web applications that require a flexible layout to arrange content side-by-side or stacked, all personalizable by the user via drag & drop.
TypeScript
80
star
2

scion-microfrontend-platform

SCION Microfrontend Platform is a TypeScript-based open-source library that helps to implement a microfrontend architecture using iframes.
TypeScript
68
star
3

mobile-ios-design-swiftui

Design System Mobile for iOS & SwiftUI
Swift
63
star
4

api-principles

The applicable SBB API Principles
SCSS
44
star
5

design_system_flutter

This framework contains SBB (Swiss Federal Railways) UI elements for Flutter Apps.
Dart
31
star
6

netzgrafik-editor-frontend

The Netzgrafik-Editor is a powerful software that enables the creation, modification, and analysis of regular-interval timetable.
TypeScript
30
star
7

matsim-sbb-extensions

matsim swiss rail
21
star
8

sbb-ml-models

Mobile Machine Learning Models
Python
17
star
9

sbb-ml-ios

SBB Mobile Machine Learning for iOS devices
Swift
17
star
10

abm-in-visum

ABM-in-Visum: a collaborative project for activity-based transport demand modelling within the PTV Visum software hosted by Swiss Federal Railways (SBB).
Python
16
star
11

sbb-rasta-stack

SBB RaSTA Protocol Reference Stack
C++
15
star
12

ch.sbb.polarion.extension.pdf-exporter

Polarion extension for customised PDF exports
Java
13
star
13

sbb-ml-android

SBB Mobile Machine Learning for Android devices
C++
12
star
14

container-platform-base

Python
11
star
15

ch.sbb.polarion.extension.generic

This is a Polarion extension which provides common part to other extensions reducing code duplication.
Java
11
star
16

SwissPassSDK-iOS

SwissPass SDK for iOS
Swift
10
star
17

thingsboard-advanced-attribute-widget

JavaScript
9
star
18

iib-maven-plugin

Maven Plugin for building IBM Integration Bus Projekts
Java
9
star
19

weasyprint-service

Rest API service providing WeasyPrint functionality
Python
9
star
20

journey-service

Journey-Service::B2C documentation (see https://developer.sbb.ch/apis/journey-service)
9
star
21

hibernate_hbm2annotation

PHP
8
star
22

BCNFStar

Interactive Schema Management for Data Warehouses
TypeScript
8
star
23

open-source-polarion-java-repo-template

8
star
24

ch.sbb.polarion.extension.api-extender

This Polarion extension provides additional functionality which is not implemented in standard Polarion API for some reason.
Java
6
star
25

scion-toolkit

SCION Toolkit is a collection of UI components and utilities designed primarily for use in SCION libraries and their demo and test applications.
TypeScript
6
star
26

netzgrafik-editor-backend

Backend for the Netzgrafik-Editor
Java
6
star
27

journey-maps-client

⛔️ DEPRECATED. Moved to https://github.com/sbb-design-systems/sbb-angular
TypeScript
5
star
28

rcm-dx

Batchfile
5
star
29

SynPopToolbox

SynPopToolbox is a Python framework designed for analysis, visualization and manipulation of a synthetic population produced by the land-use simulation software FaLC (https://github.com/falc-sim-org/FaLC) and related subproducts. Contact: [email protected]
Python
5
star
30

ch.sbb.polarion.extension.interceptor-manager.hook-samples

Hook samples for SchweizerischeBundesbahnen/ch.sbb.polarion.extension.interceptor
Java
5
star
31

ch.sbb.polarion.extension.excel-importer

This Polarion extension provides possibility to update (or create) WorkItems using xlsx-file.
Java
4
star
32

ch.sbb.polarion.extension.json-editor

This Polarion extension provides possibility to edit JSON files as WorkItem attachments.
JavaScript
4
star
33

polarion-artifacts-deployer

Python
4
star
34

ch.sbb.polarion.extension.interceptor-manager

This Polarion extension provides possibility to run custom Java code (via hooks), before Polarion saves/deletes a Work Item, Document or Test Run.
Java
4
star
35

esta-webjs-extensions

Extension modules for ESTA WebJS
TypeScript
4
star
36

DAS

Driver Advisory System
Dart
4
star
37

cimon_controller

Scripts for a CI Monitor (Buildmonitor) - request status from jenkins and display to traffic light or power socket.
Python
4
star
38

matsim-sbb

Java
4
star
39

ch.sbb.polarion.thirdparty.bundles

Custom third-party dependencies
Java
3
star
40

ch.sbb.polarion.extension.pdf-exporter.webhook-samples

Samples for PDF-Exporter Webhooks
Python
3
star
41

perma

A library for simple persistent maps and sets
Java
3
star
42

scion-microfrontend-platform-getting-started

Provides minimal application skeletons to easily work through the Getting Started Guide of the SCION Microfrontend Platform.
TypeScript
3
star
43

BakeTime

Experiment for OKR iteration
TypeScript
3
star
44

ch.sbb.export-package-generator

This project is used to find all exported packages and append them to the MANIFEST.MF file. It searches for sub-packages within the specified root packages and creates an "Export-Package" entry in the manifest file.
Java
3
star
45

ch.sbb.polarion.extension.cucumber

This Polarion extension is designed to integrate BDD process into Polarion. It provides the almost same functionality as Xray plugin for Jira.
Java
3
star
46

casc-renovate-preset-polarion-python

Renovate configuration for Polarion Python Repos
2
star
47

casc-renovate-preset-polarion-java

Renovate configuration for Polarion Java Repos
2
star
48

VDV736_RG_CH

XSLT
2
star
49

maven-wmb7-plugin

Maven Plugin for building IBM WebSphere Message Broker 7+ Projekts
Java
2
star
50

lot

Lightweight Operator Toolbox module for GO
Go
2
star
51

scion-workbench-demo

The "SCION Workbench Demo Application" is a reference application created to show how to develop web applications based on SCION Workbench.
TypeScript
2
star
52

SwissPassSDK-Android

SwissPass SDK for Android
Java
2
star
53

casc-renovate-preset-polarion-docker

Renovate configuration for Polarion Docker Repos
2
star
54

beacon-sdk-android

Kotlin
2
star
55

markdown2html-maven-plugin

This Maven plugin uses GitHub API for converting Markdown to HTML
Java
2
star
56

rsp

Re-Scheduling Problem (MontrΓ©al)
Python
1
star
57

open-source-polarion-docker-repo-template

1
star
58

open-source-polarion-python-repo-template

1
star
59

rcm-dx-viewer

Github space for SBB RCM-DX viewer
1
star
60

cimon_setup

Shell
1
star
61

openshift-patchnix

OpenShift Cluster Maintenance Ansible Scheduler
Ruby
1
star
62

sbb-graphs

Dart
1
star
63

wmb7-maven-projects-archetype

Archetype for use with the maven-wmb7-plugin
PHP
1
star
64

icinga2-plugins

Some bash scripts to do web checks with our tools
Python
1
star
65

cimon_web2

TypeScript
1
star
66

flutter-oidc

OIDC Library for Flutter apps
Dart
1
star
67

scion-rcp

SCION-related libraries to support integration in RCP applications
Java
1
star