mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-28 16:58:03 +01:00
trigger safe shutdown with rpi5 power button (#4312)
* trigger safe shutdown with rpi5 power button * run blitz.shutdown.sh with sudo everywhere * blitz.shutdown.sh: remove sudo, fulcrum to stop
This commit is contained in:
parent
a015d2c399
commit
07cdde07c0
7 changed files with 77 additions and 45 deletions
|
@ -477,6 +477,17 @@ if [ "${baseimage}" = "raspios_arm64" ]; then
|
||||||
else
|
else
|
||||||
echo "$fsOption2 already in $kernelOptionsFile"
|
echo "$fsOption2 already in $kernelOptionsFile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# *** SAFE SHUTDOWN ***
|
||||||
|
# logind
|
||||||
|
echo "[Login]" | tee /etc/systemd/logind.conf.d/safeshutdown.conf
|
||||||
|
echo "HandlePowerKey=ignore" | tee -a /etc/systemd/logind.conf.d/safeshutdown.conf
|
||||||
|
# sudoers
|
||||||
|
echo 'nobody ALL=(ALL) NOPASSWD: /home/admin/config.scripts/blitz.shutdown.sh' |
|
||||||
|
tee -a /etc/sudoers
|
||||||
|
# triggerhappy
|
||||||
|
echo 'KEY_POWER 1 sudo /home/admin/config.scripts/blitz.shutdown.sh' |
|
||||||
|
tee /etc/triggerhappy/triggers.d/powerbutton.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# special prepare when Nvidia Jetson Nano
|
# special prepare when Nvidia Jetson Nano
|
||||||
|
|
|
@ -346,7 +346,7 @@ case $CHOICE in
|
||||||
echo
|
echo
|
||||||
echo "Press ENTER when your backup download is done to shutdown."
|
echo "Press ENTER when your backup download is done to shutdown."
|
||||||
read key
|
read key
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh
|
sudo /home/admin/config.scripts/blitz.shutdown.sh
|
||||||
;;
|
;;
|
||||||
RESET-LND)
|
RESET-LND)
|
||||||
askLNDbackupCopy
|
askLNDbackupCopy
|
||||||
|
|
|
@ -160,7 +160,7 @@ patch()
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
clear
|
clear
|
||||||
echo "REBOOT .."
|
echo "REBOOT .."
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh reboot
|
sudo /home/admin/config.scripts/blitz.shutdown.sh reboot
|
||||||
sleep 8
|
sleep 8
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
@ -269,7 +269,7 @@ Do you really want to update LND now?
|
||||||
if [ ${#error} -gt 0 ]; then
|
if [ ${#error} -gt 0 ]; then
|
||||||
whiptail --title "ERROR" --msgbox "${error}" 8 30
|
whiptail --title "ERROR" --msgbox "${error}" 8 30
|
||||||
else
|
else
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh reboot
|
sudo /home/admin/config.scripts/blitz.shutdown.sh reboot
|
||||||
sleep 8
|
sleep 8
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
@ -293,7 +293,7 @@ Do you really want to update LND now?
|
||||||
if [ ${#error} -gt 0 ]; then
|
if [ ${#error} -gt 0 ]; then
|
||||||
whiptail --title "ERROR" --msgbox "${error}" 8 30
|
whiptail --title "ERROR" --msgbox "${error}" 8 30
|
||||||
else
|
else
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh reboot
|
sudo /home/admin/config.scripts/blitz.shutdown.sh reboot
|
||||||
sleep 8
|
sleep 8
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
@ -418,7 +418,7 @@ Do you really want to update Bitcoin Core now?
|
||||||
error=""
|
error=""
|
||||||
warn=""
|
warn=""
|
||||||
sudo -u admin /home/admin/config.scripts/bitcoin.update.sh tested
|
sudo -u admin /home/admin/config.scripts/bitcoin.update.sh tested
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh reboot
|
sudo /home/admin/config.scripts/blitz.shutdown.sh reboot
|
||||||
;;
|
;;
|
||||||
RECKLESS)
|
RECKLESS)
|
||||||
whiptail --title "UNTESTED Bitcoin Core update to ${bitcoinLatestVersion}" --yes-button "Cancel" \
|
whiptail --title "UNTESTED Bitcoin Core update to ${bitcoinLatestVersion}" --yes-button "Cancel" \
|
||||||
|
@ -439,11 +439,11 @@ Do you really want to update Bitcoin Core now?
|
||||||
if [ ${#error} -gt 0 ]; then
|
if [ ${#error} -gt 0 ]; then
|
||||||
whiptail --title "ERROR" --msgbox "${error}" 8 30
|
whiptail --title "ERROR" --msgbox "${error}" 8 30
|
||||||
fi
|
fi
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh reboot
|
sudo /home/admin/config.scripts/blitz.shutdown.sh reboot
|
||||||
;;
|
;;
|
||||||
CUSTOM)
|
CUSTOM)
|
||||||
sudo -u admin /home/admin/config.scripts/bitcoin.update.sh custom
|
sudo -u admin /home/admin/config.scripts/bitcoin.update.sh custom
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh reboot
|
sudo /home/admin/config.scripts/blitz.shutdown.sh reboot
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ function restart() {
|
||||||
echo "Command to restart your RaspiBlitz"
|
echo "Command to restart your RaspiBlitz"
|
||||||
confirmMsg restart
|
confirmMsg restart
|
||||||
if [ $confirm -eq 1 ]; then
|
if [ $confirm -eq 1 ]; then
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh reboot
|
sudo /home/admin/config.scripts/blitz.shutdown.sh reboot
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ function off() {
|
||||||
echo "Command to power off your RaspiBlitz"
|
echo "Command to power off your RaspiBlitz"
|
||||||
confirmMsg off
|
confirmMsg off
|
||||||
if [ $confirm -eq 1 ]; then
|
if [ $confirm -eq 1 ]; then
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh
|
sudo /home/admin/config.scripts/blitz.shutdown.sh
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,6 @@ sudo rm /var/cache/raspiblitz/temp/raspiblitz.setup
|
||||||
sudo cp /home/admin/raspiblitz.log /home/admin/raspiblitz.setup.log
|
sudo cp /home/admin/raspiblitz.log /home/admin/raspiblitz.setup.log
|
||||||
sudo chmod 640 /home/admin/raspiblitz.setup.log
|
sudo chmod 640 /home/admin/raspiblitz.setup.log
|
||||||
sudo chown root:sudo /home/admin/raspiblitz.setup.log
|
sudo chown root:sudo /home/admin/raspiblitz.setup.log
|
||||||
timeout 120 /home/admin/config.scripts/blitz.shutdown.sh reboot finalsetup
|
timeout 120 sudo /home/admin/config.scripts/blitz.shutdown.sh reboot finalsetup
|
||||||
# if system has not rebooted yet - force reboot directly
|
# if system has not rebooted yet - force reboot directly
|
||||||
sudo shutdown -r now
|
sudo shutdown -r now
|
|
@ -510,7 +510,7 @@ if [ "$1" = "export-gui" ]; then
|
||||||
read key
|
read key
|
||||||
echo "Shutting down ...."
|
echo "Shutting down ...."
|
||||||
sleep 4
|
sleep 4
|
||||||
/home/admin/config.scripts/blitz.shutdown.sh
|
sudo /home/admin/config.scripts/blitz.shutdown.sh
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,26 @@
|
||||||
# 1) give UI the info that a reboot/shutdown is now happening
|
# 1) give UI the info that a reboot/shutdown is now happening
|
||||||
# 2) shutdown/reboot in a safe way to prevent data corruption
|
# 2) shutdown/reboot in a safe way to prevent data corruption
|
||||||
|
|
||||||
|
# check if sudo
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "Please run as root (with sudo)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
source <(/home/admin/_cache.sh get network)
|
source <(/home/admin/_cache.sh get network)
|
||||||
|
|
||||||
# display info
|
# display info
|
||||||
echo ""
|
echo
|
||||||
echo "Green activity light stays dark and LCD turns white when shutdown complete."
|
rpiModel=$(cat /proc/device-tree/model 2>/dev/null | tr -d '\0')
|
||||||
|
if [ -n "${rpiModel}" ]; then
|
||||||
|
echo "${rpiModel}"
|
||||||
|
if echo ${rpiModel} | grep -Eq 'Raspberry Pi 4'; then
|
||||||
|
echo "When shutdown is complete the green activity light stays dark and the LCD turns white on the ${rpiModel}."
|
||||||
|
elif echo ${rpiModel} | grep -Eq 'Raspberry Pi 5'; then
|
||||||
|
echo "When shutdown is complete the activity light turns red and the LCD turns white on the ${rpiModel}."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$1" = "reboot" ]; then
|
if [ "$1" = "reboot" ]; then
|
||||||
shutdownParams="-h -r now"
|
shutdownParams="-h -r now"
|
||||||
echo "It will then reboot again automatically."
|
echo "It will then reboot again automatically."
|
||||||
|
@ -26,82 +41,88 @@ fi
|
||||||
echo "-----------------------------------------------"
|
echo "-----------------------------------------------"
|
||||||
sleep 3
|
sleep 3
|
||||||
|
|
||||||
# stopping electRS (if installed)
|
# general services to stop
|
||||||
echo "stop electrs - please wait .."
|
servicesToStop="electrs fulcrum"
|
||||||
sudo timeout 120 systemctl stop electrs 2>/dev/null
|
for service in ${servicesToStop}; do
|
||||||
|
if systemctl is-active --quiet ${service}; then
|
||||||
|
echo "stopping ${service} - please wait .."
|
||||||
|
timeout 120 systemctl stop ${service}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# lndg
|
||||||
# stopping LNDg (if installed)
|
# stopping LNDg (if installed)
|
||||||
isInstalled=$(sudo ls /etc/systemd/system/jobs-lndg.service 2>/dev/null | grep -c 'jobs-lndg.service')
|
isInstalled=$(sudo ls /etc/systemd/system/jobs-lndg.service 2>/dev/null | grep -c 'jobs-lndg.service')
|
||||||
if ! [ ${isInstalled} -eq 0 ]; then
|
if ! [ ${isInstalled} -eq 0 ]; then
|
||||||
echo "stop LNDg - please wait .."
|
echo "stop LNDg - please wait .."
|
||||||
sudo timeout 120 systemctl stop gunicorn.service 2>/dev/null
|
timeout 120 systemctl stop gunicorn.service 2>/dev/null
|
||||||
sudo timeout 120 systemctl stop jobs-lndg.timer 2>/dev/null
|
timeout 120 systemctl stop jobs-lndg.timer 2>/dev/null
|
||||||
sudo timeout 120 systemctl stop jobs-lndg.service 2>/dev/null
|
timeout 120 systemctl stop jobs-lndg.service 2>/dev/null
|
||||||
sudo timeout 120 systemctl stop rebalancer-lndg.timer 2>/dev/null
|
timeout 120 systemctl stop rebalancer-lndg.timer 2>/dev/null
|
||||||
sudo timeout 120 systemctl stop rebalancer-lndg.service 2>/dev/null
|
timeout 120 systemctl stop rebalancer-lndg.service 2>/dev/null
|
||||||
sudo timeout 120 systemctl stop htlc-stream-lndg.service 2>/dev/null
|
timeout 120 systemctl stop htlc-stream-lndg.service 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# stopping lightning
|
# lightning
|
||||||
echo "stop lightning - please wait .."
|
lightningServicesToStop="lnd tlnd slnd lightningd tlightningd slightningd"
|
||||||
sudo timeout 120 systemctl stop lnd 2>/dev/null
|
for service in ${lightningServicesToStop}; do
|
||||||
sudo timeout 120 systemctl stop lightningd 2>/dev/null
|
if systemctl is-active --quiet ${service}; then
|
||||||
sudo timeout 120 systemctl stop tlnd 2>/dev/null
|
echo "stopping ${service} - please wait .."
|
||||||
sudo timeout 120 systemctl stop tlightningd 2>/dev/null
|
timeout 120 systemctl stop ${service}
|
||||||
sudo timeout 120 systemctl stop slnd 2>/dev/null
|
fi
|
||||||
sudo timeout 120 systemctl stop slightningd 2>/dev/null
|
done
|
||||||
|
|
||||||
|
# bitcoind
|
||||||
if [ "${network}" != "" ]; then
|
if [ "${network}" != "" ]; then
|
||||||
|
|
||||||
# stopping bitcoin (thru cli)
|
# stopping bitcoin (thru cli)
|
||||||
echo "stop ${network}d (1) - please wait .."
|
echo "stop ${network}d (1) - please wait .."
|
||||||
timeout 10 sudo -u bitcoin ${network}-cli stop 2>/dev/null
|
timeout 10 sudo -u bitcoin ${network}-cli stop 2>/dev/null
|
||||||
|
|
||||||
# stopping bitcoind (thru systemd)
|
# stopping bitcoind (thru systemd)
|
||||||
echo "stop ${network}d (2) - please wait .."
|
echo "stop ${network}d (2) - please wait .."
|
||||||
sudo timeout 120 systemctl stop ${network}d 2>/dev/null
|
timeout 120 systemctl stop ${network}d 2>/dev/null
|
||||||
sudo timeout 120 systemctl stop t${network}d 2>/dev/null
|
timeout 120 systemctl stop t${network}d 2>/dev/null
|
||||||
sudo timeout 120 systemctl stop s${network}d 2>/dev/null
|
timeout 120 systemctl stop s${network}d 2>/dev/null
|
||||||
sleep 3
|
sleep 3
|
||||||
else
|
else
|
||||||
echo "skipping stopping layer1 (network=='' in cache)"
|
echo "skipping stopping layer1 (network=='' in cache)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# make sure drives are synced before shutdown
|
# make sure drives are synced before shutdown
|
||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
source <(/home/admin/config.scripts/blitz.datadrive.sh status)
|
||||||
if [ "${isBTRFS}" == "1" ] && [ "${isMounted}" == "1" ]; then
|
if [ "${isBTRFS}" == "1" ] && [ "${isMounted}" == "1" ]; then
|
||||||
echo "STARTING BTRFS RAID DATA CHECK ..."
|
echo "STARTING BTRFS RAID DATA CHECK ..."
|
||||||
sudo btrfs scrub start /mnt/hdd/
|
btrfs scrub start /mnt/hdd/
|
||||||
fi
|
fi
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# unmount HDD - try to kill all processes first #3114
|
# unmount HDD - try to kill all processes first #3114
|
||||||
echo "# Killing the processes using /mnt/hdd"
|
echo "# Killing the processes using /mnt/hdd"
|
||||||
processesUsingDisk=$(sudo lsof -t "/mnt/hdd")
|
processesUsingDisk=$(lsof -t "/mnt/hdd")
|
||||||
if [ -n "$processesUsingDisk" ]; then
|
if [ -n "$processesUsingDisk" ]; then
|
||||||
while read -r pid; do
|
while read -r pid; do
|
||||||
processName=$(ps -p $pid -o comm=)
|
processName=$(ps -p $pid -o comm=)
|
||||||
echo "# Stop $processName with: 'kill -SIGTERM $pid'"
|
echo "# Stop $processName with: 'kill -SIGTERM $pid'"
|
||||||
sudo kill -SIGTERM $pid # Send SIGTERM signal
|
kill -SIGTERM $pid # Send SIGTERM signal
|
||||||
sleep 5 # Wait for the process to terminate
|
sleep 5 # Wait for the process to terminate
|
||||||
done <<< "$processesUsingDisk"
|
done <<<"$processesUsingDisk"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "# Attempt to unmount /mnt/hdd"
|
echo "# Attempt to unmount /mnt/hdd"
|
||||||
sudo umount "/mnt/hdd"
|
umount "/mnt/hdd"
|
||||||
|
|
||||||
echo "starting shutdown ..."
|
echo "starting shutdown ..."
|
||||||
sudo shutdown ${shutdownParams}
|
shutdown ${shutdownParams}
|
||||||
|
|
||||||
# detect missing DBUS
|
# detect missing DBUS
|
||||||
if [ "${DBUS_SESSION_BUS_ADDRESS}" == "" ]; then
|
if [ "${DBUS_SESSION_BUS_ADDRESS}" == "" ]; then
|
||||||
echo "WARN: Missing \$DBUS_SESSION_BUS_ADDRESS .. "
|
echo "WARN: Missing \$DBUS_SESSION_BUS_ADDRESS .. "
|
||||||
if [ "$1" = "reboot" ]; then
|
if [ "$1" = "reboot" ]; then
|
||||||
echo "RUNNING FALLBACK REBOOT .. "
|
echo "RUNNING FALLBACK REBOOT .. "
|
||||||
sudo systemctl --force --force reboot
|
systemctl --force --force reboot
|
||||||
else
|
else
|
||||||
echo "RUNNING FALLBACK SHUTDOWN .. "
|
echo "RUNNING FALLBACK SHUTDOWN .. "
|
||||||
sudo systemctl --force --force poweroff
|
systemctl --force --force poweroff
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue