diff --git a/rootfs/etc/s6-overlay/scripts/gpsd b/rootfs/etc/s6-overlay/scripts/gpsd index 0f82226..636bcf7 100755 --- a/rootfs/etc/s6-overlay/scripts/gpsd +++ b/rootfs/etc/s6-overlay/scripts/gpsd @@ -25,6 +25,7 @@ source /scripts/common s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) GPSD_BIN="/sbin/gpsd" +mkdir -p /run/gpsd GPSD_ARGS=(--nowait) if chk_disabled "$GPSD_START_DAEMON"; then GPSD_ARGS+=(--foreground); fi @@ -43,6 +44,7 @@ if chk_enabled "$GPSD_USBAUTO"; then GPSD_DEVICES="${gps_dev:-${GPSD_DEVICES}}" fi GPSD_ARGS+=("${GPSD_DEVICES}") +echo "${GPSD_DEVICES}" > /run/gpsd/current_device "${s6wrap[@]}" echo "[INFO] Starting: $GPSD_BIN ${GPSD_ARGS[@]}" #shellcheck disable=SC2048,SC2086 diff --git a/rootfs/etc/s6-overlay/scripts/gpsd-watchdog b/rootfs/etc/s6-overlay/scripts/gpsd-watchdog index cf2e584..f9561ef 100755 --- a/rootfs/etc/s6-overlay/scripts/gpsd-watchdog +++ b/rootfs/etc/s6-overlay/scripts/gpsd-watchdog @@ -23,13 +23,15 @@ s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) # this module has a dependency on the gpsd module. It won't start until that module is running. +# wait until the device is known to the gpsd service: +while [[ ! -f /run/gpsd/current_device ]]; do sleep 1; done +read -r gps_dev < /run/gpsd/current_device # sleep a bit to allow gpsd to establish itself -sleep 30 +sleep 5 # determine the current port for the GPS device: if chk_enabled "$GPSD_USBAUTO"; then # if the product name of the serial port device has gps or GPS in it, we can figure out the /dev device link for it: - gps_dev="$(find /dev/serial/by-id/ -iname "*gps*" -printf '%l\n' 2>/dev/null | awk -F/ '{print "/dev/" $NF}')" if [[ -n "$gps_dev" ]]; then "${s6wrap[@]}" echo "[INFO] GPSD_USBAUTO enabled: GPS device auto-detected on $gps_dev" else @@ -41,6 +43,8 @@ fi while [[ -e "$GPSD_DEVICES" ]]; do sleep 15 done +# sometimes it takes a few secs for the new device to become listed +sleep 5 gps_dev_new="$(find /dev/serial/by-id/ -iname "*gps*" -printf '%l\n' 2>/dev/null | awk -F/ '{print "/dev/" $NF}')"