hapi-shutdown

1.0.0 • Public • Published

Hapi-shutdown

Build Status NPM version Dependencies

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"

Readme

Keywords

Package Sidebar

Install

npm i hapi-shutdown

Weekly Downloads

16

Version

1.0.0

License

MIT

Last publish

Collaborators

  • acolchado
  • arnoldzokas
  • matteofigus
  • christriddle
  • ryantomlinson
  • andyroyle
  • stevejhiggs