mirror of
https://github.com/home-assistant/operating-system.git
synced 2026-04-28 12:44:04 +01:00
* Improve UX of HA CLI wrapper and emergency console For many users, the emergency console gives feeling that the system is completely broken. However, there are various cases when the system just takes just a bit longer to start up and the emergency message is shown, while it finishes a proper startup shortly after. This change tries to improve the UX in several ways: * The limit before a forced emergency console startup is changed to 3 minutes * Waiting can be interrupted with Ctrl+C (reset counter is cleared then) * Some hints what to check have been added before starting the shell * Also, because if the HA CLI failed for 5 times in a row in quick succession, the CLI startup was then not retried anymore and user may have been left with a black screen, the restart limits timeouts have been adjusted only to back off and never mark the unit as failed Closes #4273 * Use /bin/sh and printf to silence linter errors
67 lines
1.9 KiB
Bash
Executable File
67 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
# ==============================================================================
|
|
# Run logging cli
|
|
# ==============================================================================
|
|
|
|
run_shell() { exec /bin/ash -l; }
|
|
interrupt() { echo " cancelled"; systemctl reset-failed "ha-cli@*"; run_shell; }
|
|
emergency_shell() {
|
|
printf "\n\n[WARNING] Home Assistant CLI is not starting or was interrupted.\n"
|
|
echo ""
|
|
echo "This happens when start of all services takes longer than expected, or because"
|
|
echo "of slow internet connection. Emergency console has been started, you can use"
|
|
echo "for example the following commands for troubleshooting:"
|
|
echo ""
|
|
echo " * 'docker ps -a' - e.g. to check if 'hassio_supervisor' container is running"
|
|
echo " * 'journalctl -e' - to investigate latest system logs"
|
|
echo " * 'exit' or Ctrl+D - to exit the emergency console and retry HA CLI startup"
|
|
echo ""
|
|
run_shell
|
|
}
|
|
|
|
trap interrupt INT
|
|
|
|
printf "Waiting for the Home Assistant CLI to be ready..."
|
|
|
|
i=0
|
|
while [ ! "$(docker ps -q -f name=hassio_cli)" ]; do
|
|
sleep 1
|
|
|
|
if [ $((i % 4)) = 0 ]; then
|
|
printf "\010\010\010 \010\010\010"
|
|
else
|
|
printf "."
|
|
fi
|
|
|
|
i=$((i+1))
|
|
|
|
if [ $i = 180 ]; then
|
|
emergency_shell
|
|
fi
|
|
done
|
|
|
|
docker container exec \
|
|
-ti hassio_cli \
|
|
/usr/bin/cli.sh
|
|
|
|
case $? in
|
|
10)
|
|
# Jump to root login shell (login command)
|
|
run_shell
|
|
;;
|
|
130)
|
|
# 130 is CLI termination with Ctrl+C (SIGINT)
|
|
printf "\nHome Assistant CLI has been interrupted.\n"
|
|
systemctl reset-failed "ha-cli@*"
|
|
;;
|
|
143)
|
|
# 143 graceful termination (SIGTERM). Most likely a proper shutdown.
|
|
# Just sleep for a while until actual systemd shutdown gets invoked.
|
|
printf "\nHome Assistant CLI has been terminated.\n"
|
|
sleep 30
|
|
;;
|
|
*)
|
|
printf "\nHA CLI failed with error code: %s\n" "$?"
|
|
;;
|
|
esac
|