Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitko-Kerezov committed Oct 28, 2019
1 parent ad2ef2f commit 40fd745
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ build/Release
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

Expand Down
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

class KubernetesGracefulShutdownSignalHandler {
constructor() {
this.gracefulShutdown = false;
}

get shouldShutdownGracefully() {
return this.gracefulShutdown;
}

installSignalHandler() {
if (process.env.RUNNING_KUBERNETES) {
process.on('SIGUSR1', () => {
this.gracefulShutdown = true;
});
}
}
}

const kubernetesGracefulShutdownSignalHandler = new KubernetesGracefulShutdownSignalHandler();
module.exports.kubernetesGracefulShutdownSignalHandler = kubernetesGracefulShutdownSignalHandler;
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "k8s-graceful-shutdown-signal-handler",
"types": "./typings/interfaces.d.ts",
"version": "0.1.0",
"description": "Package for managing graceful shutdown in a k8s cluster",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Icenium/k8s-graceful-shutdown-signal-handler.git"
},
"keywords": [],
"author": "Progress Software Corporation",
"license": "MIT",
"bugs": {
"url": "https://github.com/Icenium/k8s-graceful-shutdown-signal-handler/issues"
},
"homepage": "https://github.com/Icenium/k8s-graceful-shutdown-signal-handler#readme"
}
8 changes: 8 additions & 0 deletions typings/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface KubernetesGracefulShutdownSignalHandler {
shouldShutdownGracefully: boolean;
installSignalHandler(): void;
}

declare module "k8s-graceful-shutdown-signal-handler" {
export const kubernetesGracefulShutdownSignalHandler: KubernetesGracefulShutdownSignalHandler;
}

0 comments on commit 40fd745

Please sign in to comment.