Alan Eneev commented:
Happy to share! Here is our systemd unit config:
[Unit]
# This unit is needed to shield gpsd from GPS device restarts. It forwards
# connections from gpsd to GPS device. If either end of the connection fails,
# socat will terminate, and systemd will restart socat. GPSd also depends on
# this service, so systemd will restart gpsd as well.
#
# Socat listen on 0.0.0.0:44444 and "forwards" to 192.168.1.100:44444.
Description=TCP connection relay for GPSd
# Start this before GPSd, and after we're online.
Before=gpsd.service
After=network-online.target
[Service]
# Summary of used flags:
# -T3 inactivity timeout (3 seconds). GPS devices are supposed to be very
# chatty, so 3 second silence warrants a restart.
# -ly log to systemd
# -U unidirectional mode -- write into the first address, from the second address
# -d -d more verbose logs
# connect-timeout=5
# This option for the second address means that socat will exit
# with an error if it fails to establish connection within
# specified timeout (seconds).
# This means if we fail to establish connection with GPS device
# within 5 seconds, socat will exit, and systemd will retry it.
ExecStart=/usr/bin/socat -T3 -ly -U -d -d TCP-LISTEN:44444 TCP:192.168.1.100:44444,connect-timeout=5
PermissionsStartOnly=true
TimeoutSec=2
Restart=always
[Install]
# Make this a dependency of GPSd. Required to restart GPSd when this unit terminates.
RequiredBy=gpsd.service