mirror of
https://github.com/thetechprepper/emcomm-tools-os-community.git
synced 2026-09-17 15:41:44 -04:00
et-aircraft - Replaced sleep with function that waits for systemd service to become available.
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
# 1. dump1099 systemd service is launched
|
||||
# 2. Web browser is launched with dump1090 map
|
||||
|
||||
# TODO: Check for running service instead of using sleep before Min
|
||||
# TODO: Use icon and add to launcher
|
||||
# TODO: Increse size of aircraft
|
||||
# TODO: Research why RTL-SDR v4 does not work
|
||||
@@ -21,9 +20,13 @@
|
||||
|
||||
source /opt/emcomm-tools/bin/et-common
|
||||
|
||||
CLEAN_UP=1
|
||||
|
||||
cleanup() {
|
||||
et-log "Stopping dump1099 service"
|
||||
systemctl --user stop et-service-dump1090
|
||||
if [[ ${CLEAN_UP} -eq 1 ]]; then
|
||||
et-log "Stopping dump1099 service"
|
||||
systemctl --user stop et-service-dump1090
|
||||
fi
|
||||
}
|
||||
|
||||
# Stop dump1099 on exit
|
||||
@@ -31,11 +34,12 @@ trap cleanup EXIT
|
||||
|
||||
if [[ ! -e ${ET_DEVICE_SDR} ]]; then
|
||||
notify-user "No ${ET_DEVICE_SDR} detected. Reconnect your SDR."
|
||||
CLEAN_UP=0
|
||||
exit 1
|
||||
fi
|
||||
|
||||
systemctl --user restart et-service-dump1090
|
||||
if [[ $? -eq 0 ]]; then
|
||||
sleep 10
|
||||
start_and_wait_for_service et-service-dump1090
|
||||
min http://localhost:1090 2>/dev/null
|
||||
fi
|
||||
|
||||
@@ -29,9 +29,48 @@ notify-user() {
|
||||
notify-send -t 5000 --app-name="EmComm Tools" "$1"
|
||||
}
|
||||
|
||||
exit-if-no-sdr() {
|
||||
exit_if_no_sdr() {
|
||||
if [[ ! -e ${ET_DEVICE_SDR} ]]; then
|
||||
et-log "No ${ET_DEVICE_SDR} detected."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
exit_on_service_failure() {
|
||||
local systemd_unit_name="$1"
|
||||
systemctl is-active --user --quiet "${systemd_unit_name}"
|
||||
if [ $? -ne 0 ]; then
|
||||
et-log "Can't start mode. ${systemd_unit_name} failed to start."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
start_and_wait_for_service() {
|
||||
local timeout=15 # Total time to wait in seconds
|
||||
local interval=2 # Interval between checks in seconds
|
||||
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
|
||||
|
||||
# Do one more check to ensure that we are running, otherwise exit.
|
||||
exit_on_service_failure ${systemd_unit_name}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ source /opt/emcomm-tools/bin/et-common
|
||||
DUMP1090_CONF_DIR="${HOME}/.local/share/emcomm-tools/dump1090"
|
||||
DUMP1090_MAP_HTML="${DUMP1090_CONF_DIR}/gmap.html"
|
||||
|
||||
exit-if-no-sdr
|
||||
exit_if_no_sdr
|
||||
|
||||
if [[ ! -e ${DUMP1090_MAP_HTML} ]]; then
|
||||
et-log "Map HTML not found: ${DUMP1090_MAP_HTML}"
|
||||
|
||||
Reference in New Issue
Block a user