Cluster updates + add new start/stop options

-More graceful shutdown of node cluster on 'npm stop' with better cleanup of resources on exit
-Added new stop_explorer.sh script which looks up the explorer port # via settings file and closes the application running on that port # instead of saving and killing the process by pid as it did before
-Added support for pm2 and forever using 'npm run start-pm2' and 'npm run start-forever' respectively
-pm2 is automatically installed when starting with 'npm run start-pm2' if it is not already installed
-forever is automatically installed when starting with 'npm run start-forever' if it is not already installed
-Updated existing npm commands in package.json by replacing hardcoded 'node' with '$(which node)'
-/path/to/nodejs changed to /path/to/node in the /settings.json.template, /lib/settings.js and /scripts/sync.js files
-README updates:
 -Added a new 'Start/Stop the Explorer' section
 -Added PM2 instructions to the 'Start/Stop the Explorer' section
 -Moved Start/Stop Explorer instructions to the 'Start/Stop the Explorer' section
 -Moved Forever instructions to the 'Start/Stop the Explorer' section
 -/path/to/nodejs changed to /path/to/node
 -Some additional small misc fixes
This commit is contained in:
joeuhren
2021-04-17 13:26:05 -06:00
parent 24cd111e0c
commit f948e29085
9 changed files with 236 additions and 88 deletions
+21
View File
@@ -6,6 +6,27 @@
# npm update
#fi
# Check if an argument was passed into this script
if [ -n "${1}" ]; then
# Determine which argument was passed
case "${1}" in
"pm2")
# Check if pm2 is installed
if [ -z "$(which pm2)" ]; then
# Install pm2
npm install pm2@latest -g
fi
;;
"forever")
# Check if forever is installed
if [ -z "$(which forever)" ]; then
# Install forever
npm install forever -g
fi
;;
esac
fi
# Ensure that selected theme is properly installed
sh ./scripts/sass_theme_reader.sh
+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
validate_port() {
if [ -z "$1" ] || ([ -n "$1" ] && ((echo $1 | egrep -q '^[0-9]+$' && ([ $1 -lt 1 ] || [ $1 -gt 65535 ])) || ! test "$1" -gt 0 2> /dev/null)); then
echo "err"
fi
}
# Check if the settings.json file exists
if [ -f ./settings.json ]; then
# Read the webserver.port value from settings.json file
readonly SERVER_PORT="$(./node_modules/.bin/strip-json-comments settings.json | ./node_modules/.bin/json -q webserver.port)"
# Check if the webserver.port value is a valid port #
if [ -z "$(validate_port $SERVER_PORT)" ]; then
# Check if the server is currently running
if [ -n "$(lsof -t -i:${SERVER_PORT} 2> /dev/null)" ]; then
# Send a SIGINT kill signal to the process that is currently using the explorer's server port
kill -2 $(lsof -t -i:${SERVER_PORT})
# Show shutdown msg
echo "Explorer shutting down... Please wait..."
else
# Webserver is not running
echo "Error: Cannot stop explorer because it is not currently running"
fi
else
# Invalid port number
echo "Error: webserver.port value not found in settings.json. webserver.port value is missing or file is not valid json."
fi
else
# Missing settings file
echo "Error: Cannot find settings.json"
fi
+1 -1
View File
@@ -12,7 +12,7 @@ var database = 'index';
// displays usage and exits
function usage() {
console.log('Usage: scripts/sync.sh /path/to/nodejs [mode]');
console.log('Usage: scripts/sync.sh /path/to/node [mode]');
console.log('');
console.log('Mode: (required)');
console.log('update Updates index from last sync to current block');