https://github.com/haydenmeloche/graceful-shutdown
A Ktor server plugin that enables graceful shutdown with no configuration required
https://github.com/haydenmeloche/graceful-shutdown
k8s kotlin ktor ktor-plugin ktor-server
Last synced: 3 months ago
JSON representation
A Ktor server plugin that enables graceful shutdown with no configuration required
- Host: GitHub
- URL: https://github.com/haydenmeloche/graceful-shutdown
- Owner: HaydenMeloche
- License: mit
- Created: 2025-03-16T22:55:28.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2025-03-17T00:22:11.000Z (3 months ago)
- Last Synced: 2025-03-17T00:29:48.104Z (3 months ago)
- Topics: k8s, kotlin, ktor, ktor-plugin, ktor-server
- Language: Kotlin
- Homepage: https://jitpack.io/#dev.hayden/graceful-shutdown/
- Size: 59.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GracefulShutdown Plugin for Ktor
"Graceful shutdown" is a term for shutting down a process once it is complete any ongoing work.
This plugin accomplishes this by tracking all active requests Ktor is fulfilling and delaying the shutdown of Ktor until all active requests have been completed (or the specified timeout has elapsed).
This can be useful in an environment where you are doing rolling deployments with 0 downtime.
### Basic Setup
```kotlin
import dev.hayden.GracefulShutdownfun main() {
embeddedServer(Netty, port = 8080) {
install(GracefulShutdown)
// Your routes and other configurations
}.start(wait = true)
}
```### Advanced Configuration
The plugin offers several configuration options:
```kotlin
install(GracefulShutdown) {
// Maximum time to wait for requests to complete (default: 30 seconds)
shutdownTimeout = 45.seconds
// Enable in development mode (default: false)
enableInDevelopmentMode = true
// Add 'Connection: close' header to new requests during shutdown (default: true)
enableCloseConnectionHeader = true
}
```## Installation
This package uses Jitpack as its repository. This means you will need to add a custom repository for
Jitpack if you don't already have it.For Maven:
```xml
jitpack.io
https://jitpack.io
```
```xmldev.hayden
graceful-shutdown
1.0.1```
For gradle:
```groovy
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
```
```groovy
dependencies {
implementation 'dev.hayden:graceful-shutdown:1.0.1'
}
```For additional build systems check out: https://jitpack.io/#dev.hayden/graceful-shutdown