mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-09-25 11:13:12 +02:00
circuitbreaker: update to v0.2.0 + update option (#1687)
This commit is contained in:
@@ -1,28 +1,35 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
pinnedVersion="v0.2.0"
|
||||||
|
|
||||||
# command info
|
# command info
|
||||||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
||||||
echo "config script to switch the circuitbreaker on or off"
|
echo
|
||||||
echo "bonus.circuitbreaker.sh [on|off|menu]"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source /mnt/hdd/raspiblitz.conf
|
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
|
if ! grep -Eq "^circuitbreaker=" /mnt/hdd/raspiblitz.conf; then
|
||||||
echo "circuitbreaker=off" >> /mnt/hdd/raspiblitz.conf
|
echo "circuitbreaker=off" >> /mnt/hdd/raspiblitz.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# stop services
|
# 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
|
sudo systemctl stop circuitbreaker 2>/dev/null
|
||||||
|
|
||||||
isInstalled=$(sudo ls /etc/systemd/system/circuitbreaker.service 2>/dev/null | grep -c 'circuitbreaker.service')
|
isInstalled=$(sudo ls /etc/systemd/system/circuitbreaker.service 2>/dev/null | grep -c 'circuitbreaker.service')
|
||||||
|
|
||||||
# switch on
|
# switch on
|
||||||
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
||||||
echo "# installing circuitbreaker"
|
echo "# Installing circuitbreaker $pinnedVersion"
|
||||||
if [ ${isInstalled} -eq 0 ]; then
|
if [ ${isInstalled} -eq 0 ]; then
|
||||||
# install Go
|
# install Go
|
||||||
/home/admin/config.scripts/bonus.go.sh on
|
/home/admin/config.scripts/bonus.go.sh on
|
||||||
@@ -50,20 +57,20 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
|||||||
cd /home/circuitbreaker
|
cd /home/circuitbreaker
|
||||||
sudo -u circuitbreaker git clone https://github.com/lightningequipment/circuitbreaker.git
|
sudo -u circuitbreaker git clone https://github.com/lightningequipment/circuitbreaker.git
|
||||||
cd circuitbreaker
|
cd circuitbreaker
|
||||||
|
sudo -u circuitbreaker git reset --hard $pinnedVersion
|
||||||
sudo -u circuitbreaker /usr/local/go/bin/go install ./... || exit 1
|
sudo -u circuitbreaker /usr/local/go/bin/go install ./... || exit 1
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# config
|
# config
|
||||||
##################
|
##################
|
||||||
# see https://github.com/lightningequipment/circuitbreaker#configuration
|
echo
|
||||||
echo "# create circuitbreaker.yaml"
|
echo "# Setting the example configuration from:"
|
||||||
cat > /home/admin/circuitbreaker.yaml <<EOF
|
echo "# https://github.com/lightningequipment/circuitbreaker/blob/$pinnedVersion/circuitbreaker-example.yaml"
|
||||||
maxPendingHtlcs: 5
|
echo "# Find it at: /home/circuitbreaker/.circutbreaker/circuitbreaker.yaml"
|
||||||
EOF
|
echo
|
||||||
# move in place and fix ownersip
|
sudo -u circuitbreaker mkdir /home/circuitbreaker/.circuitbreaker 2>/dev/null
|
||||||
sudo -u circuitbreaker mkdir /home/circuitbreaker/.circuitbreaker
|
sudo -u circuitbreaker cp circuitbreaker-example.yaml \
|
||||||
sudo mv /home/admin/circuitbreaker.yaml /home/circuitbreaker/.circuitbreaker/circuitbreaker.yaml
|
/home/circuitbreaker/.circuitbreaker/circuitbreaker.yaml
|
||||||
sudo chown circuitbreaker:circuitbreaker /home/circuitbreaker/.circuitbreaker/circuitbreaker.yaml
|
|
||||||
|
|
||||||
# make systemd service
|
# make systemd service
|
||||||
# sudo nano /etc/systemd/system/circuitbreaker.service
|
# sudo nano /etc/systemd/system/circuitbreaker.service
|
||||||
@@ -87,20 +94,23 @@ RestartSec=60
|
|||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
" | sudo tee -a /etc/systemd/system/circuitbreaker.service
|
" | sudo tee -a /etc/systemd/system/circuitbreaker.service
|
||||||
sudo systemctl enable circuitbreaker
|
sudo systemctl enable circuitbreaker
|
||||||
echo "# OK - the circuitbreaker service is now enabled"
|
echo "# OK - the circuitbreaker.service is now enabled"
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "# circuitbreaker service is already installed."
|
echo "# The circuitbreaker.service is already installed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# setting value in raspi blitz config
|
# setting value in raspi blitz config
|
||||||
sudo sed -i "s/^circuitbreaker=.*/circuitbreaker=on/g" /mnt/hdd/raspiblitz.conf
|
sudo sed -i "s/^circuitbreaker=.*/circuitbreaker=on/g" /mnt/hdd/raspiblitz.conf
|
||||||
|
|
||||||
if [ ${isInstalled} -eq 0 ]; then
|
if [ ${isInstalled} -eq 1 ]; then
|
||||||
echo "# Start in the background with: 'sudo systemctl start circuitbreaker'"
|
echo
|
||||||
echo "# Find more info at https://github.com/lightningequipment/circuitbreaker"
|
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
|
else
|
||||||
echo " Failed to install circuitbreaker "
|
echo "# Failed to install circuitbreaker "
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -111,24 +121,68 @@ fi
|
|||||||
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
||||||
|
|
||||||
if [ ${isInstalled} -eq 1 ]; then
|
if [ ${isInstalled} -eq 1 ]; then
|
||||||
echo "# REMOVING the circuitbreaker SERVICE"
|
echo "# Removing the circuitbreaker.service"
|
||||||
# remove the systemd service
|
|
||||||
sudo systemctl stop circuitbreaker
|
sudo systemctl stop circuitbreaker
|
||||||
sudo systemctl disable circuitbreaker
|
sudo systemctl disable circuitbreaker
|
||||||
sudo rm /etc/systemd/system/circuitbreaker.service
|
sudo rm /etc/systemd/system/circuitbreaker.service
|
||||||
# delete user and it's home directory
|
echo "# Removing the user and it's home directory"
|
||||||
sudo userdel -rf circuitbreaker
|
sudo userdel -rf circuitbreaker 2>/dev/null
|
||||||
echo "# OK, the circuitbreaker Service is removed."
|
echo "# OK, Circuit Breaker is removed."
|
||||||
else
|
else
|
||||||
echo "# circuitbreaker is not installed."
|
echo "# Circuit Breaker is not installed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# setting value in raspi blitz config
|
# setting value in raspiblitz.conf
|
||||||
sudo sed -i "s/^circuitbreaker=.*/circuitbreaker=off/g" /mnt/hdd/raspiblitz.conf
|
sudo sed -i "s/^circuitbreaker=.*/circuitbreaker=off/g" /mnt/hdd/raspiblitz.conf
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
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 "# FAIL - Unknown Parameter $1"
|
||||||
echo "# may need reboot to run normal again"
|
echo "# may need reboot to run normal again"
|
||||||
exit 1
|
exit 1
|
Reference in New Issue
Block a user