Files
purple-explorer/bin/cluster
T
Joe Uhren 8e32e294b7 Cross-platform support (Win, MacOS, Linux)
-All shell scripts have been removed and replaced with javascript equivalents which allows for better platform independence
-All scripts have been improved over the older shell scripts to be more functional and dynamic
-Updated all applicable cmds in the package.json to target the new js scripts + added the backup, restore and delete database functions to the list
-Removed the json and strip-json-comments-cli packages as they are no longer needed
-Added a new package realine-sync
-Updated cluster code with better Windows support when shutting down the explorer
-Backup and Restore scripts now use mongo's own encryption instead of tar.gz by default. Older tar.gz backups can still be restored as long as the tar.gz suffix is explicitly added
-Backup and Restore scripts now support connecting to remote database based on the mongo details in settings.json
-Updated README to include a new line for the 'platform independence' feature, updated script cmds and notes about certain steps being Linux only
2022-04-23 11:28:32 -06:00

60 lines
1.8 KiB
Plaintext

var cluster = require('cluster');
var fs = require('fs');
const isWinOS = process.platform == 'win32';
if (cluster.isMaster) {
console.log('Starting cluster with pid: ' + process.pid);
// ensure workers exit cleanly
process.on('SIGINT', () => {
console.log('Cluster shutting down..');
// send kill cmd to all workers
for (var id in cluster.workers) {
console.log('Worker (' + id + ') shutting down...');
if (!isWinOS) {
// only kill the worker if not on windows (otherwise an error is displayed)
process.kill(cluster.workers[id]['process']['pid'], 'SIGINT');
}
}
function waitForWorkerShutdown () {
if (Object.keys(cluster.workers).length > 0) {
// continue waiting since worker threads are still open
setTimeout(waitForWorkerShutdown, 100);
} else {
// all worker threads have closed
// now exit the master process
if (isWinOS) {
// command line in windows doesn't seem to release itself
// show a message that the app has finished
console.log('The application is now safe to close');
}
process.exit(0);
}
}
waitForWorkerShutdown();
});
// count the machine's CPUs
var cpuCount = require('os').cpus().length;
// create a worker for each CPU
for (var i = 0; i < cpuCount; i += 1)
cluster.fork();
// listen for dying workers
cluster.on('exit', function (worker, code, signal) {
if (worker['process']['exitCode'] === 0) {
console.log('Worker (' + worker['id'] + ') shutdown complete');
} else if (signal != 'SIGINT' && worker['process']['exitCode'] !== 0 && worker['process']['exitCode'] !== 999 && worker.exitedAfterDisconnect !== true) {
console.log('Cluster restarting...');
cluster.fork();
}
});
} else
require('./instance');