From ad2ef2f851752a143fe6275bba8566d30a0a80af Mon Sep 17 00:00:00 2001 From: Dimitar Kerezov Date: Mon, 28 Oct 2019 16:04:35 +0200 Subject: [PATCH 1/2] Fix LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index d810592..7592464 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Telerik AppBuilder +Copyright (c) 2019 Progress Software Corporation. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 40fd745e48e5aa223f41e43ef6afd846b5e8d244 Mon Sep 17 00:00:00 2001 From: Dimitar Kerezov Date: Mon, 28 Oct 2019 16:44:04 +0200 Subject: [PATCH 2/2] Initial implementation --- .gitignore | 3 --- index.js | 22 ++++++++++++++++++++++ package.json | 21 +++++++++++++++++++++ typings/interfaces.d.ts | 8 ++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 index.js create mode 100644 package.json create mode 100644 typings/interfaces.d.ts diff --git a/.gitignore b/.gitignore index ad46b30..80caef7 100644 --- a/.gitignore +++ b/.gitignore @@ -36,9 +36,6 @@ build/Release node_modules/ jspm_packages/ -# TypeScript v1 declaration files -typings/ - # Optional npm cache directory .npm diff --git a/index.js b/index.js new file mode 100644 index 0000000..b88149e --- /dev/null +++ b/index.js @@ -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; diff --git a/package.json b/package.json new file mode 100644 index 0000000..8c1093a --- /dev/null +++ b/package.json @@ -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" +} diff --git a/typings/interfaces.d.ts b/typings/interfaces.d.ts new file mode 100644 index 0000000..d0ebb74 --- /dev/null +++ b/typings/interfaces.d.ts @@ -0,0 +1,8 @@ +interface KubernetesGracefulShutdownSignalHandler { + shouldShutdownGracefully: boolean; + installSignalHandler(): void; +} + +declare module "k8s-graceful-shutdown-signal-handler" { + export const kubernetesGracefulShutdownSignalHandler: KubernetesGracefulShutdownSignalHandler; +}