https://github.com/opentable/hapi-shutdown
handle SIGTERM and register triggers to be run before the server stops
https://github.com/opentable/hapi-shutdown
Last synced: about 1 year ago
JSON representation
handle SIGTERM and register triggers to be run before the server stops
- Host: GitHub
- URL: https://github.com/opentable/hapi-shutdown
- Owner: opentable
- License: mit
- Created: 2015-02-02T17:18:01.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-04-22T16:42:21.000Z (about 6 years ago)
- Last Synced: 2025-05-02T11:16:29.325Z (about 1 year ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 8
- Watchers: 19
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#Hapi-shutdown
[](https://travis-ci.org/opentable/hapi-shutdown) [](http://badge.fury.io/js/hapi-shutdown) 
Plugin listens to SIGTERM and then runs optional triggers before calling server.stop
This is for things that need to happen *before* `server.stop` is called.
For things that need to happen after server.stop, you can use `server.on('stop', ...)`
Usage:
```
var Hapi = require("hapi");
var server = new Hapi.Server();
server.register([
{
plugin: require('hapi-shutdown'),
options: {
serverSpindownTime: 10000 // time to wait for existing connections before forcibly stopping the server
}
}],
function(err){
server.start(function(){
server.plugins['hapi-shutdown'].register({
taskname: 'do stuff',
task: function(done){ console.log('doing stuff before server.stop is called'); done(); },
timeout: 2000 // time to wait
})
});
});
```
__.register(_task_)__
Register a task to be run before server.stop is called. Can be called as part of another plugin, or using `server.after()`.
Param: `task`
```
{
taskname: 'mytask', // used for logging and to guard against multiple registrations
task: function(done){
// do stuff
done()
},
timeout: 2000 // time in ms to wait for the task to complete
}
```
Returns: a joi validation error for the task.
__Logging__:
Will log using 'server.log()' and the tag "shutdown"