diff --git a/scripts/healthcheck b/scripts/healthcheck index cae85a4..44a118f 100644 --- a/scripts/healthcheck +++ b/scripts/healthcheck @@ -14,7 +14,9 @@ defaultLightningDiagnosticLogAbsPath="$defaultLightningLogPath/$defaultLightning defaultLightningOutputLogAbsPath="$defaultLightningLogPath/$defaultLightningOutputFilename" defaultTargetName="release" defaultLightningSystemdServiceName="$defaultName" +defaultLightningSystemdServiceNameForDocker="docker-$defaultName" defaultLightningSystemdServicePath="/etc/systemd/system/$defaultLightningSystemdServiceName.service" +defaultLightningSystemdServicePathForDocker="/etc/systemd/system/$defaultLightningSystemdServiceNameForDocker.service" defaultLightningBasePath="$HOME/.$defaultName" defaultLightningConfigFilename="config.toml" defaultLightningConfigPath="$defaultLightningBasePath/$defaultLightningConfigFilename" @@ -124,6 +126,53 @@ warningCount=0 echo "✅ The localhost:4230/health is okay" fi + if [[ -f "$defaultLightningSystemdServicePath" ]]; then + while read -rp "🤖 This process requires to clear the logs and restart the service. Should it clear the logs and restart the service? (yes/no) " answer; do + if [[ "$answer" == [nN] || "$answer" == [nN][oO] ]]; then + echo "👹 Oops! The healthcheck verification was exited." + + exit 1 + elif [[ "$answer" == [yY] || "$answer" == [yY][eE][sS] ]]; then + sudo rm "$defaultLightningOutputLogAbsPath" + sudo rm "$defaultLightningDiagnosticLogAbsPath" + + if [[ -f "$defaultLightningSystemdServicePathForDocker" ]]; then + sudo systemctl restart "$defaultLightningSystemdServiceNameForDocker" + else + sudo systemctl restart "$defaultName" + fi + + serverOutputWaitAttempts=0 + while [[ -f "$defaultLightningOutputLogAbsPath" && ! -s "$defaultLightningOutputLogAbsPath" ]]; do + echo "🤖 Please wait for the service output logs..." + sleep 5 + + if [[ "$serverOutputWaitAttempts" -gt 10 ]]; then + break + fi + + ((serverOutputWaitAttempts++)) + done + + echo + + if ! curl -qsS localhost:4230/health 2>/dev/null | grep -q 'OK'; then + if tail -n 5 "$defaultLightningOutputLogAbsPath" | grep -iq "Node is not staked"; then + echo "⚠️ WARNING: The node is not staked. Have you read the instructions to get onboarded? Find it here https://docs.fleek.network/docs/node/testnet-onboarding" + echo + + ((warningCount++)) + ((healthIssueCount++)) + fi + + break; + fi + fi + + printf "💩 Uh-oh! We expect a yes or no answer. Try again...\n" + done + fi + echo echo echo "==== Summary ===="