From 49449f0dfc672fb2d20e4ad752c80ddb844cd50a Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Fri, 6 Sep 2024 10:32:26 +0200 Subject: [PATCH] chore: better handle ports on Pi and allow albyhub to run on port 80 (#584) * chore: better handle ports on Pi and allow albyhub to run on port 80 * chore: install script: create data dir before running docker compose * chore: install script for pi-aarch64 * chore: pi-zero move lib folder on update * chore: replace (not append) files in install scripts * chore: install text --- scripts/linux-x86_64/README.md | 17 +++++- scripts/linux-x86_64/install.sh | 2 +- scripts/linux-x86_64/phoenixd/README.md | 5 +- scripts/linux-x86_64/phoenixd/install.sh | 10 ++-- scripts/pi-aarch64/README.md | 20 +++++++ scripts/pi-aarch64/install.sh | 67 ++++++++++++++++++++++++ scripts/pi-aarch64/update.sh | 24 +++++++++ scripts/pi-arm/README.md | 17 +++--- scripts/pi-arm/install.sh | 20 +++++-- scripts/pi-arm/update.sh | 2 + 10 files changed, 160 insertions(+), 24 deletions(-) create mode 100644 scripts/pi-aarch64/README.md create mode 100644 scripts/pi-aarch64/install.sh create mode 100644 scripts/pi-aarch64/update.sh diff --git a/scripts/linux-x86_64/README.md b/scripts/linux-x86_64/README.md index eac3135c..1713a200 100644 --- a/scripts/linux-x86_64/README.md +++ b/scripts/linux-x86_64/README.md @@ -3,7 +3,8 @@ ## Requirements - Linux distribution -- Runs pretty much on any VPS/server with 512MB RAM or more (+some swap space ideally) +- Runs pretty much on any VPS/server with 512MB RAM or more (1GB recommended / plus some swap space ideally) +- lightning port 9735 must be available ### Installation (non-Docker) @@ -46,3 +47,17 @@ Make sure to backup your data directories: The install script will add an update.sh script to update Alby Hub. It will download the latest version for you. After the update you will have to unlock Alby Hub again. + +### Using Docker + +Alby Hub comes as docker image: [ghcr.io/getalby/hub:latest](https://github.com/getAlby/hub/pkgs/container/hub) + + $ docker run -v .albyhub-data:/data -e WORK_DIR='/data' -p 8080:8080 ghcr.io/getalby/hub:latest` + +We also provide a simple docker-compose file: + + $ wget https://raw.githubusercontent.com/getAlby/hub/master/docker-compose.yml # <- edit for your needs, but defaults should work well + $ mkdir ./albyhub-data + $ docker-compose up # or docker-compose up --pull=always <- to make sure you get the latest images + +Make sure to mount and backup the data working directory. diff --git a/scripts/linux-x86_64/install.sh b/scripts/linux-x86_64/install.sh index 71f74820..4c283030 100644 --- a/scripts/linux-x86_64/install.sh +++ b/scripts/linux-x86_64/install.sh @@ -59,7 +59,7 @@ then exit fi -sudo tee -a /etc/systemd/system/albyhub.service > /dev/null << EOF +sudo tee /etc/systemd/system/albyhub.service > /dev/null << EOF [Unit] Description=Alby Hub After=network-online.target diff --git a/scripts/linux-x86_64/phoenixd/README.md b/scripts/linux-x86_64/phoenixd/README.md index 8ad41ba2..83378c99 100644 --- a/scripts/linux-x86_64/phoenixd/README.md +++ b/scripts/linux-x86_64/phoenixd/README.md @@ -5,13 +5,14 @@ Run your Alby Hub with phoenixd as a backend. ## Requirements - Linux distribution -- Runs pretty much on any VPS or server +- Runs pretty much on any VPS or server (512MB+ memory recommended) ## Docker To run Alby Hub with phoenixd use [docker-compose](https://docs.docker.com/compose/) using the [docker-compose.yml file](https://raw.githubusercontent.com/getAlby/hub/master/scripts/linux-x86_64/phoenixd/docker-compose.yml). - $ wget https://raw.githubusercontent.com/getAlby/hub/master/scripts/linux-x86_64/phoenixd/docker-compose.yml + $ wget https://raw.githubusercontent.com/getAlby/hub/master/scripts/linux-x86_64/phoenixd/docker-compose.yml # <- edit for your needs, but defaults should work well + $ mkdir -p ./albyhub-phoenixd/phoenixd && mkdir -p ./albyhub-phoenixd/albyhub # <- create the data directories for phoenixd and albyhub. make sure to have backups of this $ docker-compose up # or docker-compose up --pull=always <- to make sure you get the latest images It will run on localhost:8080 by default. You can configure the port by editing the docker-compose.yml file. diff --git a/scripts/linux-x86_64/phoenixd/install.sh b/scripts/linux-x86_64/phoenixd/install.sh index 080cd571..00615f1d 100644 --- a/scripts/linux-x86_64/phoenixd/install.sh +++ b/scripts/linux-x86_64/phoenixd/install.sh @@ -37,7 +37,7 @@ rm server-linux-x86_64.tar.bz2 rm phoenix-$PHOENIX_VERSION-linux-x64.zip ### Create start scripts -tee -a $INSTALL_DIR/phoenixd/start.sh > /dev/null << EOF +tee $INSTALL_DIR/phoenixd/start.sh > /dev/null << EOF #!/bin/bash echo "Starting phoenixd" @@ -45,7 +45,7 @@ echo "Make sure to backup your phoenixd data in $INSTALL_DIR/phoenixd/data" PHOENIX_DATADIR="$INSTALL_DIR/phoenixd/data" $INSTALL_DIR/phoenixd/phoenixd --agree-to-terms-of-service --http-bind-ip=0.0.0.0 EOF -tee -a $INSTALL_DIR/albyhub/start.sh > /dev/null << EOF +tee $INSTALL_DIR/albyhub/start.sh > /dev/null << EOF #!/bin/bash echo "Starting Alby Hub" @@ -54,7 +54,7 @@ PHOENIXD_AUTHORIZATION=\$(awk -F'=' '/^http-password/{print \$2}' "\$phoenix_con WORK_DIR="$INSTALL_DIR/albyhub/data" LN_BACKEND_TYPE=PHOENIX PHOENIXD_ADDRESS="http://localhost:9740" PHOENIXD_AUTHORIZATION=\$PHOENIXD_AUTHORIZATION LOG_EVENTS=true LDK_GOSSIP_SOURCE="" $INSTALL_DIR/albyhub/bin/albyhub EOF -tee -a $INSTALL_DIR/start.sh > /dev/null << EOF +tee $INSTALL_DIR/start.sh > /dev/null << EOF #!/bin/bash $INSTALL_DIR/phoenixd/start.sh & @@ -82,7 +82,7 @@ then exit fi -sudo tee -a /etc/systemd/system/albyhub.service > /dev/null << EOF +sudo tee /etc/systemd/system/albyhub.service > /dev/null << EOF [Unit] Description=Alby Hub After=network-online.target @@ -99,7 +99,7 @@ ExecStart=$INSTALL_DIR/albyhub/start.sh WantedBy=multi-user.target EOF -sudo tee -a /etc/systemd/system/phoenixd.service > /dev/null << EOF +sudo tee /etc/systemd/system/phoenixd.service > /dev/null << EOF [Unit] Description=Phoenixd After=network-online.target diff --git a/scripts/pi-aarch64/README.md b/scripts/pi-aarch64/README.md new file mode 100644 index 00000000..3fa06c58 --- /dev/null +++ b/scripts/pi-aarch64/README.md @@ -0,0 +1,20 @@ +### Installation on a Raspberry Pi 4/5 (aarch64) + +This install scripts will help you installing Alby Hub on a Raspberry Pi with Raspberry Pi OS (previously called Raspbian). +You should have some basic Linux understanding to install and operate it. + +Have a look at our [installation guide](https://guides.getalby.com/user-guide/v/alby-account-and-browser-extension/alby-hub/alby-hub-flavors/raspberry-pi-zero) for more details and inspiration. + +SSH into your Pi and run: +```shell +/bin/bash -c "$(curl -fsSL https://getalby.com/install/hub/pi-aarch64-install.sh)" +``` + +### Updating a running instance + +SSH into your Pi and run: +```shell +/bin/bash -c "$(curl -fsSL https://getalby.com/install/hub/pi-aarch64-update.sh)" +``` + +And see install.sh and update.sh for details. diff --git a/scripts/pi-aarch64/install.sh b/scripts/pi-aarch64/install.sh new file mode 100644 index 00000000..83d53d8d --- /dev/null +++ b/scripts/pi-aarch64/install.sh @@ -0,0 +1,67 @@ +echo "" +echo "" +echo "⚡️ Welcome to Alby Hub" +echo "-----------------------------------------" +echo "Installing..." + + +sudo mkdir -p /opt/albyhub +sudo chown -R $USER:$USER /opt/albyhub +cd /opt/albyhub +wget https://getalby.com/install/hub/server-linux-aarch64.tar.bz2 + +# Extract archives +tar -xvf server-linux-aarch64.tar.bz2 +if [[ $? -ne 0 ]]; then + echo "Failed to unpack Alby Hub. Potentially bzip2 is missing" + echo "Install it with sudo apt-get install bzip2" +fi + +# Cleanup +rm server-linux-aarch64.tar.bz2 + +# allow albyhub to bind on port 80 +sudo setcap CAP_NET_BIND_SERVICE=+eip /opt/albyhub/bin/albyhub + +# Use port 80 if available otherwise 8029 +if sudo lsof -Pi :80 -sTCP:LISTEN -t >/dev/null ; then + PORT=8029 + URL="http://$HOSTNAME.local:8029" +else + PORT=80 + URL="http://$HOSTNAME.local" +fi + +### Create systemd service +sudo tee -a /etc/systemd/system/albyhub.service > /dev/null << EOF +[Unit] +Description=Alby Hub +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +Restart=always +RestartSec=1 +User=$USER +ExecStart=/opt/albyhub/bin/albyhub +# Hack to ensure Alby Hub never uses more than 90% CPU +CPUQuota=90% + +Environment="PORT=$PORT" +Environment="WORK_DIR=/opt/albyhub/data" +Environment="LDK_ESPLORA_SERVER=https://electrs.getalbypro.com" +Environment="LOG_EVENTS=true" +Environment="LDK_GOSSIP_SOURCE=" + +[Install] +WantedBy=multi-user.target +EOF + +sudo systemctl enable albyhub +sudo systemctl start albyhub + +echo "" +echo "" +echo "✅ Installation finished! Please visit $URL to configure your new Alby Hub." +echo "" diff --git a/scripts/pi-aarch64/update.sh b/scripts/pi-aarch64/update.sh new file mode 100644 index 00000000..15edcb69 --- /dev/null +++ b/scripts/pi-aarch64/update.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +echo "🔃 Updating Alby Hub..." +sudo systemctl stop albyhub + +# Download new artifacts +cd /opt/albyhub +rm -rf albyhub-backup +mkdir albyhub-backup +mv bin albyhub-backup +mv lib albyhub-backup +cp -r data albyhub-backup + +wget https://getalby.com/install/hub/server-linux-aarch64.tar.bz2 + +# Extract archives +tar -xvf server-linux-aarch64.tar.bz2 + +# Cleanup +rm server-linux-aarch64.tar.bz2 + +sudo systemctl start albyhub + +echo "✅ Update finished! Please login again to start your wallet." diff --git a/scripts/pi-arm/README.md b/scripts/pi-arm/README.md index df96d651..ca10acbd 100644 --- a/scripts/pi-arm/README.md +++ b/scripts/pi-arm/README.md @@ -1,23 +1,18 @@ -### Installation on a Raspberry Pi Zero +### Installation on a Raspberry Pi Zero (arm) -Have a look at our [installation guide](https://guides.getalby.com/user-guide/v/alby-account-and-browser-extension/alby-hub/alby-hub-flavors/raspberry-pi-zero) for more details. +This install scripts will help you installing Alby Hub on a Raspberry Pi with Raspberry Pi OS (previously called Raspbian). +You should have some basic Linux understanding to install and operate it. -```shell - $ ssh albyhub@albyhub.local '/bin/bash -c "$(curl -fsSL https://getalby.com/install/hub/pi-zero-install.sh)"' - ``` +Have a look at our [installation guide](https://guides.getalby.com/user-guide/v/alby-account-and-browser-extension/alby-hub/alby-hub-flavors/raspberry-pi-zero) for more details and inspiration. -or on the Pi directly: +SSH into your Pi and run: ```shell /bin/bash -c "$(curl -fsSL https://getalby.com/install/hub/pi-zero-install.sh)" ``` ### Updating a running instance -```shell - $ ssh albyhub@albyhub.local '/bin/bash -c "$(curl -fsSL https://getalby.com/install/hub/pi-zero-install.sh)"' - ``` - -or on the Pi directly: +SSH into your Pi and run: ```shell /bin/bash -c "$(curl -fsSL https://getalby.com/install/hub/pi-zero-update.sh)" ``` diff --git a/scripts/pi-arm/install.sh b/scripts/pi-arm/install.sh index 490369d5..4caefe79 100644 --- a/scripts/pi-arm/install.sh +++ b/scripts/pi-arm/install.sh @@ -12,7 +12,7 @@ wget https://getalby.com/install/hub/server-linux-armv6.tar.bz2 # Extract archives tar -xvf server-linux-armv6.tar.bz2 -if [[ $? -eq 0 ]]; then +if [[ $? -ne 0 ]]; then echo "Failed to unpack Alby Hub. Potentially bzip2 is missing" echo "Install it with sudo apt-get install bzip2" fi @@ -20,8 +20,20 @@ fi # Cleanup rm server-linux-armv6.tar.bz2 +# allow albyhub to bind on port 80 +sudo setcap CAP_NET_BIND_SERVICE=+eip /opt/albyhub/bin/albyhub + +# Use port 80 if available otherwise 8029 +if sudo lsof -Pi :80 -sTCP:LISTEN -t >/dev/null ; then + PORT=8029 + URL="http://$HOSTNAME.local:8029" +else + PORT=80 + URL="http://$HOSTNAME.local" +fi + ### Create systemd service -sudo tee -a /etc/systemd/system/albyhub.service > /dev/null << EOF +sudo tee /etc/systemd/system/albyhub.service > /dev/null << EOF [Unit] Description=Alby Hub After=network-online.target @@ -36,7 +48,7 @@ ExecStart=/opt/albyhub/bin/albyhub # Hack to ensure Alby Hub never uses more than 90% CPU CPUQuota=90% -Environment="PORT=80" +Environment="PORT=$PORT" Environment="WORK_DIR=/opt/albyhub/data" Environment="LDK_ESPLORA_SERVER=https://electrs.getalbypro.com" Environment="LOG_EVENTS=true" @@ -51,5 +63,5 @@ sudo systemctl start albyhub echo "" echo "" -echo "✅ Installation finished! Please visit http://$HOSTNAME.local to configure your new Alby Hub." +echo "✅ Installation finished! Please visit $URL to configure your new Alby Hub." echo "" diff --git a/scripts/pi-arm/update.sh b/scripts/pi-arm/update.sh index 6005c65a..82730c62 100644 --- a/scripts/pi-arm/update.sh +++ b/scripts/pi-arm/update.sh @@ -8,7 +8,9 @@ cd /opt/albyhub rm -rf albyhub-backup mkdir albyhub-backup mv bin albyhub-backup +mv lib albyhub-backup cp -r data albyhub-backup + wget https://getalby.com/install/hub/server-linux-armv6.tar.bz2 # Extract archives