diff --git a/rootfs/standard/usr/share/mynode_apps/albyhub/CHANGES by claude.txt b/rootfs/standard/usr/share/mynode_apps/albyhub/CHANGES by claude.txt new file mode 100644 index 00000000..d663e86b --- /dev/null +++ b/rootfs/standard/usr/share/mynode_apps/albyhub/CHANGES by claude.txt @@ -0,0 +1,415 @@ +https://claude.ai/chat/c185814a-8984-42cc-b28e-1dad7c75950a + +--- + +Perfect! Now I can see the existing structure. Let me propose changes that work with what you already have: +Proposed Changes for PR #975 +1. Update pre_albyhub.sh +Create this file to generate the env file with proper phoenixd authentication: +#!/bin/bash +# File: rootfs/standard/usr/bin/service_scripts/pre_albyhub.sh + +source /usr/share/mynode/mynode_config.sh + +# Paths +ENV_FILE="/mnt/hdd/mynode/albyhub/albyhub.env" +PHOENIXD_FLAG="/mnt/hdd/mynode/settings/albyhub_conf_phoenixd" +PHOENIXD_CONFIG="/mnt/hdd/mynode/phoenixd/phoenix.conf" + +# Create directories +mkdir -p /mnt/hdd/mynode/albyhub +mkdir -p /mnt/hdd/mynode/settings + +# Determine which backend to use +if [ -f "$PHOENIXD_FLAG" ]; then + # Verify phoenixd is available + if ! systemctl is-active --quiet phoenixd; then + echo "Warning: phoenixd service is not running, falling back to LND" + rm -f "$PHOENIXD_FLAG" + USE_PHOENIXD=false + elif [ ! -f "$PHOENIXD_CONFIG" ]; then + echo "Warning: phoenixd config not found, falling back to LND" + rm -f "$PHOENIXD_FLAG" + USE_PHOENIXD=false + else + USE_PHOENIXD=true + fi +else + USE_PHOENIXD=false +fi + +# Generate environment file +if [ "$USE_PHOENIXD" = true ]; then + # Extract phoenixd password from config + PHOENIXD_PASSWORD=$(grep -E "^http-password=" "$PHOENIXD_CONFIG" | cut -d"=" -f2) + + cat > "$ENV_FILE" << EOF +WORK_DIR=/data +LN_BACKEND_TYPE=PHOENIX +PHOENIXD_ADDRESS=http://172.17.0.1:9740 +PHOENIXD_AUTHORIZATION=$PHOENIXD_PASSWORD +ENABLE_ADVANCED_SETUP=false +EOF +else + cat > "$ENV_FILE" << EOF +WORK_DIR=/data +LN_BACKEND_TYPE=LND +LND_ADDRESS=host.docker.internal:10009 +LND_CERT_FILE=/lnd/tls.cert +LND_MACAROON_FILE=/lnd/admin.macaroon +ENABLE_ADVANCED_SETUP=false +EOF +fi + +# Set permissions +chmod 600 "$ENV_FILE" +chown bitcoin:bitcoin "$ENV_FILE" +2. Update albyhub.service +Simplify to use the env file: +# File: rootfs/standard/etc/systemd/system/albyhub.service +[Unit] +Description=albyhub +Wants=www.service docker_images.service +After=www.service docker_images.service + +[Service] +WorkingDirectory=/opt/mynode/albyhub +ExecStartPre=/usr/bin/is_not_shutting_down.sh +ExecStartPre=/bin/bash /usr/bin/service_scripts/pre_albyhub.sh +ExecStart=/bin/bash -c 'docker run --rm \ + --name albyhub \ + --publish 3040:8080 \ + --add-host=host.docker.internal:host-gateway \ + --volume /mnt/hdd/mynode/albyhub:/data \ + --volume /mnt/hdd/mynode/lnd/tls.cert:/lnd/tls.cert:ro \ + --volume /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon:/lnd/admin.macaroon:ro \ + --env-file /mnt/hdd/mynode/albyhub/albyhub.env \ + albyhub' +ExecStartPost=/bin/bash -c 'if [ -f /usr/bin/service_scripts/post_albyhub.sh ]; then /bin/bash /usr/bin/service_scripts/post_albyhub.sh; fi' +ExecStop=docker stop -t 2 albyhub +User=bitcoin +Group=bitcoin +Type=simple +TimeoutSec=120 +Restart=always +RestartSec=60 +SyslogIdentifier=albyhub + +[Install] +WantedBy=multi-user.target +3. Create albyhub_utils.py +Add helper functions for the existing albyhub.py: +# File: rootfs/standard/var/www/mynode/albyhub_utils.py +import os +import subprocess + +PHOENIXD_FLAG = "/mnt/hdd/mynode/settings/albyhub_conf_phoenixd" +ALBYHUB_DATA_DIR = "/mnt/hdd/mynode/albyhub" +PHOENIXD_CONFIG = "/mnt/hdd/mynode/phoenixd/phoenix.conf" + +def get_albyhub_backend(): + """Get current AlbyHub backend (lnd or phoenixd)""" + if os.path.isfile(PHOENIXD_FLAG): + return "phoenixd" + return "lnd" + +def is_phoenixd_available(): + """Check if phoenixd is installed and running""" + try: + # Check if service exists and is active + result = subprocess.run(['systemctl', 'is-active', 'phoenixd'], + capture_output=True, text=True, timeout=5) + if result.returncode != 0: + return False + + # Check if config file exists + if not os.path.isfile(PHOENIXD_CONFIG): + return False + + return True + except: + return False + +def set_albyhub_backend(backend): + """ + Set AlbyHub backend to 'lnd' or 'phoenixd' + Returns: (success, message) + """ + if backend == "phoenixd": + if not is_phoenixd_available(): + return (False, "phoenixd is not installed or not running. Please enable phoenixd first.") + + # Create phoenixd flag + try: + os.makedirs(os.path.dirname(PHOENIXD_FLAG), exist_ok=True) + open(PHOENIXD_FLAG, 'a').close() + return (True, "Backend switched to phoenixd") + except Exception as e: + return (False, f"Failed to set phoenixd backend: {str(e)}") + + elif backend == "lnd": + # Remove phoenixd flag + try: + if os.path.exists(PHOENIXD_FLAG): + os.remove(PHOENIXD_FLAG) + return (True, "Backend switched to LND") + except Exception as e: + return (False, f"Failed to set LND backend: {str(e)}") + + return (False, "Invalid backend specified") + +def requires_albyhub_reset(new_backend): + """Check if switching to new_backend requires data reset""" + current_backend = get_albyhub_backend() + return current_backend != new_backend + +def backup_albyhub_data(): + """Create a backup of AlbyHub data""" + try: + import datetime + timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") + backup_dir = f"/mnt/hdd/mynode/albyhub_backup_{timestamp}" + + if os.path.exists(ALBYHUB_DATA_DIR): + subprocess.run(['cp', '-r', ALBYHUB_DATA_DIR, backup_dir], check=True) + subprocess.run(['chown', '-R', 'bitcoin:bitcoin', backup_dir], check=True) + return (True, f"Backup created at {backup_dir}") + return (True, "No data to backup") + except Exception as e: + return (False, f"Backup failed: {str(e)}") + +def reset_albyhub_data(): + """Reset AlbyHub data directory (warning: destructive!)""" + try: + if os.path.exists(ALBYHUB_DATA_DIR): + # Remove all files in the directory + for item in os.listdir(ALBYHUB_DATA_DIR): + item_path = os.path.join(ALBYHUB_DATA_DIR, item) + if os.path.isfile(item_path): + os.remove(item_path) + elif os.path.isdir(item_path): + subprocess.run(['rm', '-rf', item_path], check=True) + + # Recreate directory with proper permissions + os.makedirs(ALBYHUB_DATA_DIR, exist_ok=True) + subprocess.run(['chown', 'bitcoin:bitcoin', ALBYHUB_DATA_DIR], check=True) + return (True, "AlbyHub data reset successfully") + except Exception as e: + return (False, f"Failed to reset data: {str(e)}") +4. Update existing albyhub.py +Modify to add backend switching routes: +# File: rootfs/standard/var/www/mynode/albyhub.py +from flask import Blueprint, render_template, redirect, request, flash +from user_management import check_logged_in +from enable_disable_functions import * +from device_info import * +from application_info import * +from systemctl_info import * +import albyhub_utils +import subprocess +import os + +mynode_albyhub = Blueprint('mynode_albyhub',__name__) + +### Page functions (have prefix /app/ +{% extends "base.html" %} + +{% block content %} +
+
{{ app.name }}
+
+ +
+ +
+
Status
+
+
Service Status: {{ app_status }}
+
Lightning Backend: {{ current_backend|upper }}
+
+
+ + +
+
Lightning Backend Configuration
+ +
+ {% if not phoenixd_available %} +
+ ⚠️ Warning: phoenixd is not installed or not running. Only LND backend is available. +
+ {% endif %} + +
+
+ + + +
+ + + +
+ ⚠️ IMPORTANT: Switching backends will reset all AlbyHub data. +
    +
  • A backup will be created automatically
  • +
  • You will need to set up AlbyHub again
  • +
  • All channels and balances will be lost
  • +
+
+ + +
+
+
+ + + + + +
+
About {{ app.name }}
+
+ {{ app.description|safe }} +
+
+
+ + +{% endblock %} +Summary of Changes +This implementation: +1. ✅ Uses Taylor's env file approach - moves logic from service file to pre_albyhub.sh +2. ✅ Preserves your phoenixd authentication - extracts password from phoenix.conf exactly as your current implementation +3. ✅ Works with existing albyhub.py - extends it rather than replacing +4. ✅ Python-based UI switching - all backend switching logic in Python utilities +5. ✅ Proper safety checks - verifies phoenixd is running and config exists +6. ✅ User warnings - clear destructive action warnings with confirmation +7. ✅ Automatic backups - creates timestamped backup before switching +8. ✅ Follows MyNode patterns - uses existing structures and conventions + diff --git a/rootfs/standard/usr/share/mynode_apps/albyhub/albyhub.service b/rootfs/standard/usr/share/mynode_apps/albyhub/albyhub.service index 84f17585..c9c79b0d 100644 --- a/rootfs/standard/usr/share/mynode_apps/albyhub/albyhub.service +++ b/rootfs/standard/usr/share/mynode_apps/albyhub/albyhub.service @@ -11,20 +11,36 @@ WorkingDirectory=/opt/mynode/albyhub ExecStartPre=/usr/bin/is_not_shutting_down.sh ExecStartPre=/bin/bash -c 'if [ -f /usr/bin/service_scripts/pre_albyhub.sh ]; then /bin/bash /usr/bin/service_scripts/pre_albyhub.sh; fi' -ExecStart=docker run --rm \ - --name albyhub \ - --publish 3040:8080 \ - --add-host=host.docker.internal:host-gateway \ - --volume /mnt/hdd/mynode/albyhub:/data \ - --mount type=bind,src=/mnt/hdd/mynode/lnd/tls.cert,target=/lnd/tls.cert,readonly \ - --mount type=bind,src=/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon,target=/lnd/admin.macaroon,readonly \ - --env WORK_DIR="/data" \ - --env LN_BACKEND_TYPE="LND" \ - --env LND_ADDRESS="host.docker.internal:10009" \ - --env LND_CERT_FILE="/lnd/tls.cert" \ - --env LND_MACAROON_FILE="/lnd/admin.macaroon" \ - --env ENABLE_ADVANCED_SETUP=false \ - albyhub + +ExecStart=/bin/bash -c 'if [ ! -f /mnt/hdd/mynode/settings/albyhub_conf_phoenixd ]; then \ + docker run --rm \ + --name albyhub \ + --publish 3040:8080 \ + --add-host=host.docker.internal:host-gateway \ + --volume /mnt/hdd/mynode/albyhub:/data \ + --volume /mnt/hdd/mynode/lnd/tls.cert:/lnd/tls.cert \ + --volume /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon:/lnd/admin.macaroon \ + --env WORK_DIR="/data" \ + --env LN_BACKEND_TYPE=LND \ + --env LND_ADDRESS="host.docker.internal:10009" \ + --env LND_CERT_FILE="/lnd/tls.cert" \ + --env LND_MACAROON_FILE="/lnd/admin.macaroon" \ + --env ENABLE_ADVANCED_SETUP=false \ + albyhub; \ + else \ + docker run --rm \ + --name albyhub \ + --publish 3040:8080 \ + --add-host=host.docker.internal:host-gateway \ + --volume /mnt/hdd/mynode/albyhub:/data \ + --env WORK_DIR="/data" \ + --env LN_BACKEND_TYPE=PHOENIX \ + --env PHOENIXD_ADDRESS="http://172.17.0.1:9740" \ + --env PHOENIXD_AUTHORIZATION=$(grep -E "^http-password=" /mnt/hdd/mynode/phoenixd/phoenix.conf | cut -d"=" -f2) \ + --env ENABLE_ADVANCED_SETUP=false \ + albyhub; \ + fi' + ExecStartPost=/bin/bash -c 'if [ -f /usr/bin/service_scripts/post_albyhub.sh ]; then /bin/bash /usr/bin/service_scripts/post_albyhub.sh; fi' ExecStop=docker stop -t 2 albyhub @@ -37,4 +53,4 @@ RestartSec=60 SyslogIdentifier=albyhub [Install] -WantedBy=multi-user.target +WantedBy=multi-user.target \ No newline at end of file