raspiblitz/home.admin/XXshutdown.sh

47 lines
1.3 KiB
Bash
Raw Normal View History

2019-06-04 10:09:40 +01:00
#!/bin/bash
2019-12-11 14:10:34 +01:00
# for reboot call: sudo /home/admin/XXshutdown.sh reboot
# use this script instead of dirct shutdown command to:
# 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}
sed -i "s/^message=.*/message=''/g" ${infoFile}
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 "-----------------------------------------------"
echo "stop lnd - please wait .."
2019-12-11 13:55:28 +01:00
sudo systemctl stop lnd 2>/dev/null
2019-06-04 10:09:40 +01:00
echo "stop ${network}d (1) - please wait .."
2019-12-11 13:55:28 +01:00
sudo -u bitcoin ${network}-cli stop 2>/dev/null
2019-06-04 10:09:40 +01:00
sleep 10
echo "stop ${network}d (2) - please wait .."
2019-12-11 13:55:28 +01:00
sudo systemctl stop ${network}d 2>/dev/null
2019-06-04 10:09:40 +01:00
sleep 3
sync
echo "starting shutdown ..."
2019-12-11 13:48:29 +01:00
sudo shutdown ${shutdownParams}
2019-06-04 10:09:40 +01:00
exit 0