2019-06-04 10:09:40 +01:00
|
|
|
#!/bin/bash
|
2021-08-04 00:18:30 +02:00
|
|
|
# for reboot call: sudo /home/admin/config.scripts/blitz.shutdown.sh reboot
|
2019-12-11 14:10:34 +01:00
|
|
|
|
2021-08-27 03:59:21 -04:00
|
|
|
# use this script instead of direct shutdown command to:
|
2019-12-11 14:10:34 +01:00
|
|
|
# 1) give UI the info that a reboot/shutdown is now happening
|
|
|
|
# 2) shutdown/reboot in a safe way to prevent data corruption
|
2019-06-04 10:09:40 +01:00
|
|
|
|
|
|
|
# INFOFILE - state data from bootstrap
|
|
|
|
infoFile="/home/admin/raspiblitz.info"
|
|
|
|
|
2019-12-11 13:48:29 +01:00
|
|
|
# get network info from config
|
|
|
|
source ${infoFile} 2>/dev/null
|
|
|
|
source /mnt/hdd/raspiblitz.conf 2>/dev/null
|
|
|
|
if [ ${#network} -eq 0 ]; then
|
|
|
|
network=bitcoin
|
2019-12-11 13:53:55 +01:00
|
|
|
fi
|
2019-06-04 10:09:40 +01:00
|
|
|
|
2019-12-11 13:48:29 +01:00
|
|
|
# display info
|
2019-06-04 10:09:40 +01:00
|
|
|
echo ""
|
|
|
|
echo "LCD turns white when shutdown complete."
|
2019-12-11 13:48:29 +01:00
|
|
|
if [ "$1" = "reboot" ]; then
|
|
|
|
shutdownParams="-h -r now"
|
|
|
|
echo "It will then reboot again automatically."
|
|
|
|
sed -i "s/^state=.*/state=reboot/g" ${infoFile}
|
2021-08-30 12:06:18 +02:00
|
|
|
sed -i "s/^message=.*/message='$2'/g" ${infoFile}
|
2019-12-11 13:48:29 +01:00
|
|
|
else
|
|
|
|
shutdownParams="-h now"
|
|
|
|
echo "Then wait 5 seconds and disconnect power."
|
|
|
|
sed -i "s/^state=.*/state=shutdown/g" ${infoFile}
|
|
|
|
sed -i "s/^message=.*/message=''/g" ${infoFile}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# do shutdown/reboot
|
2019-06-04 10:09:40 +01:00
|
|
|
echo "-----------------------------------------------"
|
2021-01-12 19:15:31 +01:00
|
|
|
|
|
|
|
# stopping electRS (if installed)
|
|
|
|
echo "stop electrs - please wait .."
|
|
|
|
sudo systemctl stop electrs 2>/dev/null
|
|
|
|
|
2021-08-30 12:06:18 +02:00
|
|
|
# stopping lightning
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "stop lightning - please wait .."
|
2019-12-11 13:55:28 +01:00
|
|
|
sudo systemctl stop lnd 2>/dev/null
|
2021-08-04 00:18:30 +02:00
|
|
|
sudo systemctl stop lightningd 2>/dev/null
|
2021-08-30 12:06:18 +02:00
|
|
|
sudo systemctl stop tlnd 2>/dev/null
|
|
|
|
sudo systemctl stop tlightningd 2>/dev/null
|
|
|
|
sudo systemctl stop slnd 2>/dev/null
|
|
|
|
sudo systemctl stop slightningd 2>/dev/null
|
2021-01-12 19:15:31 +01:00
|
|
|
|
|
|
|
# stopping bitcoin (thru cli)
|
2019-06-04 10:09:40 +01:00
|
|
|
echo "stop ${network}d (1) - please wait .."
|
2021-08-30 12:06:18 +02:00
|
|
|
timeout 10 sudo -u bitcoin ${network}-cli stop 2>/dev/null
|
2021-01-12 19:15:31 +01:00
|
|
|
|
|
|
|
# stopping bitcoind (thru systemd)
|
2019-06-04 10:09:40 +01:00
|
|
|
echo "stop ${network}d (2) - please wait .."
|
2019-12-11 13:55:28 +01:00
|
|
|
sudo systemctl stop ${network}d 2>/dev/null
|
2021-08-30 12:06:18 +02:00
|
|
|
sudo systemctl stop t${network}d 2>/dev/null
|
|
|
|
sudo systemctl stop s${network}d 2>/dev/null
|
2019-06-04 10:09:40 +01:00
|
|
|
sleep 3
|
2020-01-15 12:05:26 +01:00
|
|
|
|
|
|
|
# make sure drives are synced before shutdown
|
|
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
2021-09-12 17:45:57 +02:00
|
|
|
if [ "${isBTRFS}" == "1" ] && [ "${isMounted}" == "1" ]; then
|
2020-01-15 12:05:26 +01:00
|
|
|
echo "STARTING BTRFS RAID DATA CHECK ..."
|
|
|
|
sudo btrfs scrub start /mnt/hdd/
|
|
|
|
fi
|
2019-06-04 10:09:40 +01:00
|
|
|
sync
|
2020-01-15 12:05:26 +01:00
|
|
|
|
2019-06-04 10:09:40 +01:00
|
|
|
echo "starting shutdown ..."
|
2019-12-11 13:48:29 +01:00
|
|
|
sudo shutdown ${shutdownParams}
|
2021-08-30 12:06:18 +02:00
|
|
|
exit 0
|