### Vhost Example Source: https://github.com/learnboost/cluster/blob/master/History.md Includes an example demonstrating the usage of virtual hosts (vhosts) within the cluster. ```javascript // Vhost example code goes here ``` -------------------------------- ### Add vhost example Source: https://github.com/learnboost/cluster/blob/master/History.md Includes an example demonstrating the usage of virtual hosts (vhosts). This addition helps users understand how to configure and use vhosts within the cluster. ```javascript /* Added vhost example. Closes #144 */ ``` -------------------------------- ### Cluster Server Setup with Plugins Source: https://github.com/learnboost/cluster/blob/master/Readme.md Configures and starts a Node.js application using the Cluster module, integrating various plugins for logging, statistics, PID files, CLI, and REPL. ```javascript var cluster = require('cluster') , app = require('./app'); cluster(app) .use(cluster.logger('logs')) .use(cluster.stats()) .use(cluster.pidfiles('pids')) .use(cluster.cli()) .use(cluster.repl(8888)) .listen(3000); ``` -------------------------------- ### Install Cluster Source: https://github.com/learnboost/cluster/blob/master/Readme.md Installs the Cluster module using npm. ```bash $ npm install cluster ``` -------------------------------- ### Cluster Setup by Exporting Server Instance Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Illustrates an alternative and recommended method where the server instance is exported from a module and then passed as a path to the cluster function. ```javascript cluster('app') .listen(3000); ``` -------------------------------- ### Basic Cluster Setup with HTTP Server Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Demonstrates the fundamental usage of the Cluster API by passing an HTTP server instance to the cluster function and then calling listen. ```javascript var cluster = require('../') , http = require('http'); var server = http.createServer(function(req, res){ res.writeHead(200); res.end('Hello World'); }); cluster(server) .listen(3000); ``` -------------------------------- ### TCP Echo Server Example Source: https://github.com/learnboost/cluster/blob/master/History.md Provides an example of a TCP echo server implemented using the cluster module. ```javascript // TCP echo server example code goes here ``` -------------------------------- ### Running Tests Source: https://github.com/learnboost/cluster/blob/master/Readme.md Commands to install development dependencies and run tests for the Cluster project. ```bash $ npm install $ make test ``` -------------------------------- ### Cluster Usage Example Source: https://github.com/learnboost/cluster/blob/master/docs/debug.md Demonstrates how to initialize and use the cluster module, including enabling debug output and listening on a specific port. ```javascript cluster(server) .use(cluster.debug()) .listen(3000); ``` -------------------------------- ### Start Telnet Session Source: https://github.com/learnboost/cluster/blob/master/docs/repl.md Initiates a telnet session to the REPL socket for interactive administration. ```shell $ telnet /var/run/cluster.sock ``` -------------------------------- ### Cluster Server Setup with CLI Source: https://github.com/learnboost/cluster/blob/master/docs/cli.md Demonstrates how to set up a cluster server using the pidfiles and cli plugins. This configuration allows the server script to act as both the master and the CLI interface. ```javascript var cluster = require('cluster'); cluster(server) .use(cluster.pidfiles()) .use(cluster.cli()) .listen(3000); ``` -------------------------------- ### Cluster Server Setup (Alternative Path) Source: https://github.com/learnboost/cluster/blob/master/Readme.md An alternative way to set up the Cluster server, passing the application path directly. This is recommended to prevent unnecessary database connections in the master process. ```javascript var cluster = require('cluster'); cluster('./app') .use(cluster.logger('logs')) .use(cluster.stats()) .use(cluster.pidfiles('pids')) .use(cluster.cli()) .use(cluster.repl(8888)) .listen(3000); ``` -------------------------------- ### Basic HTTP Server Example Source: https://github.com/learnboost/cluster/blob/master/Readme.md A simple Node.js HTTP server that logs requests and responds with 'Hello World'. This serves as the application to be managed by Cluster. ```javascript var http = require('http'); module.exports = http.createServer(function(req, res){ console.log('%s %s', req.method, req.url); var body = 'Hello World'; res.writeHead(200, { 'Content-Length': body.length }); res.end(body); }); ``` -------------------------------- ### Fix "listening" event by deferring "start" Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects the behavior of the "listening" event by deferring the "start" action. This ensures that the event is emitted correctly after the server has fully started. ```javascript /* Fixed "listening" event by deferring "start" */ ``` -------------------------------- ### Using Custom Plugins with Cluster Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Explains how to integrate custom plugins into the cluster setup by passing a plugin function to the use() method. ```javascript function myPlugin(path){ return function(master) { // do stuff } } cluster(server) .use(myPlugin('/some/path')) .listen(3000); ``` -------------------------------- ### Stats Output with Connection and Request Statistics Source: https://github.com/learnboost/cluster/blob/master/docs/stats.md Example output from the `stats()` REPL command when both connection and request statistics are enabled, including total requests and per-worker activity. ```text Workers connections total: 60 connections active: 0 requests total: 24064 0: 15 seconds 0|4|3358 1: 15 seconds 0|1|1126 2: 15 seconds 0|25|9613 3: 15 seconds 0|30|9967 ``` -------------------------------- ### Stats Output with Connection Statistics Source: https://github.com/learnboost/cluster/blob/master/docs/stats.md Example output from the `stats()` REPL command when connection statistics are enabled, showing total connections, active connections, and per-worker connection details. ```text Workers connections total: 60 connections active: 0 0: 15 seconds 0|4 1: 15 seconds 0|1 2: 15 seconds 0|25 3: 15 seconds 0|30 ``` -------------------------------- ### Abstract Clusters for Job Queues Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Shows a minimalist example of using cluster to manage non-server processes, such as job queues, by invoking cluster() without arguments. ```javascript var cluster = require('cluster'); var proc = cluster().start(); if (proc.isWorker) { // do things within the worker processes } else { // do something within the master } ``` -------------------------------- ### Cluster Reload Plugin Usage Source: https://github.com/learnboost/cluster/blob/master/docs/reload.md Demonstrates how to use the cluster reload plugin to watch for file changes and restart the server. It shows examples for watching the current directory, a specific directory, multiple paths, and with custom options like signal and file extensions. ```javascript cluster(server) .use(cluster.reload()) .listen(3000); ``` ```javascript cluster(server) .use(cluster.reload('lib')) .listen(3000); ``` ```javascript cluster(server) .use(cluster.reload(['lib', 'tests', 'index.js'])) .listen(3000); ``` ```javascript cluster(server) .use(cluster.reload('lib', { signal: 'SIGQUIT' })) .listen(3000); ``` ```javascript cluster(server) .use(cluster.reload('lib', { extensions: ['.js', '.coffee'] })) .listen(3000); ``` -------------------------------- ### pids() - Get Process IDs Source: https://github.com/learnboost/cluster/blob/master/docs/repl.md Outputs the process IDs of the master process and all worker processes. ```APIDOC pids() Outputs the master / worker process ids. Example: pids master: 1799 worker #0: 1801 worker #1: 1802 ``` -------------------------------- ### Checking if Script is a Worker Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Provides an example of how to determine if the current script is running as a worker process using the isWorker property. ```javascript cluster = cluster(server).listen(3000); if (cluster.isWorker) { // do something } ``` -------------------------------- ### Launching the Server and Using CLI Commands Source: https://github.com/learnboost/cluster/blob/master/docs/cli.md Shows how to launch the cluster server in the background and then use the CLI commands to interact with the cluster, such as checking status or restarting workers. ```bash $ nohup node server.js & $ node server.js status $ node server.js restart $ node server.js shutdown $ node server.js --help ``` -------------------------------- ### Basic Cluster Usage with Stats and REPL Source: https://github.com/learnboost/cluster/blob/master/docs/stats.md Demonstrates how to initialize a cluster server and enable both the stats and REPL plugins. The REPL is accessible via telnet. ```javascript cluster(server) .use(cluster.stats()) .use(cluster.repl(8888)) .listen(3000); ``` -------------------------------- ### Launch REPL with Socket Source: https://github.com/learnboost/cluster/blob/master/docs/repl.md Launches the REPL with a local Unix domain socket for remote administration. ```javascript var cluster = require('../'); var server = http.createServer(function(req, res) { var body = 'Hello World'; res.writeHead(200, { 'Content-Length': body.length }); res.end(body); }); cluster(server) .use(cluster.repl('/var/run/cluster.sock')) .listen(3000); ``` -------------------------------- ### REPL Commands Source: https://github.com/learnboost/cluster/blob/master/docs/repl.md Lists available commands for the Cluster REPL, including help, worker management, and server control. ```APIDOC REPL Commands: help(): Display help information spawn(n): Spawn one or more additional workers. If n is omitted, spawns one worker. pids(): Output master and worker process IDs. kill(id, signal): Send signal or SIGTERM to the given worker ID. SIGQUIT can be used for graceful termination. shutdown(): Gracefully shutdown the server. stop(): Hard shutdown the server. restart(): Gracefully restart all workers. echo(msg): Echo the given message to the REPL client. stats(): Display server statistics. ``` -------------------------------- ### Launch REPL with Port Source: https://github.com/learnboost/cluster/blob/master/docs/repl.md Launches the REPL listening on a specified network port, allowing remote connections. ```javascript var cluster = require('../'); var http = require('http'); var server = http.createServer(function(req, res) { var body = 'Hello World'; res.writeHead(200, { 'Content-Length': body.length }); res.end(body); }); cluster(server) .use(cluster.repl(8888)) .listen(3000); ``` -------------------------------- ### Expose utils for plugins Source: https://github.com/learnboost/cluster/blob/master/History.md Makes utility functions available for use by plugins. This provides plugins with helpful tools for extending the cluster's functionality. ```javascript /* Added; expose utils, helpful for plugins */ ``` -------------------------------- ### Configuring Cluster Settings Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Shows how to apply various settings to the cluster instance using the set(option, value) method to customize worker count, directories, and timeouts. ```javascript cluster(server) .set('working directory', '/') .set('workers', 5) .listen(3000); ``` -------------------------------- ### Master PreventDefault Support Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces `Master#preventDefault` to allow plugins to prevent the master process from its default behavior, such as listening for connections. ```javascript master.preventDefault(); ``` -------------------------------- ### Add spawn(-n, signal) support Source: https://github.com/learnboost/cluster/blob/master/History.md Adds support for the `spawn()` method with two arguments: a count `-n` and a `signal`. The signal defaults to __SIGQUIT__. ```javascript /* Added `spawn(-n, signal)` support defaulting to __SIGQUIT__ */ ``` -------------------------------- ### Pidfiles Helper Source: https://github.com/learnboost/cluster/blob/master/History.md Provides a `pidfiles()` helper function for managing process ID files, specifically `master.pidof(name)`. ```javascript const pid = master.pidof('my_process'); ``` -------------------------------- ### Enabling Request and Connection Statistics Source: https://github.com/learnboost/cluster/blob/master/docs/stats.md Demonstrates enabling both connection and request statistics by passing multiple options to the stats plugin. This provides a comprehensive view of server activity, including total requests. ```javascript cluster.use(cluster.stats({ connections: true, requests: true })) ``` -------------------------------- ### Using Bundled Plugins with Cluster Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Demonstrates how to use plugins bundled with the Cluster library, such as the logger plugin, by accessing them from the cluster object. ```javascript cluster(server) .use(cluster.logger()) .listen(3000); ``` -------------------------------- ### Master Spawning Strategy Source: https://github.com/learnboost/cluster/blob/master/History.md Implements a master spawning strategy where a new master is spawned to accept connections during restarts, allowing the old master to finish gracefully. ```javascript // Master spawning strategy implementation ``` -------------------------------- ### Add stand-alone restart test Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces a test case for the stand-alone restart functionality. This verifies that restarting in standalone mode works correctly. ```javascript /* Added stand-alone restart test */ ``` -------------------------------- ### Environment Based Usage with in() Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces the `Master#in()` method for environment-specific configurations, allowing different behaviors based on the environment (e.g., 'development', 'production'). ```javascript cluster(server) .in('development') .use(cluster.debug()) .use(cluster.repl()) .listen(3000) .in('production') .use(cluster.logger()) .listen(80); ``` -------------------------------- ### Fix logger() / pidfiles() errors with mkdirp Source: https://github.com/learnboost/cluster/blob/master/History.md Addresses errors in logger() and pidfiles() when the directory does not exist, now utilizing mkdirp. This ensures that necessary directories are created automatically. ```javascript /* Fixed `logger()` / `pidfiles()` errors when dir does not exist, now using * mkdirp. Closes #783 */ ``` -------------------------------- ### Stats REPL Command Source: https://github.com/learnboost/cluster/blob/master/docs/stats.md Shows the command to execute within the REPL to display detailed statistics about the master process, system resources, and individual workers. ```javascript cluster> stats() ``` -------------------------------- ### Configure Logger with Default Path and Level Source: https://github.com/learnboost/cluster/blob/master/docs/logger.md This snippet demonstrates how to use the logger plugin with its default settings, outputting logs to the default path and using the default log level. ```javascript cluster(server) .use(cluster.logger()) .listen(3000); ``` -------------------------------- ### Add connections option to stats() plugin Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces the `connections` option to the `stats()` plugin. This option reports connection and disconnection events, displaying them in the REPL. ```javascript /* Added `connections` option to `stats()` plugin. Reports connections and disconnections, displaying in the REPL. */ ``` -------------------------------- ### Add spawn(-n) support Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces support for the `spawn()` method with a single argument `-n`, specifying the number of workers to spawn. ```javascript /* Added `spawn(-n)` support. Closes #46 */ ``` -------------------------------- ### Listen Host DNS Resolution Source: https://github.com/learnboost/cluster/blob/master/History.md Enables DNS resolution for the host when using the `listen()` function, allowing for more flexible network configurations. ```javascript cluster.listen(port, 'hostname.example.com'); ``` -------------------------------- ### Add simple stand-alone test Source: https://github.com/learnboost/cluster/blob/master/History.md Includes a basic test case for the stand-alone mode. This provides a fundamental check for standalone operation. ```javascript /* Added simple stand-alone test */ ``` -------------------------------- ### Cluster Filename Support Source: https://github.com/learnboost/cluster/blob/master/History.md Adds support for the `cluster(filename)` configuration, which was previously a bug. This feature is highly recommended for advanced usage. ```javascript cluster(filename); ``` -------------------------------- ### spawn() - Spawn Worker Source: https://github.com/learnboost/cluster/blob/master/docs/repl.md Spawns a single additional worker process. Use spawn(n) to spawn multiple workers. ```APIDOC spawn([n]) Spawn one or more additional workers. Parameters: n: (Optional) The number of workers to spawn. Example: spawn() // Spawns 1 worker spawn(4) // Spawns 4 workers ``` -------------------------------- ### Cluster CLI Plugin API Documentation Source: https://github.com/learnboost/cluster/blob/master/docs/cli.md Provides API documentation for defining custom commands within the Cluster CLI plugin. It details the `define` method for adding new command-line flags and their associated callback functions. ```APIDOC cluster.cli.define(flags, callback, description) - Defines a new command-line flag and its behavior. - Parameters: - flags: A string or array of strings representing the command-line flags (e.g., '-h, --help, help'). - callback: A function that will be executed when the command is invoked. It typically receives the master process object as an argument. - description: A string describing the command's purpose, used in the --help output. - Example: var cli = require('cluster').cli; cli.define('-h, --help, help', function(master){ console.log('\n Usage: node \n'); commands.forEach(function(command){ console.log(' ' + command.flags.join(', ') + '\n ' + '\033[90m' + command.desc + '\033[0m' + '\n'); }); console.log(); process.exit(); }, 'Show help information'); - Related Commands: - cluster.cli.define() can be used multiple times to add various commands. ``` -------------------------------- ### Enabling Connection Statistics Source: https://github.com/learnboost/cluster/blob/master/docs/stats.md Illustrates how to configure the stats plugin to collect connection statistics by passing the `connections: true` option. This enables the display of total and active connections, as well as per-worker connection counts. ```javascript cluster.use(cluster.stats({ connections: true })) ``` -------------------------------- ### Cluster API Reference Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Provides a reference for the core Cluster API methods and properties, including listen, set, use, isWorker, isMaster, and state. ```APIDOC Cluster API: cluster(server | path | null) Initializes the cluster module. Can accept a server instance, a path to a module exporting a server, or null to manage abstract processes. .listen(port, [callback]) Starts the cluster and makes the server listen on the specified port. .set(option, value) Sets a configuration option for the cluster. Available options include: - workers: Number of workers to spawn (defaults to CPU count). - working directory: Working directory for workers. - backlog: Connection backlog. - socket port: Master socket port. - timeout: Worker shutdown timeout. - title: Master process title. - worker title: Worker process title. - user: User ID/name for workers. - group: Group ID/name for workers. .use(plugin) Registers a plugin function to extend cluster functionality. Master Properties: - state: Current state of the master process ('active', 'hard shutdown', 'graceful shutdown'). - isWorker: Boolean, true if the script is a worker. - isMaster: Boolean, true if the script is the master. Events: - start: IPC server is prepped. - worker: A worker is spawned. - listening: Server is listening. - closing: Master is shutting down. - close: Master has shut down. - worker killed: A worker has died. - worker exception: Worker uncaught exception. - kill: Signal being sent to workers. - restarting: Restart requested. - restart: Restart complete. Signals: - SIGINT: Hard shutdown. - SIGTERM: Hard shutdown. - SIGQUIT: Graceful shutdown. - SIGUSR2: Restart workers. ``` -------------------------------- ### Master do() Method Source: https://github.com/learnboost/cluster/blob/master/History.md Adds the `Master#do()` method for executing specific tasks within the master process. ```javascript master.do('someTask'); ``` -------------------------------- ### Add support to run cluster without a server Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces the capability to run the cluster in a standalone mode without requiring an active server. This expands the flexibility of the cluster. ```javascript /* Added support to run cluster without a server. Closes #72 */ ``` -------------------------------- ### Change postpone spawning until "listening" Source: https://github.com/learnboost/cluster/blob/master/History.md Defers the spawning of new processes until the "listening" event occurs. This change aims to resolve an EINVAL issue by ensuring proper initialization before spawning. ```javascript /* Changed; postpone spawning until "listening" this _should_ fix our EINVAL issue */ ``` -------------------------------- ### Add title and worker title settings Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces `title` and `worker title` settings. These settings allow customization of the process titles for the master and worker processes. ```javascript /* Added `title` and `worker title` settings. Closes #54 */ ``` -------------------------------- ### REPL Shutdown and Stop Functions Source: https://github.com/learnboost/cluster/blob/master/History.md Adds `shutdown()` and `stop()` functions to the REPL (Read-Eval-Print Loop) for controlling the cluster process. ```javascript repl.shutdown(); repl.stop(); ``` -------------------------------- ### Fix Master#listen() with env specific config Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects the behavior of Master#listen() when using environment-specific configurations. This ensures that listening is configured correctly based on the environment. ```javascript /* Fixed `Master#listen()` with env specific config. Closes #98 */ ``` -------------------------------- ### Configure Logger with Custom Path Source: https://github.com/learnboost/cluster/blob/master/docs/logger.md This snippet shows how to specify a custom directory for log files using the logger plugin. Logs will be written to the specified path. ```javascript cluster(server) .use(cluster.logger('tmp/logs')) .listen(3000); ``` -------------------------------- ### Fix stand-alone support with file path Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects the stand-alone support when a file path is provided. This ensures that the cluster can be run correctly in standalone mode with file path configurations. ```javascript /* Fixed stand-alone support with a file path. Closes #141 [reported by SebastianEdwards] */ ``` -------------------------------- ### restart() - Restart Workers Source: https://github.com/learnboost/cluster/blob/master/docs/repl.md Gracefully restarts all worker processes. ```APIDOC restart() Gracefully restart all workers. ``` -------------------------------- ### Fix user / group options Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects issues with the `user` and `group` configuration options. This ensures that user and group settings are applied correctly. ```javascript /* Fixed `user` / `group` options. Closes #60 */ ``` -------------------------------- ### Cluster Debug Output Source: https://github.com/learnboost/cluster/blob/master/docs/debug.md This section shows the typical verbose debugging information output to stderr during the lifecycle of a cluster, including startup, worker connections, and shutdown events. ```log info - master started info - worker 0 spawned info - worker 1 spawned info - worker 2 spawned info - worker 3 spawned info - worker 2 connected info - worker 0 connected info - worker 3 connected info - worker 1 connected info - listening for connections ^C info - shutting down warning - kill(SIGKILL) info - shutdown complete warning - worker 2 died warning - worker 0 died warning - worker 3 died ``` -------------------------------- ### Fix repl() bug Source: https://github.com/learnboost/cluster/blob/master/History.md Ensures the server exists before closing it in the repl() function. This addresses a specific bug related to server existence checks. ```javascript /* Fixed `repl()` bug: ensure server exists before closing it */ ``` -------------------------------- ### Add support for plugins to work within workers Source: https://github.com/learnboost/cluster/blob/master/History.md Enables plugins to function correctly within worker processes. This expands the capabilities of plugins by allowing them to operate in different process contexts. ```javascript /* Added support for plugins to work within workers. Closes #27 */ ``` -------------------------------- ### Log Dependency in package.json Source: https://github.com/learnboost/cluster/blob/master/History.md Specifies the 'log' module as a dependency in the `package.json` file. ```json { "dependencies": { "log": "*" } } ``` -------------------------------- ### Default Master#spawn() and Master#remove() to 1 Source: https://github.com/learnboost/cluster/blob/master/History.md Sets the default value for `Master#spawn()` and `Master#remove()` to 1. This simplifies their usage by providing a default count. ```javascript /* Added; default both `Master#spawn()` and `Master#remove()` to 1 */ ``` -------------------------------- ### Add support for changing watched file extensions Source: https://github.com/learnboost/cluster/blob/master/History.md Enables support for dynamically changing the file extensions that the cluster watches for reloads. This provides flexibility in configuring watched files. ```javascript /* Added support for changing watched file extensions [EirĂ­kur Nilsson] */ ``` -------------------------------- ### Remove 0.2.x compatibility Source: https://github.com/learnboost/cluster/blob/master/History.md Discontinues compatibility with Node.js 0.2.x. This simplifies the codebase and focuses on newer Node.js versions. ```javascript /* Removed 0.2.x compatibility */ ``` -------------------------------- ### Fix cli() plugin Source: https://github.com/learnboost/cluster/blob/master/History.md Addresses an issue with the cli() plugin, resolving a reported problem. This fix enhances the functionality and stability of the CLI plugin. ```javascript /* Fixed `cli()` plugin. Closes #145 [reported by alefnula] */ ``` -------------------------------- ### Save PID Files Source: https://github.com/learnboost/cluster/blob/master/docs/pidfiles.md Saves PID files to a specified directory. If no path is provided, it defaults to './pids'. This plugin is used within the cluster configuration. ```javascript cluster(server) .use(cluster.pidfiles()) .listen(3000); ``` ```javascript cluster(server) .use(cluster.pidfiles('/var/run/node')) .listen(3000); ``` -------------------------------- ### Restarts Statistics Source: https://github.com/learnboost/cluster/blob/master/History.md Adds functionality to track and display statistics related to process restarts. ```javascript cluster.getRestartStats(); ``` -------------------------------- ### Expose child Worker instance .worker Source: https://github.com/learnboost/cluster/blob/master/History.md Makes the child Worker instance accessible via the .worker property. This allows for direct interaction with worker instances. ```javascript /* Expose child `Worker` instance `.worker` */ ``` -------------------------------- ### Add support for calling master method from worker Source: https://github.com/learnboost/cluster/blob/master/History.md Enables the ability to call any master method directly from a worker process. This enhances inter-process communication and control. ```javascript /* Added support for calling any master method from a worker [felixge] */ ``` -------------------------------- ### Remove remaining 2.x support Source: https://github.com/learnboost/cluster/blob/master/History.md Eliminates all remaining support for Node.js 2.x. This change focuses the project on newer Node.js versions. ```javascript /* Removed remaining 2.x support. Closes #108 */ ``` -------------------------------- ### Cluster PID File Management Source: https://github.com/learnboost/cluster/blob/master/docs/pidfiles.md Provides API methods for managing PID files within the cluster. Includes accessing the PID directory and retrieving PIDs by name. ```APIDOC master.pidfiles Description: The directory where PID files are saved. master.pidof(name) Description: Returns the process ID (PID) for a given name. Parameters: name: The name of the process (e.g., 'master', 'worker.0'). Returns: The PID as a number. Example: master.pidof('master') // => 5978 master.pidof('worker.0') // => 5979 ``` -------------------------------- ### Maintaining Worker Count on SIGCHLD Source: https://github.com/learnboost/cluster/blob/master/History.md Ensures the worker count is maintained correctly upon receiving the `__SIGCHLD__` signal. ```javascript process.on('SIGCHLD', () => { // Maintain worker count }); ``` -------------------------------- ### kill(id, [signal]) - Kill Worker Source: https://github.com/learnboost/cluster/blob/master/docs/repl.md Sends a signal to a specific worker process. Defaults to SIGTERM if no signal is provided. ```APIDOC kill(id[, signal]) Kill worker `id` with the given `signal` or __SIGTERM__. Parameters: id: The ID of the worker to kill. signal: (Optional) The signal to send (e.g., 'SIGTERM', 'SIGQUIT'). Defaults to 'SIGTERM'. Example: kill(2) kill(3, 'SIGQUIT') ``` -------------------------------- ### Worker Management and Shutdown Source: https://github.com/learnboost/cluster/blob/master/docs/api.md API methods for managing worker processes, including spawning, graceful shutdown, hard shutdown, and restarting. ```APIDOC Master#spawn(n) Spawn `n` additional workers. Master#close() Graceful shutdown, waits for all workers to reply before exiting. Master#destroy() Hard shutdown, immediately kill all workers. Master#restart([signal]) Defaults to a graceful restart, spawning a new master process, and sending __SIGQUIT__ to the previous master process. Alternatively a custom `signal` may be passed. Master#kill([signal]) Sends __SIGTERM__ or `signal` to all worker processes. This method is used by `Master#restart()`, `Master#close()` etc. ``` -------------------------------- ### Add requests option to stats() plugin Source: https://github.com/learnboost/cluster/blob/master/History.md Adds the `requests` option to the `stats()` plugin. This option reports request statistics, displaying them in the REPL. ```javascript /* Added `requests` option to `stats()` plugin. Reports request statistics, displaying in the REPL. */ ``` -------------------------------- ### Add cyclic restart timeouts Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces timeouts for cyclic restarts. This prevents infinite restart loops by setting a limit on restart attempts. ```javascript /* Added cyclic restart timeouts. Closes #23 */ ``` -------------------------------- ### Add test case for #125 Source: https://github.com/learnboost/cluster/blob/master/History.md Includes a new test case to specifically address issue #125. This enhances test coverage and ensures the fix for #125 is effective. ```javascript /* Added test case for #125 [felixge] */ ``` -------------------------------- ### Configure Logger with Custom Path and Debug Level Source: https://github.com/learnboost/cluster/blob/master/docs/logger.md This snippet illustrates configuring the logger plugin with both a custom log directory and a specific log level ('debug') for increased verbosity. ```javascript cluster(server) .use(cluster.logger('/var/log/node', 'debug')) .listen(3000); ``` -------------------------------- ### Graceful Shutdown with -g Flag Source: https://github.com/learnboost/cluster/blob/master/History.md Replaces the duplicate `-s` flag with `-g` for graceful shutdown, improving process management. ```bash node app.js -g ``` -------------------------------- ### Fix reload() using extname() instead of indexOf() Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects the `reload()` function to use `extname()` instead of `indexOf()` for determining file extensions. This ensures more accurate file extension handling. ```javascript /* Fixed; reload() using extname() instead of indexOf() [reported by solsys] */ ``` -------------------------------- ### Define REPL Function Source: https://github.com/learnboost/cluster/blob/master/docs/repl.md Defines a custom function accessible within the REPL. The function receives the master instance, the REPL socket, and any arguments passed. ```javascript var cluster = require('../'); var repl = cluster.repl; repl.define('echo', function(master, sock, msg) { sock.write(msg + '\n'); }, 'echo the given message'); // Example usage in REPL: // echo('Hello from REPL!'); ``` -------------------------------- ### Stats Plugin Event: Client Connection Source: https://github.com/learnboost/cluster/blob/master/docs/stats.md Details the event emitted when a client connects to the server, including the associated worker. ```text client connection, worker ``` -------------------------------- ### Add stand-alone shutdown test Source: https://github.com/learnboost/cluster/blob/master/History.md Adds a test case for the stand-alone shutdown functionality. This ensures that the cluster can be shut down properly in standalone mode. ```javascript /* Added stand-alone shutdown test */ ``` -------------------------------- ### Fix abort on many immediate worker deaths Source: https://github.com/learnboost/cluster/blob/master/History.md Ensures that the process aborts gracefully when multiple workers die immediately during boot. This prevents cascading failures. ```javascript /* Fixed; abort on many immediate worker deaths within boot */ ``` -------------------------------- ### Change exit > 0 when using cli() when cluster not running Source: https://github.com/learnboost/cluster/blob/master/History.md Modifies the behavior to exit with a status code greater than 0 when attempting to use the `cli()` function while the cluster is not running. This provides clearer feedback on the cluster's state. ```javascript /* Changed; exit > 0 when trying to use the `cli()` when cluster is not running */ ``` -------------------------------- ### Remove unnecessary use of client socket Source: https://github.com/learnboost/cluster/blob/master/History.md Eliminates the unnecessary use of client sockets, which was causing bind() errors. This optimization improves socket handling and prevents binding issues. ```javascript /* Removed unnecessary use of client socket causing `bind()` errors */ ``` -------------------------------- ### Process.setuid() Typo Fix Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects a typo in the `process.setuid()` function call. ```javascript process.setuid('user'); // Corrected ``` -------------------------------- ### Add request complete stats() event Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces a "request complete" event to the `stats()` function. This event is emitted when a request finishes, providing lifecycle information. ```javascript /* Added `request complete` `stats()` event */ ``` -------------------------------- ### Change internal IPC to use UDP Source: https://github.com/learnboost/cluster/blob/master/History.md Switches the internal Inter-Process Communication (IPC) mechanism to use UDP. This change aims to improve the efficiency and reliability of communication between processes. ```javascript /* Changed internal IPC to use UDP. Closes #126 */ ``` -------------------------------- ### Change cli() to operate on orphans Source: https://github.com/learnboost/cluster/blob/master/History.md Updates the `cli()` function to continue operating on orphaned child processes. This ensures that CLI commands can still manage processes even if they become orphaned. ```javascript /* Changed; `cli()` will still operate on orphans */ ``` -------------------------------- ### Fix .listen() return value Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects the return value of the .listen() method. This change ensures that the method behaves as expected and returns the correct value upon successful listening. ```javascript /* Fixed `.listen()` return value. Closes #149 [nibblebot] */ ``` -------------------------------- ### Stats Plugin Event: Client Request Source: https://github.com/learnboost/cluster/blob/master/docs/stats.md Details the event emitted when a client makes a request, including the associated worker and request details. ```text client request, worker, request ``` -------------------------------- ### Change demote user/group in master Source: https://github.com/learnboost/cluster/blob/master/History.md Modifies the master process to demote its user and group privileges. This is a security enhancement to run with fewer privileges. ```javascript /* Changed; demote user/group in master */ ``` -------------------------------- ### Revert "Changed; demote user/group in master" Source: https://github.com/learnboost/cluster/blob/master/History.md Reverts a previous change that demoted the user/group in the master process. This restores the previous behavior regarding user/group privileges. ```javascript /* Revert "Changed; demote user/group in master" */ ``` -------------------------------- ### Cluster Worker ID Environment Variable Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces the `__CLUSTER_WORKER__` environment variable to identify worker IDs within the cluster. ```javascript process.env.__CLUSTER_WORKER__ = workerId; ``` -------------------------------- ### Fix __SIGKILL__ children on master uncaught exception Source: https://github.com/learnboost/cluster/blob/master/History.md Ensures that child processes are killed with __SIGKILL__ when an uncaught exception occurs in the master process. This provides a more robust shutdown mechanism. ```javascript /* Fixed: __SIGKILL__ children on master uncaught exception */ ``` -------------------------------- ### Worker Exception Event Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces a new 'worker exception' event to handle exceptions occurring within worker processes. ```javascript master.on('worker exception', (worker, error) => { // Handle worker exception }); ``` -------------------------------- ### Fix typo in reload() plugin Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects a typo in the reload() plugin that caused the 'signal' option to fail. This fix ensures that the signal option functions correctly. ```javascript /* Fixed typo in `reload()` plugin causing the `signal` option to fail. Closes #131 */ ``` -------------------------------- ### Fix cli() hang regression Source: https://github.com/learnboost/cluster/blob/master/History.md Resolves a regression that caused the cli() function to hang. This fix improves the stability and responsiveness of the command-line interface. ```javascript /* Fixed `cli()` hang regression. Closes #148 */ ``` -------------------------------- ### Conditional Execution with `in()` Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Conditionally perform actions based on the NODE_ENV. The `in()` method allows chaining multiple environment-specific configurations. ```javascript cluster(server) .in('development').use(cluster.debug()) .in('development').listen(3000) .in('production').listen(80); ``` ```javascript cluster(server) .set('working directory', '/') .in('development') .set('workers', 1) .use(cluster.logger('logs', 'debug')) .use(cluster.debug()) .listen(3000) .in('production') .set('workers', 4) .use(cluster.logger()) .use(cluster.pidfiles()) .listen(80); ``` ```javascript cluster(server) .set('working directory', '/') .do(function(){ console.log('some arbitrary action'); }) .in('development') .set('workers', 1) .use(cluster.logger('logs', 'debug')) .use(cluster.debug()) .in('production') .set('workers', 4) .use(cluster.logger()) .use(cluster.pidfiles()) .in('all') .listen(80); ``` -------------------------------- ### Change cli commands to signal orphaned children Source: https://github.com/learnboost/cluster/blob/master/History.md Modifies CLI commands to signal orphaned child processes. This improves the management of child processes, ensuring they are properly handled. ```javascript /* Changed; cli commands will now signal orphaned children */ ``` -------------------------------- ### Fix standalone read from stdin regression Source: https://github.com/learnboost/cluster/blob/master/History.md Addresses a regression in standalone read from stdin, specifically related to the __ENOTSOCK__ error. This fix aims to resolve issues where the server socket is not properly handled. ```javascript /* Fixed standalone read from stdin (__ENOTSOCK__) regression. Closes #153 */ ``` -------------------------------- ### Add lightRequests option to stats() Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces the `lightRequests` option to the `stats()` function. This option likely controls the verbosity or type of request statistics reported. ```javascript /* Added `lightRequests` option to `stats()` */ ``` -------------------------------- ### SIGCHLD Trap for Worker Notification Source: https://github.com/learnboost/cluster/blob/master/History.md Implements a `__SIGCHLD__` trap to notify the master process when a worker is killed, enabling recovery. ```javascript process.on('SIGCHLD', () => { // Notify master of killed worker }); ``` -------------------------------- ### Change use preventDefault instead of exit() in cli() Source: https://github.com/learnboost/cluster/blob/master/History.md Replaces the use of exit() with preventDefault() within the cli() function. This change likely affects how events are handled in the CLI, preventing premature exits. ```javascript /* Changed: use preventDefault instead of `exit()` in `cli()` */ ``` -------------------------------- ### Fix cli() exit when working with reload() Source: https://github.com/learnboost/cluster/blob/master/History.md Resolves an issue where `cli()` would exit unexpectedly when used in conjunction with `reload()` or other functions that keep the event loop active. This ensures proper CLI behavior in such scenarios. ```javascript /* Fixed `cli()` exit when working with `reload()` (or anything else keeping the event loop active) */ ``` -------------------------------- ### Fix stand-alone issue with not killing parent master Source: https://github.com/learnboost/cluster/blob/master/History.md Resolves an issue in standalone mode where the parent master process was not being killed. This ensures proper process management during shutdown. ```javascript /* Fixed stand-alone issue with not killing the parent master. Closes #565 */ ``` -------------------------------- ### Fix close(fd) issue for Master without server Source: https://github.com/learnboost/cluster/blob/master/History.md Addresses a `close(fd)` issue encountered by the Master process when it does not have an associated server. This prevents errors related to file descriptor handling. ```javascript /* Fixed `close(fd)` issue for Master without a server. Closes #89 */ ``` -------------------------------- ### Add { color: false } option to debug() Source: https://github.com/learnboost/cluster/blob/master/History.md Introduces an option `{ color: false }` for the `debug()` function. This allows disabling color output for debugging messages. ```javascript /* Added `{ color: false }` option to `debug()` */ ``` -------------------------------- ### Reload() Filtering Source: https://github.com/learnboost/cluster/blob/master/History.md Modifies the `reload()` function to filter out non-JavaScript files and defaults to the server's root directory. ```javascript cluster.reload(); // Defaults to server root and filters non-js files ``` -------------------------------- ### Fix IPC for workers without a server Source: https://github.com/learnboost/cluster/blob/master/History.md Resolves an Inter-Process Communication (IPC) issue that occurred for workers not associated with a server. This ensures proper communication even in serverless worker scenarios. ```javascript /* Fixed IPC for workers without a server. Closes #91 */ ``` -------------------------------- ### Fix err.code check Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects an issue with checking the err.code property. This ensures that error handling logic is robust and correctly identifies error conditions. ```javascript /* Fixed an `err.code` check */ ``` -------------------------------- ### Change sync unlink of server / client sockets Source: https://github.com/learnboost/cluster/blob/master/History.md Modifies the unlinking of server and client sockets to be synchronous. This ensures that sockets are properly cleaned up before proceeding. ```javascript /* Changed: sync unlink of server / client sockets */ ``` -------------------------------- ### Fix clobbering of "worker exception" Source: https://github.com/learnboost/cluster/blob/master/History.md Resolves an issue where "worker exception" messages were being clobbered. This fix ensures that worker exception information is preserved and reported correctly. ```javascript /* Fixed clobbering of "worker exception" [reported by fredericosilva] */ ``` -------------------------------- ### Fix json framing Source: https://github.com/learnboost/cluster/blob/master/History.md Corrects an issue related to JSON framing. This ensures that JSON data is transmitted and received correctly between processes. ```javascript /* Fix for json framing. Closes #109 */ ``` -------------------------------- ### Change nextTick() uncaughtException handler Source: https://github.com/learnboost/cluster/blob/master/History.md Modifies the uncaughtException handler for nextTick(). This change likely improves error handling and prevents unexpected application termination. ```javascript /* Changed: nextTick() uncaughtException handler */ ``` -------------------------------- ### Remove master __SIGHUP__ as restart Source: https://github.com/learnboost/cluster/blob/master/History.md Removes the handling of __SIGHUP__ signal for restarting the master process. This change likely alters the restart mechanism. ```javascript /* Remove master __SIGHUP__ as restart */ ``` -------------------------------- ### Checking if Script is the Master Source: https://github.com/learnboost/cluster/blob/master/docs/api.md Illustrates how to check if the current script is the master process using the isMaster property. ```javascript cluster = cluster(server).listen(3000); if (cluster.isMaster) { // do something } ``` -------------------------------- ### Rename titles to "cluster" and "cluster worker" Source: https://github.com/learnboost/cluster/blob/master/History.md Renames internal titles to "cluster" and "cluster worker" for clarity. This change improves the internal naming conventions. ```javascript /* Renamed titles to "cluster" and "cluster worker". closes #82 */ ``` -------------------------------- ### Remove local socket usage Source: https://github.com/learnboost/cluster/blob/master/History.md Removes the usage of local sockets as they are being phased out from Node.js. This change aligns the project with Node.js core developments. ```javascript /* Removed local socket usage as it is being removed from node */ ``` -------------------------------- ### Fix restart race-condition Source: https://github.com/learnboost/cluster/blob/master/History.md Resolves a race condition that could occur during restarts. This improves the reliability of the restart process. ```javascript /* Fixed restart race-condition. Closes #125 */ ``` -------------------------------- ### Stats Plugin Event: Client Disconnection Source: https://github.com/learnboost/cluster/blob/master/docs/stats.md Details the event emitted when a client disconnects from the server, including the associated worker. ```text client disconnection, worker ``` -------------------------------- ### Change only caught uncaughtExceptions when no other listeners Source: https://github.com/learnboost/cluster/blob/master/History.md Modifies the behavior to only catch uncaught exceptions when there are no other listeners attached. This prevents interference with other error handling mechanisms. ```javascript /* Changed; only caught uncaughtExceptions when no other listeners are present */ ``` -------------------------------- ### Fix close socketpair fds when worker dies Source: https://github.com/learnboost/cluster/blob/master/History.md Ensures that socketpair file descriptors (fds) are properly closed when a worker process dies. This prevents resource leaks. ```javascript /* Fixed; close socketpair fds when worker dies */ ``` -------------------------------- ### Change reload() to reload workers only Source: https://github.com/learnboost/cluster/blob/master/History.md Updates the reload() functionality to exclusively reload workers. This change refines the reload process, focusing only on worker processes. ```javascript /* Changed `reload()` to reload workers only */ ``` -------------------------------- ### Fix json framing race-condition Source: https://github.com/learnboost/cluster/blob/master/History.md Resolves a race condition related to JSON framing. This ensures that JSON data is handled reliably during concurrent operations. ```javascript /* Fixed json framing race-condition. Closes #64 */ ```