From 0390a7b559b82016e8a5bb5b86eb84ae17b98aab Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Thu, 25 Jun 2020 23:30:17 -0500 Subject: [PATCH] Upgrade to Python 3.7.7; More lnbits foundation --- .../etc/systemd/system/lnbits.service | 31 +++++++++++++++++ rootfs/standard/usr/bin/mynode_firewall.sh | 1 + .../standard/usr/bin/mynode_post_upgrade.sh | 34 +++++++++++++++++-- .../standard/usr/bin/mynode_reinstall_app.sh | 2 ++ rootfs/standard/usr/bin/mynode_startup.sh | 5 +++ .../var/www/mynode/templates/settings.html | 1 + setup/setup_device.sh | 21 ++++++++---- 7 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 rootfs/standard/etc/systemd/system/lnbits.service diff --git a/rootfs/standard/etc/systemd/system/lnbits.service b/rootfs/standard/etc/systemd/system/lnbits.service new file mode 100644 index 00000000..f55100d4 --- /dev/null +++ b/rootfs/standard/etc/systemd/system/lnbits.service @@ -0,0 +1,31 @@ +# RTL service +# /etc/systemd/system/rtl.service + +[Unit] +Description=LNBits +Wants=bitcoind.service lnd.service +After=bitcoind.service lnd.service + +[Service] +ExecStartPre=/usr/bin/is_not_shutting_down.sh +ExecStartPre=/usr/bin/wait_on_lnd.sh +Environment=FLASK_ENV=development +WorkingDirectory=/opt/mynode/lnbits + +#ExecStart=/usr/local/bin/pipenv run flask run --host 0.0.0.0 +ExecStart=/bin/sh -c 'cd /opt/mynode/lnbits && /usr/local/bin/pipenv --python 3.7 run flask run --host 0.0.0.0' +#ExecStart=/bin/sh -c 'cd /opt/mynode/lnbits && python3 /usr/local/bin/pipenv --python 3.7 run gunicorn -b :5000 lnbits:app -k gevent' + +User=bitcoin +Group=bitcoin +Type=simple +LimitNOFILE=128000 +TimeoutSec=240 +Restart=always +RestartSec=60 +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=lnbits + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/rootfs/standard/usr/bin/mynode_firewall.sh b/rootfs/standard/usr/bin/mynode_firewall.sh index c1fa808b..73674e6a 100755 --- a/rootfs/standard/usr/bin/mynode_firewall.sh +++ b/rootfs/standard/usr/bin/mynode_firewall.sh @@ -36,6 +36,7 @@ ufw allow 3002 comment 'allow BTC RPC Explorer' ufw allow 3010 comment 'allow RTL' ufw allow 3020 comment 'allow Caravan' ufw allow 4080 comment 'allow Mempool' +ufw allow 5000 comment 'allow LNBits' ufw allow 5353 comment 'allow Avahi' ufw allow 8899 comment 'allow Whirlpool' ufw allow 50001 comment 'allow Electrum Server' diff --git a/rootfs/standard/usr/bin/mynode_post_upgrade.sh b/rootfs/standard/usr/bin/mynode_post_upgrade.sh index 85993777..747a0821 100755 --- a/rootfs/standard/usr/bin/mynode_post_upgrade.sh +++ b/rootfs/standard/usr/bin/mynode_post_upgrade.sh @@ -14,6 +14,9 @@ date # Delete ramlog to prevent ram issues rm -rf /var/log/* +# Create any necessary users +sudo adduser --disabled-password --gecos "" lnbits || true + # Check if upgrades use tor TORIFY="" if [ -f /mnt/hdd/mynode/settings/torify_apt_get ]; then @@ -56,7 +59,7 @@ $TORIFY apt-get -y install libatlas-base-dev libffi-dev libssl-dev glances pytho $TORIFY apt-get -y -qq install apt-transport-https ca-certificates $TORIFY apt-get -y install libgmp-dev automake libtool libltdl-dev libltdl7 $TORIFY apt-get -y install xorg chromium openbox lightdm openjdk-11-jre libevent-dev ncurses-dev -$TORIFY apt-get -y install libudev-dev libusb-1.0-0-dev python3-venv +$TORIFY apt-get -y install libudev-dev libusb-1.0-0-dev python3-venv gunicorn libsqlite3-dev # Make sure some software is removed apt-get -y purge ntp # (conflicts with systemd-timedatectl) @@ -67,6 +70,27 @@ apt-get -y purge chrony # (conflicts with systemd-timedatectl) pip install tzupdate virtualenv --no-cache-dir +# Update Python3 to 3.7.X +PYTHON_VERSION=3.7.7 +CURRENT_PYTHON3_VERSION=$(python3 --version) +if [[ "$CURRENT_PYTHON3_VERSION" != *"Python ${PYTHON_VERSION}"* ]]; then + mkdir -p /opt/download + cd /opt/download + rm -rf Python-* + + wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz -O python.tar.xz + tar xf python.tar.xz + + cd Python-* + ./configure + make -j4 + make install + cd ~ +else + echo "Python up to date" +fi + + # Install any pip3 software pip3 install python-bitcointx --no-cache-dir pip3 install gnureadline --no-cache-dir @@ -441,8 +465,12 @@ fi # sudo -u bitcoin mv lnbits-* lnbits # cd lnbits -# pipenv install lnd-grpc -# pipenv install --dev +# # Install with python 3.7 (Only use "pipenv install --python 3.7" once or it will rebuild the venv!) +# sudo -u bitcoin pipenv --python 3.7 install --dev +# sudo -u bitcoin pipenv run pip install python-dotenv +# sudo -u bitcoin pipenv run pip install -r requirements.txt +# sudo -u bitcoin pipenv run pip install lnd-grpc +# sudo -u bitcoin pipenv run flask migrate || true # mkdir -p /home/bitcoin/.mynode/ # chown -R bitcoin:bitcoin /home/bitcoin/.mynode/ diff --git a/rootfs/standard/usr/bin/mynode_reinstall_app.sh b/rootfs/standard/usr/bin/mynode_reinstall_app.sh index e069031d..187eb521 100755 --- a/rootfs/standard/usr/bin/mynode_reinstall_app.sh +++ b/rootfs/standard/usr/bin/mynode_reinstall_app.sh @@ -28,6 +28,8 @@ elif [ "$APP" = "caravan" ]; then rm -f /home/bitcoin/.mynode/.caravan_url elif [ "$APP" = "joinmarket" ]; then rm -f /home/bitcoin/.mynode/.joinmarket_url +elif [ "$APP" = "lnbits" ]; then + rm -f /home/bitcoin/.mynode/.lnbits_url elif [ "$APP" = "lndconnect" ]; then rm -f /home/bitcoin/.mynode/.lndconnect_url elif [ "$APP" = "lndhub" ]; then diff --git a/rootfs/standard/usr/bin/mynode_startup.sh b/rootfs/standard/usr/bin/mynode_startup.sh index b3899ed0..dbba1b48 100755 --- a/rootfs/standard/usr/bin/mynode_startup.sh +++ b/rootfs/standard/usr/bin/mynode_startup.sh @@ -131,6 +131,7 @@ mkdir -p /mnt/hdd/mynode/electrs mkdir -p /mnt/hdd/mynode/docker mkdir -p /mnt/hdd/mynode/rtl_backup mkdir -p /mnt/hdd/mynode/whirlpool +mkdir -p /mnt/hdd/mynode/lnbits mkdir -p /tmp/flask_uploads echo "drive_mounted" > $MYNODE_DIR/.mynode_status chmod 777 $MYNODE_DIR/.mynode_status @@ -308,6 +309,10 @@ USER=$(stat -c '%U' /mnt/hdd/mynode/whirlpool) if [ "$USER" != "bitcoin" ]; then chown -R bitcoin:bitcoin /mnt/hdd/mynode/whirlpool fi +USER=$(stat -c '%U' /mnt/hdd/mynode/lnbits) +if [ "$USER" != "bitcoin" ]; then + chown -R bitcoin:bitcoin /mnt/hdd/mynode/lnbits +fi USER=$(stat -c '%U' /mnt/hdd/mynode/redis) if [ "$USER" != "redis" ]; then chown -R redis:redis /mnt/hdd/mynode/redis diff --git a/rootfs/standard/var/www/mynode/templates/settings.html b/rootfs/standard/var/www/mynode/templates/settings.html index 69a17520..fd9e6b6c 100644 --- a/rootfs/standard/var/www/mynode/templates/settings.html +++ b/rootfs/standard/var/www/mynode/templates/settings.html @@ -816,6 +816,7 @@ + diff --git a/setup/setup_device.sh b/setup/setup_device.sh index 6722a847..e1a235ff 100755 --- a/setup/setup_device.sh +++ b/setup/setup_device.sh @@ -83,6 +83,10 @@ fi wget http://${SERVER_IP}:8000/${TARBALL} -O /tmp/rootfs.tar.gz +# Create any necessary users +sudo adduser --disabled-password --gecos "" lnbits || true + + # Add sources apt-get -y install apt-transport-https DEBIAN_VERSION=$(lsb_release -c | awk '{ print $2 }') @@ -121,7 +125,8 @@ apt-get -y install libfreetype6-dev libpng-dev libatlas-base-dev libgmp-dev libl apt-get -y install libffi-dev libssl-dev glances python3-bottle automake libtool libltdl7 apt -y -qq install apt-transport-https ca-certificates apt-get -y install xorg chromium openbox lightdm openjdk-11-jre libevent-dev ncurses-dev -apt-get -y install zlib1g-dev libudev-dev libusb-1.0-0-dev python3-venv +apt-get -y install zlib1g-dev libudev-dev libusb-1.0-0-dev python3-venv gunicorn +apt-get -y isntall libsqlite3-dev # Make sure some software is removed @@ -149,13 +154,17 @@ pip install tzupdate virtualenv # Update Python3 to 3.7.X -PYTHON3_VERSION=$(python3 --version) -if [[ "$PYTHON3_VERSION" != *"Python 3.7.6"* ]]; then +PYTHON_VERSION=3.7.7 +CURRENT_PYTHON3_VERSION=$(python3 --version) +if [[ "$CURRENT_PYTHON3_VERSION" != *"Python ${PYTHON_VERSION}"* ]]; then mkdir -p /opt/download cd /opt/download - wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz - tar xf Python-3.7.6.tar.xz - cd Python-3.7.6 + rm -rf Python-* + + wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz -O python.tar.xz + tar xf python.tar.xz + + cd Python-* ./configure make -j4 make install