Giter Club home page Giter Club logo

reloading-node.js-gracefully's Introduction

Reloading a server in Node.js

The problem

Sometimes we could need reload a server without cut off the connections. We can use the "close" call and wait to the established connections, because "close" stops the server from accepting new connections. But in case we are using WebSockets the "close" call is not enough, becase a WebSocket could not finish in days. So we need a way to be able to detect if a WebSocket is in idle status to kill it and the solution is the server-shutdown module (@mitmaro).

This example

This example is based in two different examples:

Usage

node server/server.js

Example

  1. In a shell launch the master script:
$ node server/master.js
[6974] : Started master with 6974
[6980] :     Listeting at http://localhost:8100
[6980] :     A client (wqHAB1KF2Tl0dDrnAAAA) has connected
[...]
[6974] : Reloading...
[7011] :     Listeting at http://localhost:8100
[6974] : Sending SIGHUP signal to my child 6980
[6980] :     SIGHUP signal got. Exit graceluffy.
[6980] :     server end graceluffy.
[7011] :     A client (pYw7AtZHggIaFVu7AAAA) has connected
[...]
[6974] : stopping all...
[6974] : Sending SIGTERM signal to my child 7011
[7011] :     SIGTERM signal got. Exit now.
  1. In another shell we send the signals:
$ kill -SIGHUP 6974
$ kill -SIGTERM 6974

reloading-node.js-gracefully's People

Contributors

dayer3 avatar

Watchers

 avatar

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.