|
|
|
@ -21,38 +21,27 @@ fi
|
|
|
|
|
read pid 2>/dev/null <run.pid |
|
|
|
|
is_pid_valid=$? |
|
|
|
|
|
|
|
|
|
# Swap out the API port if the --testnet (or -t) argument is specified |
|
|
|
|
api_port=12391 |
|
|
|
|
if [[ "$@" = *"--testnet"* ]] || [[ "$@" = *"-t"* ]]; then |
|
|
|
|
api_port=62391 |
|
|
|
|
if [ -z "${pid}" ]; then |
|
|
|
|
# Attempt to locate the process ID |
|
|
|
|
pid=$(ps aux | grep '[q]ortal.jar' | awk '{print $2}') |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Ensure curl is installed |
|
|
|
|
curl_path=$(which curl) |
|
|
|
|
|
|
|
|
|
if [[ -f $curl_path ]]; then |
|
|
|
|
|
|
|
|
|
echo 'Calling GET /admin/stop on local Qortal node' |
|
|
|
|
if curl --url "http://localhost:${api_port}/admin/stop" 1>/dev/null 2>&1; then |
|
|
|
|
echo "Qortal node responded and should be shutting down" |
|
|
|
|
|
|
|
|
|
if [ "${is_pid_valid}" -eq 0 ]; then |
|
|
|
|
echo -n "Monitoring for Qortal node to end" |
|
|
|
|
while s=`ps -p $pid -o stat=` && [[ "$s" && "$s" != 'Z' ]]; do |
|
|
|
|
echo -n . |
|
|
|
|
sleep 1 |
|
|
|
|
done |
|
|
|
|
echo |
|
|
|
|
echo "${green}Qortal ended gracefully${normal}" |
|
|
|
|
rm -f run.pid |
|
|
|
|
fi |
|
|
|
|
exit 0 |
|
|
|
|
else |
|
|
|
|
echo "${red}No response from Qortal node - not running on port ${api_port}?${normal}" |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
echo "Stopping Qortal process $pid..." |
|
|
|
|
if kill "${pid}"; then |
|
|
|
|
echo "Qortal node should be shutting down" |
|
|
|
|
|
|
|
|
|
if [ "${is_pid_valid}" -eq 0 ]; then |
|
|
|
|
echo -n "Monitoring for Qortal node to end" |
|
|
|
|
while s=`ps -p $pid -o stat=` && [[ "$s" && "$s" != 'Z' ]]; do |
|
|
|
|
echo -n . |
|
|
|
|
sleep 1 |
|
|
|
|
done |
|
|
|
|
echo |
|
|
|
|
echo "${green}Qortal ended gracefully${normal}" |
|
|
|
|
rm -f run.pid |
|
|
|
|
fi |
|
|
|
|
exit 0 |
|
|
|
|
else |
|
|
|
|
echo "${red}curl is not installed or in the path${normal}" |
|
|
|
|
exit 1 |
|
|
|
|
echo "${red}Stop command failed - not running with process id ${pid}?${normal}" |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|