mirror of
https://github.com/mynodebtc/mynode.git
synced 2024-12-25 14:08:07 +00:00
Change swap default to 2GB; Swap size is configurable
This commit is contained in:
parent
56a8845cc3
commit
57cc58c852
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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...
|
||||
|
|
|
@ -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")
|
||||
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)
|
|
@ -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 @@
|
|||
|
||||
</select>
|
||||
<button id="reinstall_button">Reinstall</button>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="settings_block_subheader">Swap</div>
|
||||
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.
|
||||
<br/><br/>
|
||||
Modifying the amount of swap can affect overall performance. Saving will reboot the device.
|
||||
|
||||
<br/><br/>
|
||||
|
||||
<select name="swap_size" id="swap_size">
|
||||
<option value="0" {% if swap_size == "0" %}selected="selected"{% endif %}>No Swap</option>
|
||||
<option value="1" {% if swap_size == "1" %}selected="selected"{% endif %}>1 GB</option>
|
||||
<option value="2" {% if swap_size == "2" %}selected="selected"{% endif %}>2 GB</option>
|
||||
<option value="3" {% if swap_size == "3" %}selected="selected"{% endif %}>3 GB</option>
|
||||
<option value="4" {% if swap_size == "4" %}selected="selected"{% endif %}>4 GB</option>
|
||||
</select>
|
||||
<button id="swap_button">Save</button>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user