Giter VIP home page Giter VIP logo

processhost's Introduction

processhost

Super simple, cross-platform process hosting for Node, adapted from [Anvil]'s(https://github.com/anviljs/anvil.js) processhost.

The most useful features are:

  • Reliably kills child processes on process exit
  • Reliably restarts child processes
  • Apply a tolerance to restart behavior

API

var processes = require( "processhost" )();

configuration

Configuration hash has the following options. Only command and args are required.

{
	command: "", // this will probably be "node"
	args: [], // the command line args for the process, i.e. your script
	[cwd]: "", // defaults to current working directory
	[killSignal]: "" | [ "" ], // not required, defaults to "SIGTERM", can provide an array
	[stdio]: "inherit" | "ignore" | "pipe" // determines if the process will write to the console
	[env]: {}, // defaults to the process.env, should be simple hash
	[restart]: true, // control whether or not the process restarts after a start or restart call
	[restartLimit]: 1, // number of allowed restarts
	[restartWindow]: 100 // duration (in ms) of tolerance window
}

Notes

  1. restartWindow defaults to undefined - this results in limitless restarts
  1. stdio defaults to "inherit" causing child processes to share the parents stdio/stderr

create( processAlias, configuration )

Creates a new process without starting it.

processes.create( "myProcess", { command: "node", args: [ "./index.js" ], cwd: "./src" } );

restart( [processAlias] )

If a processAlias is provided, only starts|restarts the matching process. Otherwise, this will start|restart ALL processes that have been defined.

processes.restart(); // restart all

processes.restart( 'myApp' ); // restart only 'myApp'

setup( processesHash )

Used to define and potentially start multiple processes in a single call.

processes.setup( {
	"one": { ... },
	"two": { ... },
	"three": { ... }
} );

Note

To have the processes started automatically, add a start: true to the config block.

start( processAlias, [configuration] )

If no configuration is provided, this will start|restart the matching process. If a configuration is provided, this will create and start a new process.

processes.start( "myProcess", { command: "node", args: [ "./index.js" ], cwd: "./src" } );

stop( [processAlias] )

If no processAlias is provided, stops all running processes, otherwise it stops the specified process if it exists and is running.

processes.stop();

Events

You can subscribe to the following process level events off the process host.

  • [processAlias].crashed - the process has exited unexpectedly
  • [processAlias].failed - the process has exceeded the set tolerance
  • [processAlias].restarting - the process is restarting
  • [processAlias].started - the process has started
  • [processAlias].stderr
  • [processAlias].stdout
  • [processAlias].stopped - the process has exited after stop was called

Note

The stderr and stdout events will not fire unless you set stdio to "pipe" in the config hash.

processhost's People

Contributors

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