added logging and additional checks for screen
This commit is contained in:
parent
9b9ae82a30
commit
2b46d96075
@ -2,23 +2,32 @@
|
|||||||
|
|
||||||
# Path to the Qortal folder
|
# Path to the Qortal folder
|
||||||
QORTAL_DIR=~/qortal
|
QORTAL_DIR=~/qortal
|
||||||
|
LOG_FILE="$QORTAL_DIR/restart_log.txt"
|
||||||
|
|
||||||
|
# Logging function
|
||||||
|
log() {
|
||||||
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
# Check if screen is installed
|
# Check if screen is installed
|
||||||
if command -v screen &> /dev/null; then
|
if command -v screen &> /dev/null; then
|
||||||
echo "Screen is installed, running script in a screen session..."
|
log "Screen is installed, running script in a screen session..."
|
||||||
SCRIPT_NAME="restart-qortal-every-2-hours.sh"
|
SCRIPT_NAME="restart-qortal-every-2-hours.sh"
|
||||||
cp "$(dirname "$BASH_SOURCE")/$SCRIPT_NAME" "$QORTAL_DIR/$SCRIPT_NAME"
|
SCRIPT_PATH="$(realpath "$BASH_SOURCE")"
|
||||||
screen -S qortal_restart -dm bash "$QORTAL_DIR/$SCRIPT_NAME"
|
cp "$SCRIPT_PATH" "$QORTAL_DIR/$SCRIPT_NAME"
|
||||||
|
screen -S qortal_restart -dm bash -c "cd $QORTAL_DIR && bash $SCRIPT_NAME"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
echo "Screen is not installed, running script normally..."
|
log "Screen is not installed, running script normally..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
# Navigate to Qortal directory
|
# Navigate to Qortal directory
|
||||||
cd "$QORTAL_DIR" || exit
|
log "Navigating to Qortal directory..."
|
||||||
|
cd "$QORTAL_DIR" || { log "Failed to navigate to Qortal directory."; exit 1; }
|
||||||
|
|
||||||
# Stop Qortal core
|
# Stop Qortal core
|
||||||
|
log "Stopping Qortal core..."
|
||||||
./stop.sh &> stop_output.log &
|
./stop.sh &> stop_output.log &
|
||||||
stop_pid=$!
|
stop_pid=$!
|
||||||
|
|
||||||
@ -27,23 +36,26 @@ while true; do
|
|||||||
|
|
||||||
# Check if stop script succeeded
|
# Check if stop script succeeded
|
||||||
if ! grep -q "Qortal ended gracefully" stop_output.log; then
|
if ! grep -q "Qortal ended gracefully" stop_output.log; then
|
||||||
# Stop script did not complete successfully, kill Java process
|
log "Stop script did not complete successfully, force killing Java..."
|
||||||
echo "Stop script did not complete successfully, force killing Java..."
|
|
||||||
killall -9 java
|
killall -9 java
|
||||||
|
|
||||||
# Remove blockchain lock file
|
# Remove blockchain lock file
|
||||||
|
log "Removing blockchain lock file..."
|
||||||
rm -rf "$QORTAL_DIR/db/blockchain.lck"
|
rm -rf "$QORTAL_DIR/db/blockchain.lck"
|
||||||
else
|
else
|
||||||
echo "Qortal stopped gracefully."
|
log "Qortal stopped gracefully."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure stop process completes
|
# Ensure stop process completes
|
||||||
|
log "Waiting for stop process to complete..."
|
||||||
wait $stop_pid
|
wait $stop_pid
|
||||||
|
|
||||||
# Start Qortal core
|
# Start Qortal core
|
||||||
|
log "Starting Qortal core..."
|
||||||
./start.sh
|
./start.sh
|
||||||
|
|
||||||
# Wait for 2 hours while logging output --- CHANGE THE NUMBER OF HOURS HERE.
|
# Wait for 2 hours while logging output
|
||||||
|
log "Waiting for 2 hours before restarting..."
|
||||||
sleep 2h &
|
sleep 2h &
|
||||||
sleep_pid=$!
|
sleep_pid=$!
|
||||||
tail -f "$QORTAL_DIR/qortal.log" &
|
tail -f "$QORTAL_DIR/qortal.log" &
|
||||||
@ -51,6 +63,7 @@ while true; do
|
|||||||
|
|
||||||
# Wait for the sleep to finish, then kill the tail process
|
# Wait for the sleep to finish, then kill the tail process
|
||||||
wait $sleep_pid
|
wait $sleep_pid
|
||||||
|
log "2-hour wait complete, killing tail process..."
|
||||||
kill $tail_pid
|
kill $tail_pid
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user