#!/bin/bash # Restarts radio_ui.py on the Pi 5 (to pick up a change already pushed by # Sync_PiDisplay.command) and then closes this Terminal window. # # Split out from Sync_PiDisplay.command (2026-10-13) into its own script, # after a combined sync+build+restart+close script kept failing on the # restart step specifically. Root cause: the restart logic used to be # sent as one long inline `ssh pi "...pkill -f radio_ui.py..."` command, # and that command's own literal text - sitting in the remote shell's # command line - was itself a match for `pkill -f radio_ui.py`, so the # remote shell killed itself mid-restart and the ssh session dropped # with a bare, unhelpful exit 255 every time. The actual restart logic # now lives in PiDisplay/restart_radio.sh (synced to the Pi along with # everything else by Sync_PiDisplay.command) and is run here as a file, # not an inline string, which avoids that trap entirely. PI_HOST="mustang.local" # <-- set to your Pi's hostname (or IP address) PI_USER="bob" # <-- set to your Pi's username PI_DEST="/home/$PI_USER/PiDisplay" cd "$(dirname "$0")" echo "== Restarting radio_ui.py on $PI_USER@$PI_HOST" ssh -o ConnectTimeout=10 "$PI_USER@$PI_HOST" "bash $PI_DEST/restart_radio.sh" RESTART_STATUS=$? if [ $RESTART_STATUS -ne 0 ]; then echo "restart_radio.sh failed (ssh exit $RESTART_STATUS) - check PI_HOST/" echo "PI_USER above, that the Pi is on the network, and that" echo "PiDisplay/restart_radio.sh has been synced to the Pi (run" echo "Sync_PiDisplay.command at least once first)." fi sleep 2 # Confirm it's actually running rather than just "asked to" - uses the # [r]adio_ui.py bracket trick so this check's own ssh command line (which # literally contains the text "radio_ui.py") can't match itself and give # a false "yes" regardless of whether the restart actually worked. if ssh -o ConnectTimeout=10 "$PI_USER@$PI_HOST" "pgrep -f '[r]adio_ui\.py'" >/dev/null 2>&1; then echo "Confirmed: radio_ui.py is running on the Pi." else echo "radio_ui.py does NOT appear to be running on the Pi. Here's the" echo "end of its own log from the Pi (/tmp/radio_ui.log), which should" echo "say why it exited:" echo "----" ssh -o ConnectTimeout=10 "$PI_USER@$PI_HOST" "tail -n 20 /tmp/radio_ui.log 2>/dev/null" \ || echo "(couldn't read /tmp/radio_ui.log on the Pi)" echo "----" echo "Or SSH in and run it by hand to watch it live:" echo " cd $PI_DEST && python3 radio_ui.py" fi read -p "Press Return to close... " # Close this script's own Terminal window - matched by this process's own # tty, so it closes the right window without touching any other Terminal # windows you have open. osascript -e "tell application \"Terminal\" to close (every window whose tty is \"$(tty)\")" exit 0