# adios

> A simple module for handling shutdowns within a clustered application.

Latest version **2.1.0** (published 2019-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install adios
pnpm add adios
yarn add adios
bun add adios
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2019-04-30 |
| First published | 2015-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6 |
| Dependencies | 0 |
| Unpacked size | 215.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Elliott Foster |
| Maintainers | elliotttf |
| Keywords | shutdown, cluster |

## Links

- npm: https://www.npmjs.com/package/adios
- Repository: https://github.com/elliotttf/adios
- Homepage: https://github.com/elliotttf/adios#readme
- Issues: https://github.com/elliotttf/adios/issues
- npm.io page: https://npm.io/package/adios

## Recent versions

- 2.1.0 (latest) — 2019-04-30
- 2.0.0 — 2016-11-01
- 1.1.2 — 2016-02-22
- 1.1.1 — 2016-02-22
- 1.1.0 — 2016-02-22
- 1.0.2 — 2015-12-10
- 1.0.1 — 2015-12-10
- 1.0.0 — 2015-12-10

## README

# Adios

[![Greenkeeper badge](https://badges.greenkeeper.io/elliotttf/adios.svg)](https://greenkeeper.io/)

[![Build Status](https://travis-ci.org/elliotttf/adios.svg?branch=master)](https://travis-ci.org/elliotttf/adios)
[![Coverage Status](https://coveralls.io/repos/elliotttf/adios/badge.svg?branch=master&service=github)](https://coveralls.io/github/elliotttf/adios?branch=master)

A module for notifying clustered workers for clean shutdowns.

This is accomplished by using [domain sockets](https://en.wikipedia.org/wiki/Unix_domain_socket)
– `/var/run/adios.sock` by default – which has the added benefit of not sending messages over
application specific IPC channels. This means you don't have to filter out messages from adios
in any `process.on('message')` listeners.

_Note_: On Windows, the local domain is implemented using a named pipe. The path must refer to an
entry in `\\?\pipe\` or `\\.\pipe\`. Therefore, you must initialize adios with a path in this space
if you are running on a Windows machine.

## Usage

```javascript
'use strict';
const cluster = require('cluster');
const http = require('http');
const Adios = require('adios');

if (cluster.isMaster) {
  Adios.master.init()
    .then(() => {
      let worker = cluster.fork();
    });
}
else {
  let server = http.createServer();
  Adios.child.init(() => {
    return new Promise(resolve => {
      server.close(resolve);
    });
  })
    .then(() => {
      server.listen(3000);
    });
}
```

## API

* `Adios.master.init([path])` - The initialize function for adios masters. Sets
  up a server for IPC with clustered workers. Note: there can be only one.
  * `path` - (optional) The socket path to use. Defaults to /var/run/adios.sock
  * `config` - (optional) A configuration object for the master process.
    Contains:
    * `timeout`: time in milliseconds before a child will be force closed.
      Default: 10000, 10 seconds.

  Returns a promise that resolves when the server is listening.

* `Adios.master.kill(pid)` - Method to kill a worker by process id
  * `pid` - The process id to kill

* `Adios.master.term(pid)` - Method to terminate a worker by process id, this
  will call the graceful shutdown defined by the worker.
  * `pid` - The process id to terminate

  Returns a promise that resolves when the worker is terminated.

* `Adios.child.init(cleanCb[, path])` - The initialize function for adios
  children. Sets up a connection to the master. Note: there can be only one per
  process and it must be running on a child process.
   * `cleanCb` - The method to execute when the master is notifying of a
     shutdown. Must return a promise that resolves when work is done.
   * `path` - (optional) The socket path to use. Defaults to /var/run/adios.sock

   Returns a promise that resolves when the connection with the master has been
   established.

---
_Source: https://npm.io/package/adios · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
