From dd1c1e0fc04cbf08ac3018b4f32f53f3efc1bb78 Mon Sep 17 00:00:00 2001 From: crowetic Date: Fri, 22 Nov 2024 20:48:16 -0800 Subject: [PATCH] modified all start scripts with better memory settings, improved auto-fix script and added settings.json update to temporarily remove archive settings for network issues potentially related, will remove archiveInterval in the future. Also modified start-qortal.sh to add comprehensive checks for Qortal running and auto-fix script, and run both if not existing/running. --- 4GB-start.sh | 18 +++++- auto-fix-qortal.sh | 53 ++++++++++++++--- settings.json | 9 +-- start-6001-to-16000m.sh | 17 +++++- start-high-RAM.sh | 20 ++++++- start-modified-memory-args.sh | 19 +++++- start-qortal.sh | 105 ++++++++++++++++++++++++++++++++-- 7 files changed, 220 insertions(+), 21 deletions(-) diff --git a/4GB-start.sh b/4GB-start.sh index 23ad836..0cb63ea 100644 --- a/4GB-start.sh +++ b/4GB-start.sh @@ -33,7 +33,23 @@ fi # Limits Java JVM stack size and maximum heap usage. # Comment out for bigger systems, e.g. non-routers # or when API documentation is enabled -JVM_MEMORY_ARGS="-XX:MaxRAMPercentage=60 -XX:+UseG1GC -Xss512k -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./heapdump.hprof -Xlog:gc*:file=gc.log:time,uptime,level,tags" +#JVM_MEMORY_ARGS="-XX:MaxRAMPercentage=60 -XX:+UseG1GC -Xss512k -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./heapdump.hprof -Xlog:gc*:file=gc.log:time,uptime,level,tags" +JVM_MEMORY_ARGS=" + -Xms2600m \ + -Xmx2600m \ + -Xss1024k \ + -XX:+HeapDumpOnOutOfMemoryError \ + -XX:HeapDumpPath=./heapdump.hprof \ + -XX:+UseG1GC \ + -XX:MaxGCPauseMillis=300 \ + -XX:InitiatingHeapOccupancyPercent=75 \ + -XX:ParallelGCThreads=4 \ + -XX:ConcGCThreads=2 \ + -XX:G1HeapRegionSize=32m \ + -XX:MaxTenuringThreshold=10 \ + -XX:+AlwaysPreTouch +" + # Although java.net.preferIPv4Stack is supposed to be false # by default in Java 11, on some platforms (e.g. FreeBSD 12), diff --git a/auto-fix-qortal.sh b/auto-fix-qortal.sh index 637e8c8..b28bdd9 100644 --- a/auto-fix-qortal.sh +++ b/auto-fix-qortal.sh @@ -62,16 +62,17 @@ check_for_pi() { if [ "$(uname -m | grep 'armv7l')" != "" ]; then echo "${WHITE} 32bit ARM detected, using ARM 32bit compatible modified start script${NC}\n" PI_32_DETECTED=true + curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-modified-memory-args.sh + curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-cron + crontab auto-fix-cron + chmod +x start-modified-memory-args.sh + mv start-modified-memory-args.sh ~/qortal/start.sh + check_qortal else echo "${WHITE} 64bit ARM detected, proceeding accordingly...${NC}\n" PI_64_DETECTED=true fi - curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-modified-memory-args.sh - curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-cron - crontab auto-fix-cron - chmod +x start-modified-memory-args.sh - mv start-modified-memory-args.sh ~/qortal/start.sh - check_qortal + else echo "${YELLOW} Not a Raspberry pi machine, continuing...${NC}\n" check_memory @@ -469,6 +470,43 @@ force_bootstrap() { update_script } +potentially_update_settings() { + + BACKUP_FILE=~/backups/qortal-settings/settings-$(date +%Y%m%d%H%M%S).json + # Create backup folder if not exists and backup settings.json + echo "${GREEN}Creating backup directory ~/backups/qortal-settings...${NC}" + mkdir -p ~/backups/qortal-settings + echo "Backing up settings to ${BACKUP_FILE}..." + cp ~/qortal/settings.json "${BACKUP_FILE}" + + SETTINGS_FILE=~/qortal/settings.json + + echo "Checking for archivingPause setting..." + if grep -q '"archivingPause"' "${SETTINGS_FILE}"; then + echo "archivingPause exists... updating value..." + if command -v jq &> /dev/null; then + echo "jq exists, using jq to modify setting..." + jq '.archivingPause = 999999999999' "${SETTINGS_FILE}" > settings.tmp && mv settings.tmp "${SETTINGS_FILE}" + else + echo "jq doesn't exist, modifying with sed..." + sed -i 's/"archivingPause"[[:space:]]*:[[:space:]]*[0-9]*/"archivingPause": 999999999999/' "${SETTINGS_FILE}" + fi + else + echo "archivingPause doesn't exist, adding..." + if command -v jq &> /dev/null; then + echo "jq exists, adding with jq..." + jq '.archivingPause = 999999999999' "${SETTINGS_FILE}" > settings.tmp && mv settings.tmp "${SETTINGS_FILE}" + else + echo "jq doesn't exist, adding with sed..." + sed -i 's/}$/,"archivingPause": 999999999999}/' "${SETTINGS_FILE}" + fi + fi + + echo "Settings check complete! Exiting..." + exit +} + + update_script() { echo "${YELLOW}Updating script to newest version and backing up old one...${NC}\n" mkdir -p ~/qortal/new-scripts @@ -484,7 +522,8 @@ update_script() { rm -rf ~/auto_fix_updated echo "${YELLOW} Auto-fix script run complete.${NC}\n" sleep 5 - exit + potentially_update_settings } + initial_update diff --git a/settings.json b/settings.json index e1211c8..e07cee4 100644 --- a/settings.json +++ b/settings.json @@ -1,10 +1,11 @@ { "apiDocumentationEnabled":true, - "maxPeers": 77, + "maxPeers": 88, "minOutboundPeers": 22, - "maxNetworkThreadPoolSize": 660, - "repositoryConnectionPoolSize": 1880, + "maxNetworkThreadPoolSize": 600, + "repositoryConnectionPoolSize": 1220, "apiWhitelistEnabled": false, - "blockCacheSize": 333, + "blockCacheSize": 33, + "archiveInterval": 999999999999, "apiRestricted": false } diff --git a/start-6001-to-16000m.sh b/start-6001-to-16000m.sh index 922094c..425d3dc 100644 --- a/start-6001-to-16000m.sh +++ b/start-6001-to-16000m.sh @@ -33,7 +33,22 @@ fi # Limits Java JVM stack size and maximum heap usage. # Comment out for bigger systems, e.g. non-routers # or when API documentation is enabled -JVM_MEMORY_ARGS="-XX:MaxRAMPercentage=40 -XX:+UseG1GC -Xss512k -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./heapdump.hprof" +#JVM_MEMORY_ARGS="-XX:MaxRAMPercentage=40 -XX:+UseG1GC -Xss512k -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./heapdump.hprof" +JVM_MEMORY_ARGS=" + -Xms6000m \ + -Xmx6000m \ + -Xss2048k \ + -XX:+HeapDumpOnOutOfMemoryError \ + -XX:HeapDumpPath=./heapdump.hprof \ + -XX:+UseG1GC \ + -XX:MaxGCPauseMillis=300 \ + -XX:InitiatingHeapOccupancyPercent=55 \ + -XX:ParallelGCThreads=4 \ + -XX:ConcGCThreads=2 \ + -XX:G1HeapRegionSize=32m \ + -XX:MaxTenuringThreshold=10 \ + -XX:+AlwaysPreTouch +" # Although java.net.preferIPv4Stack is supposed to be false # by default in Java 11, on some platforms (e.g. FreeBSD 12), diff --git a/start-high-RAM.sh b/start-high-RAM.sh index 1977763..1c90d5a 100644 --- a/start-high-RAM.sh +++ b/start-high-RAM.sh @@ -34,13 +34,29 @@ fi # Comment out for bigger systems, e.g. non-routers # or when API documentation is enabled # Uncomment (remove '#' sign) line below if your system has less than 12GB of RAM for optimal RAM defaults -JVM_MEMORY_ARGS="-XX:MaxRAMPercentage=40 -XX:+UseG1GC -Xss512k -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./heapdump.hprof" +#JVM_MEMORY_ARGS="-XX:MaxRAMPercentage=40 -XX:+UseG1GC -Xss512k -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./heapdump.hprof" +JVM_MEMORY_ARGS=" + -Xms8000m \ + -Xmx8000m \ + -Xss4096k \ + -XX:+HeapDumpOnOutOfMemoryError \ + -XX:HeapDumpPath=./heapdump.hprof \ + -XX:+UseG1GC \ + -XX:MaxGCPauseMillis=300 \ + -XX:InitiatingHeapOccupancyPercent=35 \ + -XX:ParallelGCThreads=4 \ + -XX:ConcGCThreads=2 \ + -XX:G1HeapRegionSize=32m \ + -XX:MaxTenuringThreshold=10 \ + -XX:+AlwaysPreTouch +" + # Although java.net.preferIPv4Stack is supposed to be false # by default in Java 11, on some platforms (e.g. FreeBSD 12), # it is overridden to be true by default. Hence we explicitly # set it to false to obtain desired behaviour. -nohup nice -n 2 java \ +nohup nice -n 12 java \ -Djava.net.preferIPv4Stack=false \ ${JVM_MEMORY_ARGS} \ -jar qortal.jar \ diff --git a/start-modified-memory-args.sh b/start-modified-memory-args.sh index 6e1d676..b7b52c0 100644 --- a/start-modified-memory-args.sh +++ b/start-modified-memory-args.sh @@ -33,13 +33,28 @@ fi # Limits Java JVM stack size and maximum heap usage. # Comment out for bigger systems, e.g. non-routers # or when API documentation is enabled -JVM_MEMORY_ARGS="-Xss1256k -Xmx1750m" +#JVM_MEMORY_ARGS="-Xss1256k -Xms1750m -Xmx1750m" +JVM_MEMORY_ARGS=" + -Xms1750m \ + -Xmx1750m \ + -Xss1212k \ + -XX:+HeapDumpOnOutOfMemoryError \ + -XX:HeapDumpPath=./heapdump.hprof \ + -XX:+UseG1GC \ + -XX:MaxGCPauseMillis=300 \ + -XX:InitiatingHeapOccupancyPercent=50 \ + -XX:ParallelGCThreads=4 \ + -XX:ConcGCThreads=2 \ + -XX:G1HeapRegionSize=32m \ + -XX:MaxTenuringThreshold=10 \ + -XX:+AlwaysPreTouch +" # Although java.net.preferIPv4Stack is supposed to be false # by default in Java 11, on some platforms (e.g. FreeBSD 12), # it is overridden to be true by default. Hence we explicitly # set it to false to obtain desired behaviour. -nohup nice -n 5 java \ +nohup nice -n 15 java \ -Djava.net.preferIPv4Stack=false \ ${JVM_MEMORY_ARGS} \ -jar qortal.jar \ diff --git a/start-qortal.sh b/start-qortal.sh index 3bf0b7c..96198dd 100644 --- a/start-qortal.sh +++ b/start-qortal.sh @@ -1,5 +1,102 @@ #!/bin/bash -cd qortal -./stop.sh -sleep 3 -./start.sh + +QORTAL_RUNNING=$(curl -sS --connect-timeout 10 "localhost:12391/admin/status") +GUI_START="~/.config/autostart/start-qortal.desktop" + +if [ -f "${GUI_START}" ]; then + echo "Qortal is set up to start via GUI, waiting 2 minutes for Qortal to start..." + sleep 120 + echo "Checking if Qortal is running..." + QORTAL_RUNNING=$(curl -sS --connect-timeout 10 "localhost:12391/admin/status") + if [ -n "${QORTAL_RUNNING}" ]; then + echo "Qortal is already running...not starting Qortal..." + exit + else + echo "Qortal did not start after 2 minutes...waiting another 90 seconds..." + sleep 90 + echo "Attempting to start Qortal again..." + bash ~/qortal/start.sh + echo "Waiting 120 seconds..." + sleep 120 + QORTAL_RUNNING=$(curl -sS --connect-timeout 10 "localhost:12391/admin/status") + if [ -n "${QORTAL_RUNNING}" ]; then + echo "Qortal running, exiting..." + exit + else + echo "Qortal is still not running... checking for auto-fix-visible GUI..." + if [ -f ~/.config/autostart/auto-fix-visible* ]; then + echo "auto-fix-visible exists, waiting for auto-fix script to run..." + exit 1 + else + echo "auto-fix-visible doesn't exist... running auto-fix script manually..." + curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-qortal.sh + chmod +x auto-fix-qortal.sh + echo "Executing auto-fix-qortal.sh..." + ./auto-fix-qortal.sh + exit + fi + fi + fi + +else + echo "Qortal is not set up to start via GUI...Checking if Qortal is running after a 90-second wait..." + sleep 90 + QORTAL_RUNNING=$(curl -sS --connect-timeout 10 "localhost:12391/admin/status") + if [ -z "${QORTAL_RUNNING}" ]; then + echo "Qortal is not running..." + echo "Attempting to start Qortal..." + bash ~/qortal/start.sh + echo "Start script has executed, awaiting Qortal start..." + sleep 90 + echo "Checking if Qortal is running..." + QORTAL_RUNNING=$(curl -sS --connect-timeout 10 "localhost:12391/admin/status") + if [ -n "${QORTAL_RUNNING}" ]; then + echo "Qortal has started successfully! Exiting script..." + exit + else + echo "Qortal did not start...force-killing Java and starting again..." + killall -9 java + bash ~/qortal/start.sh + echo "Qortal start script has been executed..." + if crontab -l | grep -q '#.*auto-fix-qortal.sh'; then + echo "'auto-fix-qortal.sh' is commented out in crontab. Manually executing auto-fix script..." + echo "Grabbing the newest version of auto-fix script..." + cd + curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-qortal.sh + chmod +x auto-fix-qortal.sh + echo "Executing auto-fix-qortal.sh..." + ./auto-fix-qortal.sh + exit + elif crontab -l | grep -q '[^#]*auto-fix-qortal.sh'; then + echo "'auto-fix-qortal.sh' is active in crontab...auto-fix script should run automatically within 7 min from reboot..." + echo "Checking if machine has just booted..." + UPTIME=$(awk '{print int($1)}' /proc/uptime) + if [ "${UPTIME}" -ge 420 ]; then + echo "Machine has been online longer than 7 min, assuming auto-fix script would have run if it were supposed to..." + echo "Running auto-fix script manually..." + curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-qortal.sh + chmod +x auto-fix-qortal.sh + echo "Executing auto-fix-qortal.sh..." + ./auto-fix-qortal.sh + exit + else + echo "Machine has been online less than 7 min, allowing auto-fix script to run on its own..." + exit + fi + else + echo "'auto-fix-qortal.sh' does not exist in crontab." + echo "Assuming it was removed accidentally..." + echo "Running auto-fix script manually, and setting it up to run automatically..." + curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-qortal.sh + chmod +x auto-fix-qortal.sh + echo "Executing auto-fix-qortal.sh..." + ./auto-fix-qortal.sh + exit + fi + fi + else + echo "Qortal is running, exiting script..." + exit + fi +fi +