Add ability to enable/disable quicksync

This commit is contained in:
Taylor Helsper 2019-07-31 21:46:22 -05:00
parent 4e991f627a
commit 63e52d2a0a
6 changed files with 77 additions and 8 deletions

View File

@ -16,8 +16,16 @@ mkdir -p $QUICKSYNC_CONFIG_DIR
cp -f /usr/share/quicksync/settings.json $QUICKSYNC_CONFIG_DIR/settings.json
# Check if quicksync was disabled
while [ -f $QUICKSYNC_DIR/.quicksync_disabled || -f /home/bitcoin/.mynode/.quicksync_disabled ]; do
sleep 1d
while [ -f /home/bitcoin/.mynode/quicksync_disabled ] || [ -f /mnt/hdd/mynode/settings/quicksync_disabled ]; do
# Pretend quicksync step is complete
touch $QUICKSYNC_DIR/.quicksync_download_complete
touch $QUICKSYNC_DIR/.quicksync_complete
sync
# Give Bitcoin a couple minutes to start
sleep 120s
echo "stable" > $MYNODE_DIR/.mynode_status
sync
sleep 10d
done
# Make sure folder exists

View File

@ -15,11 +15,15 @@ sync
# Copy files
echo "quicksync_copy" > $MYNODE_DIR/.mynode_status
rm -rf $MYNODE_DIR/bitcoin/blocks/
rm -rf $MYNODE_DIR/bitcoin/chainstate/
tar -xvf $QUICKSYNC_DIR/blockchain*.tar.gz -C $MYNODE_DIR/bitcoin/ --dereference
# Mark quicksync complete
echo "stable" > $MYNODE_DIR/.mynode_status
# Mark quicksync complete and give BTC a few minutes to startup with its new data
touch $QUICKSYNC_DIR/.quicksync_complete
sync
sleep 5m
echo "stable" > $MYNODE_DIR/.mynode_status
sync
exit 0

View File

@ -55,6 +55,17 @@ def unset_uploader():
os.system("rm -rf /mnt/hdd/mynode/settings/uploader")
def is_quicksync_enabled():
return not os.path.isfile("/home/bitcoin/.mynode/quicksync_disabled") and \
not os.path.isfile("/mnt/hdd/mynode/settings/quicksync_disabled")
def disable_quicksync():
os.system("touch /home/bitcoin/.mynode/quicksync_disabled")
os.system("touch /mnt/hdd/mynode/settings/quicksync_disabled")
def enable_quicksync():
os.system("rm -rf /home/bitcoin/.mynode/quicksync_disabled")
os.system("rm -rf /mnt/hdd/mynode/settings/quicksync_disabled")
def set_skipped_product_key():
os.system("touch /home/bitcoin/.mynode/.product_key_skipped")
os.system("touch /mnt/hdd/mynode/settings/.product_key_skipped")

View File

@ -117,7 +117,7 @@ def index():
return render_template('state.html', **templateData)
elif status == STATE_DRIVE_MOUNTED:
templateData = {
"title": "myNode QuickSync",
"title": "myNode Drive Mounted",
"header_text": "Drive Mounted",
"subheader_text": "myNode starting soon..."
}

View File

@ -23,9 +23,25 @@ def restart_lnd():
def stop_bitcoind():
os.system("systemctl stop bitcoind")
def stop_quickcync():
def stop_quicksync():
os.system("systemctl stop quicksync")
def settings_disable_quicksync():
stop_bitcoind()
stop_quicksync()
disable_quicksync()
delete_bitcoin_data()
delete_quicksync_data()
reboot_device()
def settings_enable_quicksync():
stop_bitcoind()
stop_quicksync()
enable_quicksync()
delete_bitcoin_data()
delete_quicksync_data()
reboot_device()
def reset_bitcoin_env_file():
os.system("echo 'BTCARGS=' > "+BITCOIN_ENV_FILE)
@ -59,7 +75,7 @@ def reset_blockchain():
def restart_quicksync():
os.system('echo "quicksync_reset" > /mnt/hdd/mynode/.mynode_status')
stop_bitcoind()
stop_quickcync()
stop_quicksync()
delete_bitcoin_data()
delete_quicksync_data()
reboot_device()
@ -129,6 +145,7 @@ def page_settings():
"product_key_skipped": pk_skipped,
"product_key_error": pk_error,
"quicksync_status": quicksync_status,
"is_quicksync_disabled": not is_quicksync_enabled(),
"is_uploader_device": is_uploader(),
"uptime": uptime
}
@ -313,6 +330,24 @@ def toggle_uploader_page():
}
return render_template('reboot.html', **templateData)
@mynode_settings.route("/settings/toggle-quicksync")
def toggle_quicksync_page():
# Toggle uploader
if is_quicksync_enabled():
t = Timer(1.0, settings_disable_quicksync)
t.start()
else:
t = Timer(1.0, settings_enable_quicksync)
t.start()
# Wait until device is restarted
templateData = {
"title": "myNode Reboot",
"header_text": "Restarting",
"subheader_text": "This will take several minutes..."
}
return render_template('reboot.html', **templateData)
@mynode_settings.route("/settings/ping")
def ping_page():
return "alive"

View File

@ -253,6 +253,17 @@
<div class="settings_block">
<div class="settings_block_header">Bitcoin</div>
<div class="settings_block_subheader">Toggle QuickSync</div>
Disabling QuickSync will reset blockchain data and re-download and validate the blockchain independently. This may take a long time, but you can re-enable QuickSync later.
<br/>
{% if is_quicksync_disabled %}
<a href="/settings/toggle-quicksync" class="ui-button ui-widget ui-corner-all settings_button">Re-enable QuickSync</a>
{% else %}
<a href="/settings/toggle-quicksync" class="ui-button ui-widget ui-corner-all settings_button">Disable QuickSync</a>
{% endif %}
<div class="divider"></div>
<div class="settings_block_subheader">Reset Blockchain</div>
If bitcoind is having issues, you can restart from the initial state right after QuickSync completed. This will take several hours.
<br/>
@ -330,7 +341,7 @@
<div class="settings_block_header">Developer</div>
<div class="settings_block_subheader">Uploader Device</div>
This disables most features and prioritize sharing QuickSync files.
This disables most features and prioritize sharing QuickSync files. It can be reversed later.
<br/>
{% if is_uploader_device %}
<a href="/settings/toggle-uploader" class="ui-button ui-widget ui-corner-all settings_button">Disable Uploader Device</a>