From 4ada7f1aafe8a66ab6dbc1188b9353eacf171576 Mon Sep 17 00:00:00 2001 From: Gaston Gonzalez Date: Thu, 7 Nov 2024 08:41:39 -0700 Subject: [PATCH] et-mode - Added more robust checks for starting services and their dependencies --- overlay/etc/skel/.conkyrc | 3 +- overlay/opt/emcomm-tools/bin/et-mode | 50 +++++++++++++++++++++------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/overlay/etc/skel/.conkyrc b/overlay/etc/skel/.conkyrc index ca48a38..04ba620 100644 --- a/overlay/etc/skel/.conkyrc +++ b/overlay/etc/skel/.conkyrc @@ -36,7 +36,8 @@ CAT : ${execpi 10 et-system-info et-cat} GPS : ${execpi 10 et-system-info et-gps} Audio: ${execpi 10 et-system-info et-audio} -Mode : ${execpi 10 et-system-info et-mode} +${font DejaVu Sans:bold:size=10}${color #8d5133}${alignc}MODE +${font DejaVu Sans Mono:size=11}${color yellow}${execpi 10 et-system-info et-mode} ${font DejaVu Sans:bold:size=10}${color #8d5133}${alignc}OPERATOR ${font DejaVu Sans Mono:size=11}${color yellow}Callsign: ${execpi 10 et-system-info callsign} diff --git a/overlay/opt/emcomm-tools/bin/et-mode b/overlay/opt/emcomm-tools/bin/et-mode index 5d668d3..152e843 100755 --- a/overlay/opt/emcomm-tools/bin/et-mode +++ b/overlay/opt/emcomm-tools/bin/et-mode @@ -2,12 +2,13 @@ # # Author : Gaston Gonzalez # Date : 6 November 2024 +# Updated : 7 November 2024 # Purpose : Configures the system for a specific mode of operation +# Use a simple text file to save the state of the last mode selected MODE_STATUS_FILE="${HOME}/.config/emcomm-tools/et-mode" -# TODO Add better detection between startup services / apps - +# List of supported modes of operation MODE_ID_NONE="none" MODE_ID_APRS_DIGIPEATER="aprs-digipeater" MODE_ID_APRS_CLIENT="aprs-client" @@ -24,6 +25,34 @@ stop_all_services() { systemctl --user stop et-service-direwolf-digipeater } +TIMEOUT=15 # Total time to wait in seconds +INTERVAL=2 # Interval between checks in seconds + +start_and_wait_for_service() { + local systemd_unit_name="$1" + local elapsed=0 + + et-log "Starting ${systemd_unit_name}..." + systemctl --user start ${systemd_unit_name} + + et-log "Waiting for ${systemd_unit_name} to become active..." + + while ! systemctl is-active --user --quiet "${systemd_unit_name}"; do + sleep "$INTERVAL" + elapsed=$((elapsed + INTERVAL)) + if [ "$elapsed" -ge "$TIMEOUT" ]; then + et-log "Timeout reached. ${systemd_unit_name} failed to start." + exit 1 + fi + et-log "Waiting for ${systemd_unit_name} to become active..." + done + + # Some applications even when started still need a bit of extra time to be available. + # Add a short think time of 2 seconds. The ARDOP modem requies extra time. + sleep 2 +} + +# Build list of options options=() options+=("${MODE_ID_NONE}" "No mode selected") options+=("${MODE_ID_APRS_CLIENT}" "APRS Client (YAAC)") @@ -31,6 +60,7 @@ options+=("${MODE_ID_APRS_DIGIPEATER}" "APRS Digipeater") options+=("${MODE_ID_WINLINK_ARDOP}" "Winlink ARDOP") options+=("${MODE_ID_WINLINK_PACKET}" "Winlink Packet") +# Prompt user for option and save exit status SELECTED_MODE=$(dialog --clear --menu "Select a mode:" 20 60 10 "${options[@]}" 3>&1 1>&2 2>&3) exit_status=$? @@ -46,24 +76,20 @@ if [ $exit_status -eq 0 ]; then ;; ${MODE_ID_APRS_DIGIPEATER}) systemctl --user start et-service-direwolf-digipeater + et-log "APRS digipeater now running." ;; ${MODE_ID_APRS_CLIENT}) - systemctl --user start et-service-direwolf-simple - sleep 3 + start_and_wait_for_service et-service-direwolf-simple et-yaac start ;; ${MODE_ID_WINLINK_ARDOP}) - systemctl --user start et-service-ardop - sleep 3 - systemctl --user start et-service-winlink-ardop - sleep 3 + start_and_wait_for_service et-service-ardop + start_and_wait_for_service et-service-winlink-ardop min http://localhost:8080 ;; ${MODE_ID_WINLINK_PACKET}) - systemctl --user start et-service-direwolf-simple - sleep 3 - systemctl --user start et-service-winlink-packet - sleep 2 + start_and_wait_for_service et-service-direwolf-simple + start_and_wait_for_service et-service-winlink-packet min http://localhost:8080 ;; *)