Improve dynamic app install, add lndg

This commit is contained in:
Taylor Helsper 2022-04-28 23:07:13 -05:00
parent c8e5f3a6c6
commit ebe00046ab
8 changed files with 101 additions and 40 deletions

View File

@ -1,5 +1,16 @@
#!/bin/bash
chmod 640 /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon
sleep 10s
# Set folders +x so files can be navigated by bitcoin group
chmod +x /mnt/hdd/mynode/lnd/data || true
chmod +x /mnt/hdd/mynode/lnd/data/chain || true
chmod +x /mnt/hdd/mynode/lnd/data/chain/bitcoin || true
chmod +x /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet || true
# New files should be 640, if it already exists update it so bitcoin group can read macaroon
if [ -f /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon ]; then
chmod 640 /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon
fi
exit 0

View File

@ -1,5 +1,6 @@
{
"name": "LNDg",
"is_beta": true,
"short_name": "lndg",
"latest_version": "v1.0.5",
"linux_user": "lndg",
@ -11,8 +12,7 @@
"hide_status_icon": false,
"app_tile_default_status_text": "Lightning Tool",
"app_tile_running_status_text": "Running",
"app_tile_button_href": "/lndg",
"app_tile_button_text": "Info",
"app_tile_button_onclick": "open_app_in_new_tab({HTTP_PORT})",
"can_uninstall": true,
"can_enable_disable": true,
"show_on_application_page": true,

View File

@ -7,15 +7,17 @@ Wants=www.service docker_images.service
After=www.service docker_images.service
[Service]
WorkingDirectory=/opt/mynode/lndg
ExecStartPre=/usr/bin/is_not_shutting_down.sh
ExecStartPre=/bin/bash -c 'if [ -f /usr/bin/service_scripts/pre_lndg.sh ]; then /bin/bash /usr/bin/service_scripts/pre_lndg.sh; fi'
ExecStart=TODO
ExecStart=/bin/bash -c "/opt/mynode/lndg/.venv/bin/supervisord && /opt/mynode/lndg/.venv/bin/python manage.py runserver 0.0.0.0:8889"
ExecStartPost=/bin/bash -c 'if [ -f /usr/bin/service_scripts/post_lndg.sh ]; then /bin/bash /usr/bin/service_scripts/post_lndg.sh; fi'
ExecStop=TODO
#ExecStop=TODO
# Need new user
User=root
Group=root
User=lndg
Group=lndg
Type=simple
TimeoutSec=120
Restart=always

View File

@ -2,30 +2,25 @@
set -x
set -e
echo "==================== INSTALLING APP ===================="
# Helpful variables to add:
# VERSION?
# DOWNLOAD PATH TO TAR.GZ?
# PATH TO SD CARD FOLDER
# PATH TO DATA DRIVE FOLDER
#
# Install deps
virtualenv -p python3 .venv
.venv/bin/pip install -r requirements.txt
.venv/bin/pip install whitenoise
.venv/bin/pip install supervisor
echo "INSTALLING LNDG SCRIPT - START"
# Patch to store file locally
sed -i 's|/usr/local/etc/supervisord.conf|/opt/mynode/lndg/.venv/supervisord.conf|g' initialize.py
echo "====== User Info ======"
whoami
id
# Init LNDg
.venv/bin/python initialize.py --lnddir=/mnt/hdd/mynode/lnd --adminpw=bolt -wn -dx -sd --sduser=lndg
echo "====== ENV DATA ======"
env
# Patch supervisord config
mkdir -p logs
sed -i 's|/var/log|/opt/mynode/lndg/logs|g' .venv/supervisord.conf
echo "====== CURRENT FOLDER DATA ======"
pwd
ls -lsa
# Load initial data
.venv/bin/python jobs.py
echo "====== SLEEPING A BIT ======"
sleep 3s
echo "INSTALLING LNDG SCRIPT - END"
echo "==================== DONE INSTALLING APP ===================="

View File

@ -104,6 +104,10 @@ def get_app_latest_version_from_file(app):
def replace_app_info_variables(app_data, text):
text = text.replace("{VERSION}", app_data["latest_version"])
text = text.replace("{SHORT_NAME}", app_data["short_name"])
if app_data["http_port"] != None:
text = text.replace("{HTTP_PORT}", app_data["http_port"])
if app_data["https_port"] != None:
text = text.replace("{HTTPS_PORT}", app_data["https_port"])
return text
def initialize_application_defaults(app):
@ -149,9 +153,11 @@ def initialize_application_defaults(app):
if not "app_tile_default_status_text" in app: app["app_tile_default_status_text"] = ""
if not "app_tile_running_status_text" in app: app["app_tile_running_status_text"] = app["app_tile_default_status_text"]
if not "app_tile_button_href" in app: app["app_tile_button_href"] = "#"
if not "app_tile_button_onclick" in app: app["app_tile_button_onclick"] = ""
# Update fields that may use variables that need replacing, like {VERSION}, {SHORT_NAME}, etc...
app["targz_download_url"] = replace_app_info_variables(app, app["targz_download_url"])
app["app_tile_button_onclick"] = replace_app_info_variables(app, app["app_tile_button_onclick"])
return app
@ -462,11 +468,16 @@ def reset_custom_app_version_data():
## Single Application Actions
######################################################################################
def create_application_user(app_data):
log_message(" Running create_application_user...")
username = app_data["linux_user"]
if not linux_user_exists(username):
linux_create_user(username)
# Ensure user belongs to bitcoin group
add_user_to_group(username, "bitcoin")
def create_application_folders(app_data):
log_message(" Running create_application_folders...")
app_folder = app_data["install_folder"]
data_folder = app_data["storage_folder"]
@ -566,7 +577,7 @@ def init_dynamic_app(app_info):
app_name = app_info["short_name"]
app_dir = DYNAMIC_APPLICATIONS_FOLDER + "/" + app_name
log_message(" Loading " + app_name + "...")
os.system("cp -f {} {}".format(app_dir+"/app.service", "/etc/systemd/system/"+app_name+".service"))
os.system("cp -f {} {}".format(app_dir+"/"+app_name+".service", "/etc/systemd/system/"+app_name+".service"))
os.system("cp -f {} {}".format(app_dir+"/"+app_name+".png", "/var/www/mynode/static/images/app_icons/"+app_name+".png"))
if (os.path.isfile(app_dir+"/scripts/pre_"+app_name+".sh")):
os.system("cp -f {} {}".format(app_dir+"/scripts/pre_"+app_name+".sh", "/usr/bin/service_scripts/pre_"+app_name+".sh"))
@ -653,8 +664,8 @@ def upgrade_dynamic_apps(short_name="all"):
my_env["STORAGE_FOLDER"] = app_data["storage_folder"]
if app_data["install_env_vars"]:
for key in app_data["install_env_vars"]:
my_env["key"] = app_data["install_env_vars"][key]
subprocess.check_output("cd {}; /bin/bash /usr/bin/service_scripts/install_{}.sh 1>&2".format(app_data["install_folder"], app_name), shell=True, env=my_env)
my_env[key] = app_data["install_env_vars"][key]
subprocess.check_output("cd {}; sudo -u {} /bin/bash /usr/bin/service_scripts/install_{}.sh 1>&2".format(app_data["install_folder"], app_data["linux_user"], app_name), shell=True, env=my_env)
# Mark update latest version if success
log_message(" Upgrade success!")

View File

@ -350,4 +350,7 @@ def linux_create_user(username, make_home_folder=False):
dash_m = "-m"
cmd = "useradd {} -s /bin/bash {} || true".format(dash_m, username)
run_linux_cmd(cmd)
run_linux_cmd(cmd, print_command=True)
def add_user_to_group(username, group):
run_linux_cmd("adduser {} {}".format(username, group), print_command=True)

View File

@ -21,7 +21,10 @@
{% if electrs_active or ( not electrs_active and not app.requires_electrs ) %}
{% if not is_installing_docker_images or ( is_installing_docker_images and not app.requires_docker_image_installation ) %}
{% if app.is_enabled or not app.can_enable_disable %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="{{app.app_tile_button_href}}" id="{{app.short_name}}">{{app.app_tile_button_text}}</a>
<a class="ui-button ui-widget ui-corner-all mynode_button"
{% if app.app_tile_button_onclick != "" %} onclick="{{app.app_tile_button_onclick}}" {% endif %}
href="{{app.app_tile_button_href}}"
id="{{app.short_name}}">{{app.app_tile_button_text}}</a>
{% endif %}
{% if app.can_enable_disable %}
<a class="ui-button ui-widget ui-corner-all mynode_button" onclick="toggleEnabled('{{app.short_name}}')">

View File

@ -228,6 +228,13 @@
showing_lightning_details = !showing_lightning_details;
}
function is_using_tor() {
if (location.hostname.includes(".onion")) {
return true;
}
return false;
}
function open_new_mynode_tab(port, protocol="same") {
hostname=location.hostname
if (protocol == "same") {
@ -238,6 +245,42 @@
url = protocol+'//'+hostname+':'+port
window.open(url,'_blank');
}
function open_app_in_new_tab(http_port, https_port="NA", requires_https=false, custom_tor_address="NA", tor_http_port="80", tor_https_port="443") {
protocol=location.protocol
hostname=location.hostname
port_string=""
if (is_using_tor() && custom_tor_address != "NA") {
hostname="{{custom_tor_address}}"
// Use "default" port - either 80 or 443 for HTTP/HTTPS unless overriden
if (protocol == "http:" && tor_http_port != "80") {
port_string=":"+tor_http_port
}
if (protocol == "https:" && tor_https_port != "443") {
port_string=":"+tor_https_port
}
} else {
if (protocol == "http:" && http_port != "80") {
port_string=":"+http_port
}
if (protocol == "https:" && https_port != "443") {
port_string=":"+https_port
}
}
// If app is HTTP only
if (https_port == "NA") {
protocol = "http:"
port_string = ":"+http_port
if (is_using_tor() && custom_tor_address == "NA") {
port_string=":"+tor_http_port
}
}
url = protocol+'//'+hostname+port_string
window.open(url,'_blank');
}
// Update page function
@ -469,13 +512,6 @@
$(document).ready(function() {
$( document ).tooltip();
function is_using_tor() {
if (location.hostname.includes(".onion")) {
return true;
}
return false;
}
$("#lit").on("click", function() {
url = 'https://'+location.hostname+':8443'
window.open(url,'_blank');