Skip to content

Commit

Permalink
chore: better handle ports on Pi and allow albyhub to run on port 80 (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
bumi authored Sep 6, 2024
1 parent 207a8e4 commit 49449f0
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 24 deletions.
17 changes: 16 additions & 1 deletion scripts/linux-x86_64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
2 changes: 1 addition & 1 deletion scripts/linux-x86_64/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions scripts/linux-x86_64/phoenixd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions scripts/linux-x86_64/phoenixd/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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"
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"
Expand All @@ -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 &
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions scripts/pi-aarch64/README.md
Original file line number Diff line number Diff line change
@@ -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.
67 changes: 67 additions & 0 deletions scripts/pi-aarch64/install.sh
Original file line number Diff line number Diff line change
@@ -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 ""
24 changes: 24 additions & 0 deletions scripts/pi-aarch64/update.sh
Original file line number Diff line number Diff line change
@@ -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."
17 changes: 6 additions & 11 deletions scripts/pi-arm/README.md
Original file line number Diff line number Diff line change
@@ -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)"
```
Expand Down
20 changes: 16 additions & 4 deletions scripts/pi-arm/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,28 @@ 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

# 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
Expand All @@ -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"
Expand All @@ -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 ""
2 changes: 2 additions & 0 deletions scripts/pi-arm/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 49449f0

Please sign in to comment.