Giter Site home page Giter Site logo

futurestudio / hapi-pulse Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 1.0 369 KB

hapi plugin that gracefully stops the hapi server (for graceful process reloads, e.g. with PM2)

License: MIT License

JavaScript 100.00%
hapi hapijs hapi-plugin hapi-server pm2 signal shutdown graceful-shutdown hapi-pulse future-studio-university

hapi-pulse's Introduction

hapi-pulse logo

hapi plugin to gracefully stop your hapi server


Installation · Usage · Plugin Options



Build Status Known Vulnerabilities Latest Version Total downloads

Follow @marcuspoehls for updates!


The Future Studio University supports development of this hapi plugin 🚀
Join the Future Studio University and Skyrocket in Node.js


Introduction

A hapi plugin that gracefully stops the hapi server on SIGINT and SIGTERM and your custom signals.

hapi-pulse works great with PM2 and other Node.js process manager to accomplish zero-downtime deployments!

This serves existing requests before closing the connection and stopping the hapi server process. It uses hapi’s server.stop() method to close connections properly.

Requirements

hapi v19 (or later) and Node.js v12 (or newer)

This plugin requires hapi v19 (or later) and Node.js v12 or newer.

Compatibility

Major Release hapi.js version Node.js version
v3 >=17 hapi >=12
v2 >=17 hapi >=8

Installation

Add hapi-pulse as a dependency to your project:

npm i hapi-pulse

Usage

The most straight forward way to register the hapi-pulse plugin:

await server.register({
  plugin: require('hapi-pulse'),
  options: {
    // any option that is supported by hapi's "server.stop()"
    timeout: 15000,

    // plugin specific options
    logger: console,
    signals: ['SIGINT'],
    postServerStop: async function () {
      // await Database.close()
    }
  }
})

Plugin Registration Options

hapi-pulse passes the options through to hapi’s server.stop(options). Customize the behavior of server.stop(), like the timeout before forcefully stopping the process.

Additionally, you can pass along the following options:

  • logger: (Object), default: console — in case of an error, hapi-pulse logs the error with logger.error('message', error)
  • signals: (Array), default: ['SIGINT', 'SIGTERM'] — use this signals option to customize the events on which hapi-pulse will stop the server
  • preServerStop: (Function), default: Promise.resolve — an async function that runs before server.stop()
  • postServerStop: (Function), default: Promise.resolve — an async function that runs after server.stop()
  • preShutdown: (Function), default: Promise.resolve — an async function that runs after postServerStop() and before process.exit
  • timeout: (int), default: 5000 (5 seconds) — the timeout existing connections should be closed until they are forcefully interrupted. This option is passed through to hapi’s server.stop()

Example

await server.register({
  plugin: require('hapi-pulse'),
  options: {
    timeout: 25 * 1000,
    logger: console,
    signals: ['SIGINT', 'SIGTERM'],
    preServerStop: async function () {
      // this runs before server.stop()
    },
    postServerStop: async function () {
      // this runs after server.stop()
      // e.g., await Database.close()
    },
    preShutdown: async function () {
      // this runs after postServerStop() and before process.exit
    }
  }
})

// went smooth like chocolate :)

Feature Requests

Do you miss a feature? Please don’t hesitate to create an issue with a short description of your desired addition to this plugin.

Links & Resources

Contributing

  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀

License

MIT © Future Studio


futurestud.io  ·  GitHub @futurestudio  ·  Twitter @futurestud_io

hapi-pulse's People

Contributors

alferpal avatar celsiusf avatar dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeper[bot] avatar marcuspoehls avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

siarcarse

hapi-pulse's Issues

Warnings when installing hapi-pulse

Hi I am getting the following yarn warnings:

warning hapi-pulse > @hapi/[email protected]: Switch to 'npm install joi'
warning hapi-pulse > @hapi/joi > @hapi/[email protected]: Moved to 'npm install @sideway/address'
warning hapi-pulse > @hapi/joi > @hapi/[email protected]: Moved to 'npm install @sideway/pinpoint'
warning hapi-pulse > @hapi/joi > @hapi/[email protected]: Moved to 'npm install @sideway/formula'

I installed hapi-pulse 3.0.0
I am using @hapi/hapi: 20.1.3 and joi: 17.4.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.