Giter Site home page Giter Site logo

radagaisus / pm2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unitech/pm2

0.0 3.0 0.0 760 KB

Modern CLI process manager for Node apps with a builtin load-balancer

Home Page: http://unitech.io

License: MIT License

JavaScript 90.73% Shell 9.27%

pm2's Introduction

Monit

The modern and stable CLI process manager for Node apps with native clusterization, monitoring, hot code reload, startup scripts and much more.

Tested with Node v0.11, v0.10, v0.9, v0.8 (https://travis-ci.org/Unitech/pm2). Compatible CoffeeScript. Works on Linux & MacOS.

NPM

Build Status Build Status NPM version

Blog post for some context : Goodbye node-forever, hello PM2

Flattr this

Readme Contents

# Installation
npm install -g pm2
# Usage/Features
$ npm install pm2 -g     # Install pm2 command line globally
$ pm2 start app.js -i 4  # Daemonize pm2 and Start 4 clustered instances of app.js
                         # You can also pass the 'max' params to start 
                         # the right numbers of processes depending of CPUs
$ pm2 list               # Display all processes status
$ pm2 monit              # Monitor all processes
$ pm2 logs               # Display all processes logs in streaming
$ pm2 dump               # Dump the states of all processes
$ pm2 stop pm2_id        # Stop specific process id
$ pm2 stopAll            # Stop all processes
$ pm2 resurrect          # Put online previously dumped processes
$ pm2 reload all         # Hot Reload all processes with 0s downtime (only for HTTP)
$ pm2 restart pm2_id     # Restart specific process
$ pm2 restart all        # Hard Restart all proccesses
$ pm2 stop all           # Stop all processes
$ pm2 generate app       # Generate a JSON process configuration
$ pm2 startup            # Generate init script to keep processes alive
$ pm2 web                # Health computer API endpoint (http://localhost:9615)
## Different ways to launch a process
$ pm2 start app.js -i max  # Will start maximum processes depending on CPU availables
$ pm2 start app.js -i 3    # Will start 3 processes
$ pm2 start app.js --name serverone # Start a process an name it as server one
                                    # you can now stop the process by doing
                                    # pm2 stop serverone
$ pm2 start app.json       # Start processes with options declared in app.json
                           # Go to chapter Multi process JSON declaration for more
                           
$ pm2 start app.js -c "* * * * * *" # Will restart the process depending on the
                                    # cron pattern. Here it will restart the process
                                    # every second

$ pm2 start app.js -i max -- -a 23  # Pass arguments after -- to app.js
$ pm2 start app.js -i max -e err.log -o out.log -w  # Will start and generate a configuration file
## Is my production server ready for PM2 ?

Just try the tests before using PM2 on your production server

$ git clone https://github.com/Unitech/pm2.git
$ cd pm2
$ npm install  # Or do npm install --dev if devDependencies are not installed
$ npm test

If a test is broken please report us issues here

## Hot code reload (0s downtime)

This feature permits to reload code without loosing current processed queries. ONLY FOR NETWORKED APPLICATIONS

$ pm2 reload all

Thanks to TruongSinh Tran-Nguyen https://github.com/truongsinh

## CoffeeScript
$ pm2 start my_app.coffee

That's all !

## Updating pm2 and resurecting process
$ pm2 dump
$ npm install -g pm2@latest
$ pm2 kill ; pm2 resurect
npm install git://github.com/Unitech/pm2.git -g
## pm2 list

List infos about all processes managed by pm2. It shows also how many times a process has been restarted because of an unhandled exception.

Monit

## pm2 monit

Monitor CPU and memory usage of every node process (and also clustered processes) managed by pm2.

Monit

## pm2 automatic startup script generation

PM2 provides an automatic way to keep Node processes alive. It uses an init script (compatible with most Linux systems).

$ pm2 startup

Now you can reboot your server, and already launched processes should be kepts alive ;)

## pm2 logs

Display logs in streaming of all processes, without having to do a tail -f or something else. You can also pass [name|id] as parameter to stream only the log of a specified process.

Monit

## pm2 dump/resurrect

You can dump all currently running processes, including their environment and execution path. After restarting or stopping PM2 you can resurrect them.

Monit

## pm2 cron restart

The -c "cron_pattern" option permits to hard restart a process scheduled on the cron pattern. Look at test/cli.sh for examples.

## pm2 health web api endpoint

PM2 can disserve an API endpoint to monitor processes and computer health (cpu usage, memory, network interfaces...)

pm2 web
# Multi process JSON declaration

processes.json :

[{
  "name"      : "echo",
  "script"    : "./examples/args.js",
  "instances" : "1",
  "args"      : "['--toto=heya coco', '-d', '1']",
  "cron_restart" : "* * * * * *"
},{
    "name"      : "api",
    "script"    : "./examples/child.js",
    "instances" : "4",
    "fileError" : "./examples/child-err.log",
    "fileOutput" : "./examples/child-out.log"
},{
  "min_uptime" : "100",
  "max_restarts" : "400",
  "name" : "auto-kill",
  "script" : "./examples/killfast.js"
}]

Then with the cli :

$ pm2 start processes.json
  • "min_uptime": if a process is restarted with an uptime smaller than this value, this restart counts as an unstable restart. If this option is not specified, all restarts are considered unstable.

  • "max_restarts": if the number of unstable restarts exceeds this number, the process will be stopped and a message with number with restarts will be logged.

# Test
npm test

Features

  • Clusterize your Node networked script without adding one line of code
  • Fully tested
  • Monitor process/cluster processes health (status, memory, cpu usage, restarted time) via CLI (htop like)
  • Monitor server health (processes, cpu core...) via JSON api (pm2 web)
  • Launch multiple applications via JSON
  • Forever keep alive processes
  • Log streaming in realtime (pm2 logs)
  • Log uncaught exceptions in error logs
  • Track restarted time
  • Auto stop processes who exit too fast
  • Dump current processes and resurrect (upstart)

Next Features/Ideas

  • Remote administration/status checking
  • Builtin Inter process communication channel (message bus)
  • Auto start of the script at start (upstart)
  • V8 GC memory leak detection
  • Web interface
  • Keeping monitoring data
  • Integrated wrk utils endpoint benchmark

Install a process (draft, not implemented)

You can install processes and communicate with them

$ m2 install web-pm2
$ m2 list
$ m2 start web-pm2
$ m2 info web-pm2  # list 
  • Add homogen communication channel (pubsub/eventemitter2 - wildcard events) (axon pub/sub-message.js)

Sponsors

Thanks to Devo.ps and Wiredcraft for their knowledge and expertise.

# License - Apache License v2

Copyright [2013] [Strzelewicz Alexandre [email protected]]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

pm2's People

Contributors

brentropy avatar jhurliman avatar joshskidmore avatar jvtrigueros avatar markkevans avatar nathanpeck avatar rlidwka avatar sciolist avatar truongsinh avatar unitech avatar yyx990803 avatar

Watchers

 avatar  avatar  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.