diff --git a/stop.sh b/stop.sh index 678472a7..d79a51db 100755 --- a/stop.sh +++ b/stop.sh @@ -21,15 +21,50 @@ fi read pid 2>/dev/null /dev/null 2>&1; then + success=1 + fi +fi + +# Try to kill process with SIGTERM +if [ "$success" -ne 1 ] && [ -n "$pid" ]; then + echo "Stopping Qortal process $pid..." + if kill -15 "${pid}"; then + success=1 + fi +fi + +# Warn and exit if still no success +if [ "$success" -ne 1 ]; then + if [ -n "$pid" ]; then + echo "${red}Stop command failed - not running with process id ${pid}?${normal}" + else + echo "${red}Stop command failed - not running?${normal}" + fi + exit 1 +fi +if [ "$success" -eq 1 ]; 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 @@ -40,8 +75,6 @@ if kill "${pid}"; then echo "${green}Qortal ended gracefully${normal}" rm -f run.pid fi - exit 0 -else - echo "${red}Stop command failed - not running with process id ${pid}?${normal}" - exit 1 fi + +exit 0