Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LNbits 0.12.x fixes #854

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rootfs/standard/etc/systemd/system/lnbits.service
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ ExecStartPre=/usr/bin/service_scripts/pre_lnbits.sh
WorkingDirectory=/opt/mynode/lnbits

ExecStart=/usr/bin/docker run --rm \
--name lnbits-legend \
--name lnbits \
-p 5000:5000 \
--volume /mnt/hdd/mynode/lnbits/.env:/app/.env \
--volume /mnt/hdd/mynode/lnbits/:/app/data \
--volume /mnt/hdd/mynode/lnd/tls.cert:/app/tls.cert \
--volume /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon:/app/admin.macaroon \
--add-host=host.docker.internal:host-gateway \
lnbits-legend
ExecStop=/usr/bin/docker stop -t 2 lnbits-legend
lnbits
ExecStop=/usr/bin/docker stop -t 2 lnbits

User=bitcoin
Group=bitcoin
Expand Down
2 changes: 1 addition & 1 deletion rootfs/standard/usr/bin/mynode_docker_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ while true; do
# Handled in pre_lnbits.sh

# Build lnbits docker container
docker build --no-cache -t lnbits-legend .
docker build --no-cache -t lnbits .

echo $LNBITS_VERSION > $LNBITS_VERSION_FILE
fi
Expand Down
43 changes: 29 additions & 14 deletions rootfs/standard/usr/bin/service_scripts/pre_lnbits.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
#!/bin/bash

set -x
source /usr/share/mynode/mynode_app_versions.sh

# Copy config file
if [ ! -f /mnt/hdd/mynode/lnbits/.env ]; then
cp /usr/share/mynode/lnbits.env /mnt/hdd/mynode/lnbits/.env
# Delete old myNode .env file created before 0.12.x
if [ -f /usr/share/mynode/lnbits.env ]; then
rm -f /usr/share/mynode/lnbits.env
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not get rid of this file since I can control it a bit better and reference the config. Can it just be updated with the latest version from the lnbits repo? If I do have to put in default settings, this file (/usr/share/mynode/lnbits/env) is a nice way to do it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix the way you suggested

fi

# if current LNbits version config is missign create .env from .env.example
if [ ! -f /mnt/hdd/mynode/lnbits/update_config_$LNBITS_VERSION ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, I would create a version number to track config updates so that it doesn't update automatically each upgrade / lnbits version change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the .env template be updated on each update so new options and defaults would be corrected on update too?

There are version files from Application Management related to installed, latest and available version. Could those be used as reference here too?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It normally doesn't need to be updated for each new release. Normally, the software should account for "missing" settings in the config file to use the default anyway. Keeping the file around makes it easy to update the default settings and control how the app runs. Those files just control the application version and not the settings files. There are examples in a few places, like pre_rtl.sh.

RTL_CONFIG_UPDATE_NUM=1
if [ ! -f /mnt/hdd/mynode/rtl/update_settings_$RTL_CONFIG_UPDATE_NUM ]; then
    cp -f /usr/share/mynode/RTL-Config.json /mnt/hdd/mynode/rtl/RTL-Config.json
    touch /mnt/hdd/mynode/rtl/update_settings_$RTL_CONFIG_UPDATE_NUM
fi

rm -f /mnt/hdd/mynode/lnbits/update_config_*
touch /mnt/hdd/mynode/lnbits/update_config_$LNBITS_VERSION

cp -f /opt/mynode/lnbits/.env.example /mnt/hdd/mynode/lnbits/.env
chown bitcoin:bitcoin /mnt/hdd/mynode/lnbits/.env

# debug Disable
sed -i "s|^DEBUG=.*|DEBUG=false|g" /mnt/hdd/mynode/lnbits/.env
# debug Enable
# sed -i "s|^DEBUG=.*|DEBUG=true|g" /mnt/hdd/mynode/lnbits/.env

# ADMIN_UI Disable
sed -i "s|^LNBITS_ADMIN_UI=.*|LNBITS_ADMIN_UI=false|g" /mnt/hdd/mynode/lnbits/.env
# ADMIN_UI Enable
# sed -i "s|^LNBITS_ADMIN_UI=.*|LNBITS_ADMIN_UI=true|g" /mnt/hdd/mynode/lnbits/.env

# Update env with mynode lnd REST ip and port
sed -i "s|^LND_REST_ENDPOINT=.*|LND_REST_ENDPOINT=https\:\/\/172.17.0.1:10080\/|g" /mnt/hdd/mynode/lnbits/.env

# Update env with files mapped in lnbits.service
sed -i "s|^LND_REST_CERT=.*|LND_REST_CERT=\"/app/tls.cert\"|g" /mnt/hdd/mynode/lnbits/.env
sed -i "s|^LND_REST_MACAROON=.*|LND_REST_MACAROON=\"/app/admin.macaroon\"|g" /mnt/hdd/mynode/lnbits/.env
fi

# Force update of LNBits config file (increment to force new update)
# LNBITS_CONFIG_UPDATE_NUM=1
# if [ ! -f /mnt/hdd/mynode/lnbits/update_config_$LNBITS_CONFIG_UPDATE_NUM ]; then
# cp -f /usr/share/mynode/lnbits.env /mnt/hdd/mynode/lnbits/.env
# chown bitcoin:bitcoin /mnt/hdd/mynode/lnbits/.env
# touch /mnt/hdd/mynode/lnbits/update_config_$LNBITS_CONFIG_UPDATE_NUM
# fi

# Generate hex macaroons
#macaroonAdminHex=$(xxd -ps -u -c 1000 /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon)

# Update env file
sed -i "s|^LND_REST_MACAROON=.*|LND_REST_MACAROON=\"/app/admin.macaroon\"|g" /mnt/hdd/mynode/lnbits/.env
77 changes: 0 additions & 77 deletions rootfs/standard/usr/share/mynode/lnbits.env

This file was deleted.

13 changes: 13 additions & 0 deletions rootfs/standard/var/pynode/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,19 @@ def clear_mempool_cache():
os.system("sync")
os.system("systemctl restart mempool")

#==================================
# LNbits Functions
#==================================
def delete_lnbits_settings():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't think this would work. It looks like this launches a new container rather than running a command in the existing lnbits container.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried it? It may work by launching a second container. Alternatively, you could exec into the running container to run the command, but I guess that would only clear the settings if lnbits was actively running.

os.system("rm -rf /mnt/hdd/mynode/lnbits/.super_user")
os.system("/usr/bin/docker run --rm \
--name lnbits-delete-settings \
--volume /mnt/hdd/mynode/lnbits/.env:/app/.env \
--volume /mnt/hdd/mynode/lnbits/:/app/data \
lnbits poetry run lnbits-cli delete-settings")
if is_service_enabled("lnbits"):
restart_service("lnbits")

#==================================
# Specter Functions
#==================================
Expand Down
20 changes: 19 additions & 1 deletion rootfs/standard/var/www/mynode/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,22 @@ def api_get_usb_info():
data["status"] = "success"
except Exception as e:
data["data"] = str(e)
return generate_api_json_response(data)
return generate_api_json_response(data)

@mynode_api.route("/api/get_lnbits_superuser")
def api_get_lnbits_superuser():
check_logged_in()

data = {}
data["status"] = "error"
data["data"] = "UNKNOWN"
try:
info = ""

info += to_string(subprocess.check_output("cat /mnt/hdd/mynode/lnbits/.super_user", shell=True))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this file that stored the super_user info get created? I only see it getting read/deleted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it looks like it file is created by lnbits.

info += "\n"
data["data"] = info
data["status"] = "success"
except Exception as e:
data["data"] = str(e)
return generate_api_json_response(data)
10 changes: 10 additions & 0 deletions rootfs/standard/var/www/mynode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,16 @@ def reset_thunderhub_config_page():
flash("Thunderhub Configuration Reset", category="message")
return redirect("/settings")

@mynode_settings.route("/settings/delete-lnbits-settings")
def delete_lnbits_settings_page():
check_logged_in()

t = Timer(10.0, delete_lnbits_settings)
t.start()

flash("LNbits Settings Deleted", category="message")
return redirect("/settings")

@mynode_settings.route("/settings/reset-specter-config")
def reset_specter_config_page():
check_logged_in()
Expand Down
30 changes: 30 additions & 0 deletions rootfs/standard/var/www/mynode/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,18 @@
$('#loading_spinner_overlay').fadeIn();
window.location.href='/settings/toggle_setting?name=torify_apt_get&enable='+val
});

$("#run-lnbits-cli-superuser").on("click", function() {
$("#run-lnbits-cli-superuser").prop("disabled",true);
$("#run-lnbits-cli-superuser-result").html("Loading...");
$.get("/api/get_lnbits_superuser")
.done(function( data ) {
$("#run-lnbits-cli-superuser").prop("disabled",false);
$("#run-lnbits-cli-superuser-result").html( data["data"] );
}
);
});

});

function hideAllUpgradeLogs() {
Expand Down Expand Up @@ -1215,6 +1227,24 @@
</div>


<div class="settings_block">
<a id="lnbits"></a>
<div class="settings_block_header">LNbits</div>

<div class="settings_block_subheader">Reset LNbits Settings</div>
This will delete your LNbits settings from database. This should not impact users, wallets and installed extension data stored in LNbits. When applied LNbits will read its default settings from .env file to database. Use this also if you need reset super user username and password.
<br/>
<a href="/settings/delete-lnbits-settings" class="ui-button ui-widget ui-corner-all settings_button">Delete Settings</a>

<div class="divider"></div>

<div class="settings_block_subheader">Show LNbits superuser ID</div>
Run lnbits-cli superuser command and show usr ID. It is needed to access LNbits admin UI.
<br/>
<button id="run-lnbits-cli-superuser" class="ui-button ui-widget ui-corner-all settings_button">Show superuser ID</button>
<pre id="run-lnbits-cli-superuser-result"></pre>
</div>

<div class="settings_block">
<a id="specter"></a>
<div class="settings_block_header">Specter</div>
Expand Down