Recommended operating system: Debian.
To run an SSB room you need to have a static public IP, ideally with a DNS record (i.e.<hostname.yourdomain.tld>
).
On a fresh Debian 9 box, as root, run:
apt update
apt upgrade -y
apt install -y apt-transport-https ca-certificates curl software-properties-common
wget https://download.docker.com/linux/debian/gpg -O docker-gpg
sudo apt-key add docker-gpg
echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list.d/docker.list
apt update
apt install -y docker-ce
systemctl start docker
systemctl enable docker
docker pull staltz/ssb-room
From GitHub:
git clone https://github.com/staltz/ssb-room.git
cd ssb-room
docker build -t staltz/ssb-room .
mkdir ~/ssb-room-data
chown -R 1000:1000 ~/ssb-room-data
(If migrating from an old server, copy the previous ssb-room-data
and paste it in the new one)
This assumes your server's network interface is eth0
. Run ip addr
to make sure what the network interface code is, it could be something, such as ens3
.
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8007
Create a ./create-room
script:
cat > ./create-room <<EOF
#!/bin/bash
memory_limit=$(($(free -b --si | awk '/Mem\:/ { print $2 }') - 200*(10**6)))
docker run -d --name room \
-v ~/ssb-room-data/:/home/node/.ssb/ \
--network host \
--restart unless-stopped \
--memory "\$memory_limit" \
staltz/ssb-room
EOF
where --memory
sets an upper memory limit of your total memory minus 200 MB (for example: on a 1 GB server this could be simplified to --memory 800m
).
Then make the script executable and run it:
chmod +x ./create-room
./create-room
The shell script in ./room
will help us command our SSB Room server:
cat > ./room <<EOF
#!/bin/sh
docker exec -it room ssb-room \$@
EOF
Then make it executable and run it:
chmod +x ./room
./room check
SSB room has a built-in health check: ssb-room check
.
When room
becomes unhealthy, we want to kill the container, so it will be automatically restarted by Docker.
For this situation, we will use ahdinosaur/healer:
docker pull ahdinosaur/healer
docker run -d --name healer \
-v /var/run/docker.sock:/tmp/docker.sock \
--restart unless-stopped \
ahdinosaur/healer
Sometimes the room
or healer
containers will stop running (despite --restart unless-stopped
!).
For this situation, we will setup two cron job scripts:
printf '#!/bin/sh\n\ndocker start room\n' | tee /etc/cron.hourly/room && chmod +x /etc/cron.hourly/room
printf '#!/bin/sh\n\ndocker start healer\n' | tee /etc/cron.hourly/healer && chmod +x /etc/cron.hourly/healer
Because docker start <service>
is idempotent, it will not change anything if the service is already running, but if the service is not running it will start it.