pot-js v0.0.0-beta.51
pot-js
Process management module

Table of Contents
Motivation
forever and pm2 are great third-party process management tools, but they are not module friendly. Saying if you are writing a CLI service tool, you may need to built-in a process management module for handling process monitor, run as a daemon, stop, scale, reload, and then you could just focus on developing your service logic. So I created this module.
Features
- Automatically restart process if it crashes. Like forever
- Able to scale or reload instances with zero down time. Like pm2
- Provides both CLI and Node.js module API
- Supports isolated workspaces
- User friendly interactive CLI
- Easy to extend
- Built-in powerful logger system
Installing
$ npm install pot-jsFor global CLI command, please add -g option
$ npm install -g pot-jsCLI Reference
pot <command> [options]
Commands:
pot start [entry] Spawn and monitor a process
pot restart [name] Restart a process
pot restartall Restart all processes
pot reload [name] Reload a process
pot reloadall Reload all processes
pot stop [name] Stop a process
pot stopall Stop all processes
pot scale [name] [instances] Scale up/down a process
pot list List processes [aliases: ls]
pot log [name] [category] Show log
pot show [name] Show process information
pot flush [name] Remove log files
pot flushall Remove all log files
Options:
--version Show version number [boolean]
-h, --help Show help [boolean]Node.js module API Reference
exec(options)
Spawn and monitor a process.
Options
args(String|String[]): List of string arguments. Defaults to[].baseDir(String): The base directory for resolving modules or directories. Defaults to thecurrent working directory.cluster(Boolean): Enforce using cluster mode. If not set, it will automatically set totruewhen spawning a Node.js related process.config(String): Path to the config file. Defaults to.potrc.cwd(String): Current working directory. Defaults toprocess.cwd().daemon(Boolean): Run as a daemon. Defaults tofalse.entry(String): Entry script path. Defaults to./index.js.env(Object): Environment variables object. Defaults toprocess.env.events(Object): Defining scripts by event hooks. Likescriptsinpackage.json. Here are available event hooks:spawn: New child process has been spawnedstart: The monitor has startedstop: The monitor has fully stopped and the process is killedcrash: The monitor has crashed (too many restarts or spawn error)sleep: The monitor is sleepingexit: Child process has exitedstdout: Child process stdout has emitted datastderr: Child process stderr has emitted datawarn: Child process has emitted an error
execArgs(String|String[]): Execution arguments. Defaults to[].execPath(String): Execution Path. Defaults toprocess.execPath, which returns the absolute pathname of the executable that started the Node.js process. i.e./usr/local/bin/node.force(Boolean): Enforce restart even if the process is exists. Defaults tofalse.inspect(Boolean|String|Object): Enable node inspector. Require Node.js >= v6.3.0. Defaults tofalse.instances(Number): Cluster instances. Defaults to1.logLevel(String|Object): Log level. See pot-logger for detail. Here are available levels:- ALL
- TRACE
- DEBUG (default in
developmentmode) - INFO (default in
productionmode) - WARN
- ERROR
- FATAL
- OFF
logsDir(String): Log files directory. Indaemonmode, log messages will write to some.logfiles.maxRestarts(Number): How many restarts are allowed within 60s.monitorProcessTitle(String): Monitor process title. Defaults to "node".name(String): Process monitor name. Should be unique. Defaults to the basename ofbaseDir.production(Boolean): Production mode. Short hand for setting NODE_ENV="production" env. Defaults totrue.watch(Boolean|Object): Enable watch mode. Defaults tofalse. Here are available props for object config:enable(Boolean): Enablewatch. Defaults totrue.dirs(String|String[]): Defining watching directories.ignoreDotFiles(Boolean): Ignore watching.*files. Defaults totrue.ignoreNodeModulesDir(Boolean): Ignore watchingnode_modulesdirectory. Defaults totrue.
workspace(String): Workspace.
Connection
API to communicate with monitors
(TODO)
Connection.getNames(options)Connection.getByName(name, options)Connection.getState(name, options)Connection.getAllInstances(options)Connection.flushOffline()connection#getState(instanceId)connection#restart()connection#reload(options)connection#scale(number)connection#flush()connection#disconnect()connection#requestStopServer(options)
Operators
Command lines interface helper functions
(TODO)
Operators.start(options)Operators.restart(options)Operators.restartAll(options)Operators.reload(options)Operators.reloadAll(options)Operators.stop(options)Operators.stopAll(options)Operators.scale(options)Operators.list(options)Operators.show(options)Operators.log(options)Operators.flush(options)Operators.flushAll(options)
Schemas
Config and CLI json schemas
(TODO)
Commands
pot-js commands descriptor. Useful to extend or modify command via createCli()
A command may contain these props:
command(String): A string representing the command. eg:stop [name]description(String): Command descriptionschema(Object): The JSON schema of options and positional argumentsoperator(Function): The operator function of the command
(TODO)
createCli(pkg, commands)
A helper function to create CLI, built on top of yargs
(TODO)
License
MIT
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago