Skip to content

Commit

Permalink
make gpsd-watchdog more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
kx1t committed Nov 17, 2023
1 parent 9cddfde commit 0100c38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/scripts/gpsd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions rootfs/etc/s6-overlay/scripts/gpsd-watchdog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}')"

Expand Down

0 comments on commit 0100c38

Please sign in to comment.