From b9887427274a09c5764ed5fbeee1392f8e14ed41 Mon Sep 17 00:00:00 2001 From: crowetic Date: Thu, 24 Oct 2024 09:41:52 -0700 Subject: [PATCH] fixed issue where restart wasn't actually taking place, and added checks for stop.sh correctly finishing prior to killing as last resort after 30 seconds. May need to modify time a bit more. --- restart-qortal-every-2-hours.sh | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/restart-qortal-every-2-hours.sh b/restart-qortal-every-2-hours.sh index a73579e..a1d7440 100644 --- a/restart-qortal-every-2-hours.sh +++ b/restart-qortal-every-2-hours.sh @@ -8,27 +8,32 @@ while true; do cd "$QORTAL_DIR" || exit # Stop Qortal core - ./stop.sh + ./stop.sh &> stop_output.log - # Wait for 45 seconds + # Wait for 30 seconds sleep 30 - if [ -f "$QORTAL_DIR/db/blockchain.lck" ]; then - - # Kill all Java processes - killall -9 java + # Check if stop script succeeded + if ! grep -q "Qortal ended gracefully" stop_output.log; then + # Stop script did not complete successfully, kill Java process + echo "Stop script did not complete successfully, force killing Java..." + killall -9 java - # Remove blockchain lock file - rm -rf "$QORTAL_DIR/db/blockchain.lck" + # Remove blockchain lock file + rm -rf "$QORTAL_DIR/db/blockchain.lck" fi + # Start Qortal core ./start.sh - # Wait for 2 hours before restarting again, while tailing the log file + # Wait for 2 hours while logging output sleep 2h & - tail -f "$QORTAL_DIR/qortal.log" + sleep_pid=$! + tail -f "$QORTAL_DIR/qortal.log" & + tail_pid=$! - # Kill the tail process after sleep is done - kill $! + # Wait for the sleep to finish, then kill the tail process + wait $sleep_pid + kill $tail_pid done