systemd - 通过网络访问 GPSD 端口 2947

标签 systemd gpsd

使用 digitalbarbedwire.com 上的帖子中的信息,使用最新的 Jessie Lite Raspbian Jan 2017、Adafruit Ultimate GPS 帽子和 PPS 获得 RPI2。设置简单,PPS 和所有 GPS 命令在本地都能很好地工作。

我正在尝试让 gpsd 在端口 2947 上接受通过网络传入的请求,以导出位置信息 (OpenCPN)。我编辑了/etc/default/gpsd 以添加 -G 选项 GPSD_OPTIONS="-n -G"但不允许外部请求。如果我停止 gpsd (sudo service stop gpsd),并在前台调用 gps (/usr/sbin/gpsd -N -n -G/dev/ttyAMA0/dev/pps0,一切正常!所以我猜测有一个将 gpsd 作为守护进程启动的权限问题,但我还没有弄清楚。快把我逼疯了!

有什么建议吗?

相关文件:

$ cat /lib/systemd/system/gpsd.socket
[Unit]
Description=GPS (Global Positioning System) Daemon Sockets

[Socket]
ListenStream=/var/run/gpsd.sock
ListenStream=[::1]:2947
ListenStream=0.0.0.1:2947
SocketMode=0600

[Install]
WantedBy=socket

$ cat /etc/default/gpsd
# Default settings for the gpsd init script and the hotplug wrapper.

# Start the gpsd daemon automatically at boot time
START_DAEMON="true"

# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="true"


# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/dev/ttyAMA0 /dev/pps0"

# Other options you want to pass to gpsd
GPSD_OPTIONS="-n"

$ cat /lib/systemd/system/gpsd.service
[Unit]
Description=GPS (Global Positioning System) Daemon
Requires=gpsd.socket
# Needed with chrony SOCK refclock
After=chronyd.service

[Service]
EnvironmentFile=-/etc/default/gpsd
ExecStart=/usr/sbin/gpsd -N -G $GPSD_OPTIONS $DEVICES

[Install]
Also=gpsd.socket

有什么想法吗?

最佳答案

Gpsd 实际上并未监听端口 2947,而 systemd 却在监听。默认情况下,在 Debian 中这只是本地的。当请求传入时,systemd 会启动 gpsd(如有必要),并将 future 的请求重定向到守护进程。因此给 gpsd 提供 -G 参数实际上不会改变任何东西。

您需要为 systemd gpsd.socket 单元添加覆盖,并告诉它监听所有地址:

# /etc/systemd/system/gpsd.socket.d/socket.conf
[Socket]
# First blank ListenStream clears the system defaults
ListenStream=
ListenStream=2947
ListenStream=/var/run/gpsd.sock

最佳实践是将此覆盖文件放在/etc/systemd/中,而不是编辑/lib/systemd/中的单元文件。

有关 systemd.socket 语法的文档:https://www.freedesktop.org/software/systemd/man/systemd.socket.html

关于systemd - 通过网络访问 GPSD 端口 2947,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42240757/

相关文章:

linux - 在 Linux 中使用 systemd 启动脚本

unix - 使用gpsd或cgps返回纬度和经度,然后退出

c++ - GPSD 提供错误的时间

NMEA AIS 位置消息完成 UTC 时间戳获取

python - gpsd python 客户端

Systemd 服务未启动我的应用程序

systemd - 设置 systemd journalctl 以忽略进程

Systemd: 'User' 部分中的未知左值 'Unit'

linux - CentOS 的 systemctl/服务调用期间的用户输入?

linux - Scons 在 gpsd 中发现无效语法