8e32e294b7
-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
60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
const settings = require('../lib/settings');
|
|
const { exec } = require('child_process');
|
|
|
|
function validate_port(port) {
|
|
if (port == null || typeof port !== 'number' || port < 1 || port > 65535)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
function check_webserver_running(cb) {
|
|
// determine operating system
|
|
switch (process.platform) {
|
|
case 'win32':
|
|
// windows
|
|
exec(`for /f "tokens=5" %a in ('netstat -aon ^| findstr :${settings.webserver.port} ^| findstr LISTENING') do @echo %~nxa`, (err, stdout, stderr) => {
|
|
// check if the port is open
|
|
if (stdout != null && stdout != '') {
|
|
// split the results in case there are multiple (usually because of ipv4 and ipv6)
|
|
split = stdout.split('\n');
|
|
|
|
// return the kill cmd
|
|
return cb(`taskkill /f /pid ${split[0]}`);
|
|
} else
|
|
return cb(null);
|
|
});
|
|
break;
|
|
default:
|
|
// linux, macos, etc.
|
|
exec(`lsof -t -i:${settings.webserver.port}`, (err, stdout, stderr) => {
|
|
// check if the port is open
|
|
if (stdout != null && stdout != '') {
|
|
// return the kill cmd
|
|
return cb(`kill -2 ${stdout.trim()}`);
|
|
} else
|
|
return cb(null);
|
|
});
|
|
}
|
|
}
|
|
|
|
// check if the webserver.port value is a valid port #
|
|
if (validate_port(settings.webserver.port) == true) {
|
|
// check if the server is currently running
|
|
check_webserver_running(function(killcmd) {
|
|
// check return value
|
|
if (killcmd != null) {
|
|
// send a kill signal to the process that is currently using the explorer's server port
|
|
exec(killcmd, (err, stdout, stderr) => {
|
|
// show shutdown msg
|
|
console.log('Explorer shutting down... Please wait...');
|
|
});
|
|
} else {
|
|
// webserver is not running
|
|
console.log('Error: Cannot stop explorer because it is not currently running');
|
|
}
|
|
});
|
|
} else {
|
|
// invalid port number
|
|
console.log('Error: webserver.port value not found in settings.json.');
|
|
} |