diff --git a/rootfs/standard/etc/dphys-swapfile b/rootfs/standard/etc/dphys-swapfile index 7f9e8482..d0637e6e 100644 --- a/rootfs/standard/etc/dphys-swapfile +++ b/rootfs/standard/etc/dphys-swapfile @@ -13,7 +13,7 @@ # set size to absolute value, leaving empty (default) then uses computed value # you most likely don't want this, unless you have an special disk situation -#######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################CONF_SWAPSIZE=100100 +#CONF_SWAPSIZE=100100 # set size to computed value, this times RAM size, dynamically adapts, # guarantees that there is enough swap without wasting disk space on excess @@ -23,5 +23,9 @@ # can be set to empty for no limit, but beware of filled partitions! # this is/was a (outdated?) 32bit kernel limit (in MBytes), do not overrun it # but is also sensible on 64bit to prevent filling /var or even / partition -CONF_MAXSWAP=1024 +#CONF_MAXSWAP=8000 + +# myNode Settings +CONF_SWAPSIZE=2048 +CONF_MAXSWAP=8000 CONF_SWAPFILE=/mnt/hdd/swapfile diff --git a/rootfs/standard/usr/bin/mynode_startup.sh b/rootfs/standard/usr/bin/mynode_startup.sh index 5fccd096..5335cc19 100755 --- a/rootfs/standard/usr/bin/mynode_startup.sh +++ b/rootfs/standard/usr/bin/mynode_startup.sh @@ -74,7 +74,7 @@ fi # Verify we are in a clean state -if [ $IS_RASPI -eq 1 ] || [ $IS_ROCKPRO64 -eq 1 ]; then +if [ $IS_RASPI -eq 1 ] || [ $IS_ROCK64 -eq 1 ] || [ $IS_ROCKPRO64 -eq 1 ]; then dphys-swapfile swapoff || true dphys-swapfile uninstall || true fi @@ -321,14 +321,23 @@ chown bitcoin:bitcoin /mnt/hdd/mynode/ # Setup swap on new HDD -if [ $IS_RASPI -eq 1 ] || [ $IS_ROCKPRO64 -eq 1 ]; then - if [ ! -f /mnt/hdd/swapfile ]; then - dd if=/dev/zero of=/mnt/hdd/swapfile count=1000 bs=1MiB - chmod 600 /mnt/hdd/swapfile +if [ ! -f /mnt/hdd/mynode/settings/swap_size ]; then + # Set defaults + touch /mnt/hdd/mynode/settings/swap_size + echo "2" > /mnt/hdd/mynode/settings/swap_size + sed -i "s|CONF_SWAPSIZE=.*|CONF_SWAPSIZE=2048|" /etc/dphys-swapfile +else + # Update swap config file in case upgrade overwrote file + SWAP=$(cat /mnt/hdd/mynode/settings/swap_size) + SWAP_MB=$(($SWAP * 1024)) + sed -i "s|CONF_SWAPSIZE=.*|CONF_SWAPSIZE=$SWAP_MB|" /etc/dphys-swapfile +fi +if [ $IS_RASPI -eq 1 ] || [ $IS_ROCK64 -eq 1 ] || [ $IS_ROCKPRO64 -eq 1 ]; then + SWAP=$(cat /mnt/hdd/mynode/settings/swap_size) + if [ "$SWAP" -ne "0" ]; then + dphys-swapfile install + dphys-swapfile swapon fi - - mkswap /mnt/hdd/swapfile - dphys-swapfile swapon fi diff --git a/rootfs/standard/var/www/mynode/device_info.py b/rootfs/standard/var/www/mynode/device_info.py index 0548ba8c..98286c2a 100644 --- a/rootfs/standard/var/www/mynode/device_info.py +++ b/rootfs/standard/var/www/mynode/device_info.py @@ -9,6 +9,27 @@ import subprocess # Globals local_ip = "unknown" +#================================== +# Utilities +#================================== +def get_file_contents(filename): + contents = "UNKNOWN" + try: + with open(filename, "r") as f: + contents = f.read().strip() + except: + contents = "ERROR" + return contents + +def set_file_contents(filename, data): + try: + with open(filename, "w") as f: + f.write(data) + os.system("sync") + return True + except: + return False + return False #================================== # Manage Device @@ -251,6 +272,13 @@ def is_mount_read_only(mnt): return 'ro' in flags return False +def set_swap_size(size): + size_mb = int(size) * 1024 + os.system("sed -i 's|CONF_SWAPSIZE=.*|CONF_SWAPSIZE={}|' /etc/dphys-swapfile".format(size_mb)) + return set_file_contents("/mnt/hdd/mynode/settings/swap_size", size) + +def get_swap_size(): + return get_file_contents("/mnt/hdd/mynode/settings/swap_size") #================================== # Service Status, Enabled, Logs, etc... diff --git a/rootfs/standard/var/www/mynode/settings.py b/rootfs/standard/var/www/mynode/settings.py index a7873383..9349bcff 100644 --- a/rootfs/standard/var/www/mynode/settings.py +++ b/rootfs/standard/var/www/mynode/settings.py @@ -134,6 +134,7 @@ def page_settings(): "serial_number": serial_number, "device_type": device_type, "device_ram": device_ram, + "swap_size": get_swap_size(), "product_key": product_key, "product_key_skipped": pk_skipped, "product_key_error": pk_error, @@ -757,6 +758,8 @@ def ping_page(): @mynode_settings.route("/settings/toggle-darkmode") def toggle_darkmode_page(): + check_logged_in() + if is_darkmode_enabled(): disable_darkmode() else: @@ -765,8 +768,32 @@ def toggle_darkmode_page(): @mynode_settings.route("/settings/toggle-netdata") def toggle_netdata_page(): + check_logged_in() + if is_netdata_enabled(): disable_netdata() else: enable_netdata() - return redirect("/settings") \ No newline at end of file + return redirect("/settings") + +@mynode_settings.route("/settings/modify-swap") +def modify_swap_page(): + check_logged_in() + + check_and_mark_reboot_action("modify_swap") + + size = request.args.get('size') + set_swap_size(size) + + # Trigger reboot + t = Timer(1.0, reboot_device) + t.start() + + # Display wait page + templateData = { + "title": "myNode Reboot", + "header_text": "Restarting", + "subheader_text": "This will take several minutes...", + "ui_settings": read_ui_settings() + } + return render_template('reboot.html', **templateData) \ No newline at end of file diff --git a/rootfs/standard/var/www/mynode/templates/settings.html b/rootfs/standard/var/www/mynode/templates/settings.html index 566e3ffc..83165f0d 100644 --- a/rootfs/standard/var/www/mynode/templates/settings.html +++ b/rootfs/standard/var/www/mynode/templates/settings.html @@ -319,6 +319,20 @@ window.location.href='/settings/reinstall-app?app='+reinstall_app_choice }); + var swap_choice=""; + $("#swap_size").selectmenu( { + change: function( event, data ) { + swap_choice = data.item.value; + $("#swap_button").button("enable"); + } + }); + $("#swap_button").button({ + disabled: true + }); + $("#swap_button").on("click", function() { + window.location.href='/settings/modify-swap?size='+swap_choice + }); + $('#btc_lnd_tor_checkbox').change(function () { $("#btc_lnd_tor").show(); }); @@ -804,6 +818,24 @@ + +
+ +
Swap
+ Devices can use space on the external drive as additional RAM. The default is to use 2GB of space on the drive as additional memory, but this can be changed. +

+ Modifying the amount of swap can affect overall performance. Saving will reboot the device. + +

+ + +