mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-24 14:51:03 +01:00
circuitbreaker: update to v0.2.0 + update option (#1687)
This commit is contained in:
parent
7559ee6cc6
commit
5c87285833
1 changed files with 89 additions and 35 deletions
|
@ -1,72 +1,79 @@
|
|||
#!/bin/bash
|
||||
|
||||
pinnedVersion="v0.2.0"
|
||||
|
||||
# command info
|
||||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
||||
echo "config script to switch the circuitbreaker on or off"
|
||||
echo "bonus.circuitbreaker.sh [on|off|menu]"
|
||||
exit 1
|
||||
echo
|
||||
echo "Config script to switch the circuitbreaker on, off or update to the latest release tag or commit"
|
||||
echo "bonus.circuitbreaker.sh [on|off|update|update commit]"
|
||||
echo
|
||||
echo "Version to be installed by default: $pinnedVersion"
|
||||
echo "Source: https://github.com/lightningequipment/circuitbreaker"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# add default value to raspi config if needed
|
||||
# add default value to raspiblitz.conf if needed
|
||||
if ! grep -Eq "^circuitbreaker=" /mnt/hdd/raspiblitz.conf; then
|
||||
echo "circuitbreaker=off" >> /mnt/hdd/raspiblitz.conf
|
||||
fi
|
||||
|
||||
# stop services
|
||||
echo "# making sure the service is not running"
|
||||
echo "# Making sure the service is not running"
|
||||
sudo systemctl stop circuitbreaker 2>/dev/null
|
||||
|
||||
isInstalled=$(sudo ls /etc/systemd/system/circuitbreaker.service 2>/dev/null | grep -c 'circuitbreaker.service')
|
||||
|
||||
# switch on
|
||||
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
||||
echo "# installing circuitbreaker"
|
||||
echo "# Installing circuitbreaker $pinnedVersion"
|
||||
if [ ${isInstalled} -eq 0 ]; then
|
||||
# install Go
|
||||
/home/admin/config.scripts/bonus.go.sh on
|
||||
|
||||
|
||||
# get Go vars
|
||||
source /etc/profile
|
||||
# create dedicated user
|
||||
sudo adduser --disabled-password --gecos "" circuitbreaker
|
||||
# set PATH for the user
|
||||
sudo bash -c "echo 'PATH=\$PATH:/home/circuitbreaker/go/bin/' >> /home/circuitbreaker/.profile"
|
||||
|
||||
|
||||
# make sure symlink to central app-data directory exists"
|
||||
sudo rm -rf /home/circuitbreaker/.lnd # not a symlink.. delete it silently
|
||||
# create symlink
|
||||
sudo ln -s /mnt/hdd/app-data/lnd/ /home/circuitbreaker/.lnd
|
||||
|
||||
|
||||
# sync all macaroons and unix groups for access
|
||||
/home/admin/config.scripts/lnd.credentials.sh sync
|
||||
# macaroons will be checked after install
|
||||
|
||||
|
||||
# add user to group with admin access to lnd
|
||||
sudo /usr/sbin/usermod --append --groups lndadmin circuitbreaker
|
||||
|
||||
|
||||
# install from source
|
||||
cd /home/circuitbreaker
|
||||
sudo -u circuitbreaker git clone https://github.com/lightningequipment/circuitbreaker.git
|
||||
cd circuitbreaker
|
||||
sudo -u circuitbreaker git reset --hard $pinnedVersion
|
||||
sudo -u circuitbreaker /usr/local/go/bin/go install ./... || exit 1
|
||||
|
||||
##################
|
||||
# config
|
||||
##################
|
||||
# see https://github.com/lightningequipment/circuitbreaker#configuration
|
||||
echo "# create circuitbreaker.yaml"
|
||||
cat > /home/admin/circuitbreaker.yaml <<EOF
|
||||
maxPendingHtlcs: 5
|
||||
EOF
|
||||
# move in place and fix ownersip
|
||||
sudo -u circuitbreaker mkdir /home/circuitbreaker/.circuitbreaker
|
||||
sudo mv /home/admin/circuitbreaker.yaml /home/circuitbreaker/.circuitbreaker/circuitbreaker.yaml
|
||||
sudo chown circuitbreaker:circuitbreaker /home/circuitbreaker/.circuitbreaker/circuitbreaker.yaml
|
||||
|
||||
echo
|
||||
echo "# Setting the example configuration from:"
|
||||
echo "# https://github.com/lightningequipment/circuitbreaker/blob/$pinnedVersion/circuitbreaker-example.yaml"
|
||||
echo "# Find it at: /home/circuitbreaker/.circutbreaker/circuitbreaker.yaml"
|
||||
echo
|
||||
sudo -u circuitbreaker mkdir /home/circuitbreaker/.circuitbreaker 2>/dev/null
|
||||
sudo -u circuitbreaker cp circuitbreaker-example.yaml \
|
||||
/home/circuitbreaker/.circuitbreaker/circuitbreaker.yaml
|
||||
|
||||
# make systemd service
|
||||
# sudo nano /etc/systemd/system/circuitbreaker.service
|
||||
# sudo nano /etc/systemd/system/circuitbreaker.service
|
||||
echo "
|
||||
[Unit]
|
||||
Description=circuitbreaker Service
|
||||
|
@ -87,20 +94,23 @@ RestartSec=60
|
|||
WantedBy=multi-user.target
|
||||
" | sudo tee -a /etc/systemd/system/circuitbreaker.service
|
||||
sudo systemctl enable circuitbreaker
|
||||
echo "# OK - the circuitbreaker service is now enabled"
|
||||
echo "# OK - the circuitbreaker.service is now enabled"
|
||||
|
||||
else
|
||||
echo "# circuitbreaker service is already installed."
|
||||
echo "# The circuitbreaker.service is already installed."
|
||||
fi
|
||||
|
||||
# setting value in raspi blitz config
|
||||
sudo sed -i "s/^circuitbreaker=.*/circuitbreaker=on/g" /mnt/hdd/raspiblitz.conf
|
||||
|
||||
if [ ${isInstalled} -eq 0 ]; then
|
||||
echo "# Start in the background with: 'sudo systemctl start circuitbreaker'"
|
||||
if [ ${isInstalled} -eq 1 ]; then
|
||||
echo
|
||||
echo "# Find more info at https://github.com/lightningequipment/circuitbreaker"
|
||||
echo
|
||||
echo "# Start in the background with: 'sudo systemctl start circuitbreaker'"
|
||||
echo "# Monitor with: 'sudo journalctl -fu circuitbreaker'"
|
||||
else
|
||||
echo " Failed to install circuitbreaker "
|
||||
echo "# Failed to install circuitbreaker "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -111,24 +121,68 @@ fi
|
|||
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
||||
|
||||
if [ ${isInstalled} -eq 1 ]; then
|
||||
echo "# REMOVING the circuitbreaker SERVICE"
|
||||
# remove the systemd service
|
||||
echo "# Removing the circuitbreaker.service"
|
||||
sudo systemctl stop circuitbreaker
|
||||
sudo systemctl disable circuitbreaker
|
||||
sudo rm /etc/systemd/system/circuitbreaker.service
|
||||
# delete user and it's home directory
|
||||
sudo userdel -rf circuitbreaker
|
||||
echo "# OK, the circuitbreaker Service is removed."
|
||||
else
|
||||
echo "# circuitbreaker is not installed."
|
||||
echo "# Removing the user and it's home directory"
|
||||
sudo userdel -rf circuitbreaker 2>/dev/null
|
||||
echo "# OK, Circuit Breaker is removed."
|
||||
else
|
||||
echo "# Circuit Breaker is not installed."
|
||||
fi
|
||||
|
||||
# setting value in raspi blitz config
|
||||
# setting value in raspiblitz.conf
|
||||
sudo sed -i "s/^circuitbreaker=.*/circuitbreaker=off/g" /mnt/hdd/raspiblitz.conf
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# update
|
||||
if [ "$1" = "update" ]; then
|
||||
echo "# Updating Circuit Braker"
|
||||
cd /home/circuitbreaker/circuitbreaker
|
||||
# from https://github.com/apotdevin/thunderhub/blob/master/scripts/updateToLatest.sh
|
||||
# fetch latest master
|
||||
sudo -u circuitbreaker git fetch
|
||||
if [ "$2" = "commit" ]; then
|
||||
echo "# Updating to the latest commit in the default branch"
|
||||
TAG=$(git describe --tags)
|
||||
else
|
||||
TAG=$(git tag | sort -V | tail -1)
|
||||
# unset $1
|
||||
set --
|
||||
UPSTREAM=${1:-'@{u}'}
|
||||
LOCAL=$(git rev-parse @)
|
||||
REMOTE=$(git rev-parse "$UPSTREAM")
|
||||
if [ $LOCAL = $REMOTE ]; then
|
||||
echo "# You are up-to-date on version" $TAG
|
||||
echo "# Starting the circuitbreaker service ... "
|
||||
sudo systemctl start circuitbreaker
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
echo "# Pulling latest changes..."
|
||||
sudo -u circuitbreaker git pull -p
|
||||
sudo -u circuitbreaker git reset --hard $TAG
|
||||
echo "# Installing the version: $TAG"
|
||||
sudo -u circuitbreaker /usr/local/go/bin/go install ./... || exit 1
|
||||
echo
|
||||
echo "# Setting the example configuration from:"
|
||||
echo "# https://github.com/lightningequipment/circuitbreaker/blob/$TAG/circuitbreaker-example.yaml"
|
||||
echo "# Find it at: /home/circuitbreaker/.circutbreaker/circuitbreaker.yaml"
|
||||
sudo -u circuitbreaker mkdir /home/circuitbreaker/.circuitbreaker 2>/dev/null
|
||||
sudo -u circuitbreaker cp circuitbreaker-example.yaml \
|
||||
/home/circuitbreaker/.circuitbreaker/circuitbreaker.yaml
|
||||
echo
|
||||
echo "# Updated to version" $TAG
|
||||
echo
|
||||
echo "# Starting the circuitbreaker service ... "
|
||||
sudo systemctl start circuitbreaker
|
||||
echo "# Monitor with: 'sudo journalctl -fu circuitbreaker'"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "# FAIL - Unknown Parameter $1"
|
||||
echo "# may need reboot to run normal again"
|
||||
exit 1
|
Loading…
Add table
Reference in a new issue