From ea90b2bcfe04816ff0954218a36bcf9f591bfbfc Mon Sep 17 00:00:00 2001 From: cryptosharks131 Date: Wed, 22 Sep 2021 23:26:05 -0400 Subject: [PATCH] Move remaining files to parent folder to access settings variables and update docs --- README.md | 13 +++++++++---- gui/delete_payments.py => delete_payments.py | 9 +++++---- gui/jobs.py => jobs.py | 13 +++++++------ gui/keysend.py => keysend.py | 9 +++++---- gui/rebalancer.py => rebalancer.py | 17 +++++++++-------- systemd.md | 12 ++++++------ systemd.sh | 12 ++++++------ 7 files changed, 47 insertions(+), 38 deletions(-) rename gui/delete_payments.py => delete_payments.py (76%) rename gui/jobs.py => jobs.py (96%) rename gui/keysend.py => keysend.py (89%) rename gui/rebalancer.py => rebalancer.py (94%) diff --git a/README.md b/README.md index 0844274..6a1f386 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Lite GUI web interface to analyze lnd data and manage your node with automation. 6. Initialize a settings.py file for your django site `.venv/bin/python initialize.py` 7. Migrate all database objects `.venv/bin/python manage.py migrate` 8. Run the server via chosen webserver or via python development server `.venv/bin/python manage.py runserver :80` -9. Generate some initial data for your web GUI `.venv/bin/python gui/jobs.py` +9. Generate some initial data for your web GUI `.venv/bin/python jobs.py` -If you are not using the default path for LND `~/.lnd` you can add a custom path in the django settings file `lndg/settings.py` +Note: If you are not using the default path for LND `~/.lnd` you can add a custom path in the django settings file `lndg/settings.py` ## Updating 1. Make sure you are in the lndg folder `cd lndg` @@ -20,10 +20,15 @@ If you are not using the default path for LND `~/.lnd` you can add a custom path 3. Migrate any database changes `.venv/bin/python manage.py migrate` ## Backend Data Refreshes and Automated Rebalancing -The files `jobs.py` and `rebalancer.py` inside lndg/gui/ serve to update the backend database with the most up to date information and rebalance any channels based on your lndg dashboard settings and requests. A refresh interval of at least 15-30 seconds is recommended for the best user experience. +The files `jobs.py` and `rebalancer.py` inside lndg/gui/ serve to update the backend database with the most up to date information and rebalance any channels based on your lndg dashboard settings and requests. A refresh interval of at least 15-30 seconds is recommended for the best user experience. -You can find instructions on settings these files up to run in the background via systemd [here](https://github.com/cryptosharks131/lndg/blob/master/systemd.md). +You can find instructions on settings these files up to run in the background via systemd [here](https://github.com/cryptosharks131/lndg/blob/master/systemd.md). +If you are familiar with crontab, this is also an option for setting up these files to run on a frequent basis, however it only has a resolution of 1 minute. +A bash script has also been included to install the systemd setup. `sudo bash systemd.sh` +## Nginx Webserver +If you would like to serve the dashboard at all times, it is recommended to setup a proper production webserver to host the site. +A bash script has been included to help aide in the setup of a nginx webserver. `sudo bash nginx.sh` ## API Backend The following data can be accessed at the /api endpoint: `payments`, `invoices`, `forwards`, `channels`, and `rebalancer` diff --git a/gui/delete_payments.py b/delete_payments.py similarity index 76% rename from gui/delete_payments.py rename to delete_payments.py index 07ef0ff..adac4a3 100644 --- a/gui/delete_payments.py +++ b/delete_payments.py @@ -1,17 +1,18 @@ import os, codecs, grpc -from lnd_deps import lightning_pb2 as ln -from lnd_deps import lightning_pb2_grpc as lnrpc +from lndg import settings +from gui.lnd_deps import lightning_pb2 as ln +from gui.lnd_deps import lightning_pb2_grpc as lnrpc #Define lnd connection for repeated use def lnd_connect(): #Open connection with lnd via grpc - with open(os.path.expanduser('~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon'), 'rb') as f: + with open(os.path.expanduser(settings.LND_DIR_PATH + '/data/chain/bitcoin/mainnet/admin.macaroon'), 'rb') as f: macaroon_bytes = f.read() macaroon = codecs.encode(macaroon_bytes, 'hex') def metadata_callback(context, callback): callback([('macaroon', macaroon)], None) os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA' - cert = open(os.path.expanduser('~/.lnd/tls.cert'), 'rb').read() + cert = open(os.path.expanduser(settings.LND_DIR_PATH + '/tls.cert'), 'rb').read() cert_creds = grpc.ssl_channel_credentials(cert) auth_creds = grpc.metadata_call_credentials(metadata_callback) creds = grpc.composite_channel_credentials(cert_creds, auth_creds) diff --git a/gui/jobs.py b/jobs.py similarity index 96% rename from gui/jobs.py rename to jobs.py index 40faf65..528f2cd 100644 --- a/gui/jobs.py +++ b/jobs.py @@ -3,10 +3,10 @@ from django.conf import settings from django.db.models import Max from pathlib import Path from datetime import datetime -from lnd_deps import lightning_pb2 as ln -from lnd_deps import lightning_pb2_grpc as lnrpc +from gui.lnd_deps import lightning_pb2 as ln +from gui.lnd_deps import lightning_pb2_grpc as lnrpc -BASE_DIR = Path(__file__).resolve().parent.parent +BASE_DIR = Path(__file__).resolve().parent settings.configure( DATABASES = { 'default': { @@ -16,7 +16,8 @@ settings.configure( } ) django.setup() -from models import Payments, PaymentHops, Invoices, Forwards, Channels, Peers +from lndg import settings +from gui.models import Payments, PaymentHops, Invoices, Forwards, Channels, Peers def update_payments(stub): #Remove anything in-flight so we can get most up to date status @@ -192,13 +193,13 @@ def reconnect_peers(stub): def lnd_connect(): #Open connection with lnd via grpc - with open(os.path.expanduser('~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon'), 'rb') as f: + with open(os.path.expanduser(settings.LND_DIR_PATH + '/data/chain/bitcoin/mainnet/admin.macaroon'), 'rb') as f: macaroon_bytes = f.read() macaroon = codecs.encode(macaroon_bytes, 'hex') def metadata_callback(context, callback): callback([('macaroon', macaroon)], None) os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA' - cert = open(os.path.expanduser('~/.lnd/tls.cert'), 'rb').read() + cert = open(os.path.expanduser(settings.LND_DIR_PATH + '/tls.cert'), 'rb').read() cert_creds = grpc.ssl_channel_credentials(cert) auth_creds = grpc.metadata_call_credentials(metadata_callback) creds = grpc.composite_channel_credentials(cert_creds, auth_creds) diff --git a/gui/keysend.py b/keysend.py similarity index 89% rename from gui/keysend.py rename to keysend.py index eab4ae7..9048c96 100644 --- a/gui/keysend.py +++ b/keysend.py @@ -1,17 +1,18 @@ import os, codecs, grpc, secrets from hashlib import sha256 -from lnd_deps import router_pb2 as lnr -from lnd_deps import router_pb2_grpc as lnrouter +from lndg import settings +from gui.lnd_deps import router_pb2 as lnr +from gui.lnd_deps import router_pb2_grpc as lnrouter def lnd_connect(): #Open connection with lnd via grpc - with open(os.path.expanduser('~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon'), 'rb') as f: + with open(os.path.expanduser(settings.LND_DIR_PATH + '/data/chain/bitcoin/mainnet/admin.macaroon'), 'rb') as f: macaroon_bytes = f.read() macaroon = codecs.encode(macaroon_bytes, 'hex') def metadata_callback(context, callback): callback([('macaroon', macaroon)], None) os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA' - cert = open(os.path.expanduser('~/.lnd/tls.cert'), 'rb').read() + cert = open(os.path.expanduser(settings.LND_DIR_PATH + '/tls.cert'), 'rb').read() cert_creds = grpc.ssl_channel_credentials(cert) auth_creds = grpc.metadata_call_credentials(metadata_callback) creds = grpc.composite_channel_credentials(cert_creds, auth_creds) diff --git a/gui/rebalancer.py b/rebalancer.py similarity index 94% rename from gui/rebalancer.py rename to rebalancer.py index 56838c2..a582620 100644 --- a/gui/rebalancer.py +++ b/rebalancer.py @@ -3,12 +3,12 @@ from django.conf import settings from django.db.models import Sum from pathlib import Path from datetime import datetime -from lnd_deps import lightning_pb2 as ln -from lnd_deps import lightning_pb2_grpc as lnrpc -from lnd_deps import router_pb2 as lnr -from lnd_deps import router_pb2_grpc as lnrouter +from gui.lnd_deps import lightning_pb2 as ln +from gui.lnd_deps import lightning_pb2_grpc as lnrpc +from gui.lnd_deps import router_pb2 as lnr +from gui.lnd_deps import router_pb2_grpc as lnrouter -BASE_DIR = Path(__file__).resolve().parent.parent +BASE_DIR = Path(__file__).resolve().parent settings.configure( DATABASES = { 'default': { @@ -18,18 +18,19 @@ settings.configure( } ) django.setup() -from models import Rebalancer, Channels, LocalSettings +from lndg import settings +from gui.models import Rebalancer, Channels, LocalSettings #Define lnd connection for repeated use def lnd_connect(): #Open connection with lnd via grpc - with open(os.path.expanduser('~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon'), 'rb') as f: + with open(os.path.expanduser(settings.LND_DIR_PATH + '/data/chain/bitcoin/mainnet/admin.macaroon'), 'rb') as f: macaroon_bytes = f.read() macaroon = codecs.encode(macaroon_bytes, 'hex') def metadata_callback(context, callback): callback([('macaroon', macaroon)], None) os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA' - cert = open(os.path.expanduser('~/.lnd/tls.cert'), 'rb').read() + cert = open(os.path.expanduser(settings.LND_DIR_PATH + '/tls.cert'), 'rb').read() cert_creds = grpc.ssl_channel_credentials(cert) auth_creds = grpc.metadata_call_credentials(metadata_callback) creds = grpc.composite_channel_credentials(cert_creds, auth_creds) diff --git a/systemd.md b/systemd.md index c5e9586..8cc0452 100644 --- a/systemd.md +++ b/systemd.md @@ -4,11 +4,11 @@ You will need to fill in the proper username below in the paths marked `/lndg/gui/jobs.sh` +`nano /home//lndg/jobs.sh` ``` #!/bin/bash -/home//lndg/.venv/bin/python /home//lndg/gui/jobs.py +/home//lndg/.venv/bin/python /home//lndg/jobs.py ``` Create a service file for `jobs.py`, copying the contents below to the file and filling in the user you would like this to run under. `nano /etc/systemd/system/jobs-lndg.service` @@ -18,7 +18,7 @@ Description=Run Jobs For Lndg [Service] User= Group= -ExecStart=/usr/bin/bash /home//lndg/gui/jobs.sh +ExecStart=/usr/bin/bash /home//lndg/jobs.sh StandardError=append:/var/log/lnd_jobs_error.log ``` @@ -40,11 +40,11 @@ Enable the timer to run the jobs service file at the specified interval. ## Rebalancer Runs Create a simple bash file to call `rebalancer.py`, copying the contents below to the file. -`nano /home//lndg/gui/rebalancer.sh` +`nano /home//lndg/rebalancer.sh` ``` #!/bin/bash -/home//lndg/.venv/bin/python /home//lndg/gui/rebalancer.py +/home//lndg/.venv/bin/python /home//lndg/rebalancer.py ``` Create a service file for `rebalancer.py`, copying the contents below to the file and filling in the user you would like this to run under. `nano /etc/systemd/system/rebalancer-lndg.service` @@ -54,7 +54,7 @@ Description=Run Rebalancer For Lndg [Service] User= Group= -ExecStart=/usr/bin/bash /home//lndg/gui/rebalancer.sh +ExecStart=/usr/bin/bash /home//lndg/rebalancer.sh StandardError=append:/var/log/lnd_rebalancer_error.log RuntimeMaxSec=3600 ``` diff --git a/systemd.sh b/systemd.sh index 667d44c..ad1cb1c 100644 --- a/systemd.sh +++ b/systemd.sh @@ -4,10 +4,10 @@ RED='\033[0;31m' NC='\033[0m' function configure_jobs() { - cat << EOF > /home/$INSTALL_USER/lndg/gui/jobs.sh + cat << EOF > /home/$INSTALL_USER/lndg/jobs.sh #!/bin/bash -/home/$INSTALL_USER/lndg/.venv/bin/python /home/$INSTALL_USER/lndg/gui/jobs.py +/home/$INSTALL_USER/lndg/.venv/bin/python /home/$INSTALL_USER/lndg/jobs.py EOF cat << EOF > /etc/systemd/system/jobs-lndg.service @@ -16,7 +16,7 @@ Description=Run Jobs For Lndg [Service] User=$INSTALL_USER Group=$INSTALL_USER -ExecStart=/usr/bin/bash /home/$INSTALL_USER/lndg/gui/jobs.sh +ExecStart=/usr/bin/bash /home/$INSTALL_USER/lndg/jobs.sh StandardError=append:/var/log/lnd_jobs_error.log EOF @@ -33,10 +33,10 @@ EOF } function configure_rebalancer() { - cat << EOF > /home/$INSTALL_USER/lndg/gui/rebalancer.sh + cat << EOF > /home/$INSTALL_USER/lndg/rebalancer.sh #!/bin/bash -/home/$INSTALL_USER/lndg/.venv/bin/python /home/$INSTALL_USER/lndg/gui/jobs.py +/home/$INSTALL_USER/lndg/.venv/bin/python /home/$INSTALL_USER/lndg/jobs.py EOF cat << EOF > /etc/systemd/system/rebalancer-lndg.service @@ -45,7 +45,7 @@ Description=Run Rebalancer For Lndg [Service] User=$INSTALL_USER Group=$INSTALL_USER -ExecStart=/usr/bin/bash /home/$INSTALL_USER/lndg/gui/rebalancer.sh +ExecStart=/usr/bin/bash /home/$INSTALL_USER/lndg/rebalancer.sh StandardError=append:/var/log/lnd_rebalancer_error.log RuntimeMaxSec=3600 EOF