This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@rodewitsch/pm2-supervisor

1.0.1 • Public • Published

pm2-supervisor

GitHub license Total alerts Language grade: JavaScript npm npm

A utility for periodically checking the availability of services launched by the pm2 process manager. Allows you to restart services in the event of a case described in the list of restart rules.

Installation pm2-supervisor

With NPM:

npm i -g @rodewitsch/pm2-supervisor

With Yarn:

yarn global add @rodewitsch/pm2-supervisor

With NPM from Github:

npm i -g git+https://github.com/rodewitsch/pm2-supervisor.git

Start with systemd

[Unit]
Description=pm2-supervisor
After=network.target

[Service]
Type=simple
User=ubuntu
ExecStart=pm2-supervisor
Restart=on-failure

[Install]
WantedBy=multi-user.target

Usage commands

Command Description
pm2-supervisor -h, --help Show help
pm2-supervisor -v, --version Show version
pm2-supervisor -t, --test Test rules config
pm2-supervisor -e, --edit Open editor with rules
pm2-supervisor -l, --list Print rules
pm2-supervisor Execute rules

Check types

httpStatus

Description

Perform an http request and restart the specified process when response code doesn't match the status code property of rule.

Rule options:

  • interval - (optional) executes the rule every specified time value
  • skip - (optional) number of skips before restarting the process
  • method - http method
  • url - url
  • body - (optional) http request body
  • headers - (optional) http request headers
  • statusCode - expected response code

GET example:

Check every second and if the endpoint's statusCode response does not match 200, restart the process named "server"..
{
    "serviceName": "server",
    "type": "httpStatus",
    "options": {
      "interval": "1s",
      "method": "GET",
      "url": "http://localhost:3000/502",
      "statusCode": 200
    }
  }

POST example:

  {
    "serviceName": "server",
    "type": "httpStatus",
    "options": {
      "interval": "1s",
      "method": "POST",
      "url": "http://localhost:3000/200",
      "body": [{ "somePayload": 1 }],
      "headers": { "Content-Type": "application/json" },
      "statusCode": 200
    }
  }

httpTimeout

Description

Perform an http request and restart the specified process when response doesn't received during the specified time.

Rule options:

  • interval - (optional) executes a rule every specified time value (syntax: 1s, 2m, 3h)
  • skip - (optional) number of skips before restarting the process
  • method - http method
  • url - url
  • body - (optional) http request body
  • headers - (optional) http request headers
  • timeout - request timeout

GET example:

Check every five seconds and if answer does not received during 1 minute, restart the process.
{
    "serviceName": "server",
    "type": "httpTimeout",
    "options": {
      "interval": "5s",
      "method": "GET",
      "url": "http://localhost:3000/200",
      "query": { "sleep": 5000 },
      "timeout": "1m"
    }
  }

cpuUsage

Description text

Restart a process when cpu usage is more than setted.

Rule options:

  • interval - (optional) executes a rule every specified time value (syntax: 1s, 2m, 3h)
  • skip - (optional) number of skips before restarting the process
  • usage - usage value

Example:

Check every 5 seconds and if some process with a specified name uses more cpu than written in a usage property, restart the process.
{
    "serviceName": "server",
    "type": "cpuUsage",
    "options": {
      "interval": "5s",
      "skip": 5,
      "usage": 80
    }
  }

memoryUsage

Description text

Restart a process when memory usage is more than setted.

Rule options:

  • interval - (optional) executes a rule every specified time value (syntax: 1s, 2m, 3h)
  • skip - (optional) number of skips before restarting the process
  • usage - memory usage value (syntax: 1kb, 2 mb, 3gb)

Example:

Check every 5 seconds and if any process with the specified name is using more memory than the usage property specified, restart the process.
{
    "serviceName": "server",
    "type": "memoryUsage",
    "options": {
      "interval": "5s",
      "skip": 5,
      "usage": "36mb"
    }
  }

Readme

Keywords

Package Sidebar

Install

npm i @rodewitsch/pm2-supervisor

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

22.7 kB

Total Files

11

Last publish

Collaborators

  • rodewitsch