Files
purple-explorer/scripts/stop_explorer.sh
T
joeuhren f948e29085 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
2021-04-17 13:26:05 -06:00

32 lines
1.2 KiB
Bash

#!/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