troubleshooting.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head lang="en">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="Author" content="Eric S. Raymond">
  6. <meta name="Description" content="How to bring up a GPS under GPSD">
  7. <meta name="Keywords" content="GPS, gpsd, troubleshooting">
  8. <meta name="Revised" content="3 November 2019">
  9. <meta name="robots" content="index,follow">
  10. <title>Troubleshooting GPSD</title>
  11. <link rel="stylesheet" href="main.css" type="text/css">
  12. </head>
  13. <body>
  14. <div id="Header">Troubleshooting GPSD</div>
  15. <div id="Menu">
  16. <img src="gpsd-logo-small.png" alt="Small gpsd Logo" height="126"
  17. width="105"><br>
  18. <a href="index.html">Home</a><br>
  19. <a href="index.html#news">News</a><br>
  20. <a href="index.html#downloads">Downloads</a><br>
  21. <a href="index.html#mailing-lists">Mailing lists</a><br>
  22. <a href="index.html#documentation">Documentation</a><br>
  23. <a href="faq.html">FAQ</a><br>
  24. <a href="xgps-sample.html">Screenshots</a><br>
  25. <a href="index.html#recipes">Recipes</a><br>
  26. <a href="index.html#others">Other GPSDs</a><br>
  27. <a href="hardware.html">Hardware</a><br>
  28. <a href="for-vendors.html">For GPS Vendors</a><br>
  29. <a href="wishlist.html">Wish List</a><br>
  30. <a href="hall-of-shame.html">Hall of Shame</a><br>
  31. Troubleshooting<br>
  32. <a href="hacking.html">Hacker's Guide</a><br>
  33. <a href="protocol-transition.html">Application Compatibility</a>
  34. <a href="references.html">References</a><br>
  35. <a href="history.html">History</a><br>
  36. <a href="future.html">Future</a><br>
  37. <div>&nbsp;</div>
  38. <a href='http://www.catb.org/hacker-emblem/'><img
  39. src='glider.png' alt='hacker emblem' height="55" width="55"></a><br>
  40. <script src="https://www.openhub.net/p/3944/widgets/project_thin_badge.js"></script>
  41. <hr>
  42. <script><!--
  43. google_ad_client = "pub-1458586455084261";
  44. google_ad_width = 160;
  45. google_ad_height = 600;
  46. google_ad_format = "160x600_as";
  47. google_ad_type = "text";
  48. google_ad_channel = "";
  49. //--></script>
  50. <script src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
  51. </script>
  52. <hr>
  53. <a href="https://validator.w3.org/check/referer"><img
  54. src="https://www.w3.org/Icons/valid-html401"
  55. alt="Valid HTML 4.01!" height="31" width="88"></a>
  56. </div>
  57. <div id="Content">
  58. <h1>Contents</h1>
  59. <p>References like <b>foobar(n)</b> are a Unix convention meaning you
  60. should look up the program <b>foobar</b> using the <b>man</b> utility
  61. for browsing manual pages. Numeric section 1 refers to general
  62. commands and section 8 to administrative commands.</p>
  63. <ol class="ToC">
  64. <li><a href="#firsttry">First Try</a></li>
  65. <li><a href="#gpstroubleshooting">GPS Troubleshooting</a></li>
  66. <li><a href="#usbtroubleshooting">USB Troubleshooting</a></li>
  67. <li><a href="#generaltroubleshooting">General Troubleshooting</a></li>
  68. <li><a href="#startuptroubleshooting">Start at Boot Troubleshooting</a></li>
  69. <li><a href="#telnet" >Telnet</a></li>
  70. <li><a href="#hotplugtroubleshooting">Udev Hotplug Troubleshooting</a></li>
  71. <li><a href="#systemdtroubleshooting" >Systemd Troubleshooting</a></li>
  72. </ol>
  73. <h1 id='firsttry'>First Try</h1>
  74. <p>If you have a USB GPS and have installed from a binary package,
  75. plug your GPS into a USB port and run <code>xgps</code> or
  76. <code>cgps</code>. Very likely you will see fix data appear in the
  77. client. If so, you're done.</p>
  78. <p>If you have a Bluetooth GPS, follow our <a href="bt.html">Bluetooth
  79. instructions</a> and run <code>xgps</code> or <code>cgps</code>. Very
  80. likely you will see fix data appear in the client. If so, you're
  81. done.</p>
  82. <p>If you have a serial (RS232) GPS, plug it into a serial port
  83. connector and jump to <a href="#generaltroubleshooting">General
  84. Troubleshooting</a></p>
  85. <p>We do not yet have troubleshooting instructions for GPSes using
  86. CF (Compact Flash) interfaces. Please contribute some if you can.</p>
  87. <p>If your test client does not show data, keep reading.</p>
  88. <h1 id='gpstroubleshooting'>GPS troubleshooting</h1>
  89. <p>Check that the GPS has power. If it is a USB device, it
  90. needs to be cabled to a USB port to have power. All Bluetooth GPSes
  91. and some serial GPSes are powered by an on-board battery; check that
  92. the battery is present and charged. The GPS may have an on-off switch
  93. which needs to be in the 'on' position.</p>
  94. <p>Most GPSes have a power-on LED; it should be continuously on
  95. or blinking once a second. If it is continuously off, your GPS is dead
  96. or disconnected. Check that it has power.</p>
  97. <h1 id='usbtroubleshooting'>USB troubleshooting</h1>
  98. <p>USB GPSes actually emulate RS232 serial using converter chips.
  99. Under Linux, the <code>usbserial</code> kernel module must be loaded
  100. for correct operation of this class of device. Normally this module
  101. load should happen automatically when the device activates, but if you
  102. don't receive data check for it with <b>lsmod(8)</b>.</p>
  103. <p>On Linux systems with module autoloading disabled or misconfigured,
  104. it is possible you may need to load the module manually with a command
  105. such as <code>sudo modprobe usbserial vendor=0x1a86
  106. product=0x7523</code>. Do not copy those hex numbers slavishly, they
  107. are examples. To get the right numbers, you will need to dig up the
  108. vendor and product ID of your USB-serial converter device.</p>
  109. <p>Run <b>lsusb(8)</b> before and after connecting your GPS; after,
  110. you should see an additional line indicating a new device. Expect the
  111. new line to describe a serial-to-USB adapter chip, often (but not
  112. always) the Prolific Technology PL2303. Then run <b>dmesg(8)</b>,
  113. looking near the end for a message indicating a new USB device of
  114. that kind and giving you the device path - <code>/dev/ttyUSBn</code>
  115. for some number n.</p>
  116. <p>If you have installed a GPSD binary package on a Linux system and
  117. are using a USB GPS, you should not need to start gpsd manually,
  118. because the hotplug system will have done it for you. You should be
  119. able to start a test client (such as <code>cgps</code> or
  120. <code>xgps</code>) and watch it report fixes. If this works, you are
  121. done and can skip the rest of this guide.</p>
  122. <h1 id="generaltroubleshooting">General Troubleshooting</h1>
  123. <h2>Make sure gpsd is not running</h2>
  124. <p>Before doing anything else, make sure there is no instance of gpsd
  125. running:</p>
  126. <pre>sudo killall gpsd</pre>
  127. <p>Remove any sockets gpsd might have left behind, e.g.:</p>
  128. <pre>sudo rm /var/run/gpsd.sock</pre>
  129. <h2>Ensure no other programs are using your device</h2>
  130. <p>Tools like modemmanager might be using your device, probably
  131. automatically attached to it by udev or systemd. To check if your
  132. device is ready to be used by gpsd try running <b>lsof(8)</b>
  133. and search the output for your GPS device path (for example
  134. <code>lsof -n | grep /dev/ttyUSB0</code>). If something is
  135. listed in the output you'll have to stop these processes and
  136. reconfigure them to ignore your GPS device.
  137. <h2>Use gpsmon to check that your device is emitting data</h2>
  138. <p>Try running <b>gpsmon(1)</b>, giving it your GPS device path as an
  139. argument (for example. <code>"gpsmon /dev/ttyUSB0"</code>). After a
  140. few moments to sync up, it should display a screen full of data on the
  141. device, including displaying the raw packet data streaming from it.</p>
  142. <p>If <b>gpsmon(1)</b> reports no data at all, you may have the device
  143. path wrong; check that using <b>dmesg(8)</b> or by whatever means you
  144. have available. If you have the right device, you may have some
  145. low-level system problem with serial or USB that you'll need to fix
  146. before <code>gpsd</code> will operate. Check your cabling, power, and
  147. kernel configuration.</p>
  148. <h2>Launch gpsd to see its progress messages</h2>
  149. <p>You can launch gpsd with the options -N (don't daemonize) and -D
  150. [0-8] (debug and level). This will let it run and send output,
  151. including traffic from the GPS receiver, to the terminal. This is a
  152. recommended first step because it avoids client issues. For example,
  153. here we give gpsd a control socket but no device:</p>
  154. <pre># gpsd -N -D3 -F /var/run/gpsd.sock
  155. gpsd: launching (Version 2.96~dev)
  156. gpsd: listening on port gpsd
  157. gpsd: running with effective group ID 0
  158. gpsd: running with effective user ID 0
  159. ^Cgpsd: received terminating signal 2.
  160. gpsd: exiting.
  161. #</pre>
  162. <p>If you get something like this error message: "gpsd: error while
  163. loading shared libraries: libgpsd.so.0: cannot open shared object
  164. file: No such file or directory" then run ldconfig(8) and try again.</p>
  165. <p>Here we give it a device file. But the device file isn't there, and
  166. there is no receiver.</p>
  167. <pre># gpsd -N -D3 -F /var/run/gpsd.sock /dev/ttyUSB0
  168. gpsd: launching (Version 2.96~dev)
  169. gpsd: listening on port gpsd
  170. gpsd: running with effective group ID 0
  171. gpsd: running with effective user ID 0
  172. gpsd: stashing device /dev/ttyUSB0 at slot 0
  173. ^Cgpsd: received terminating signal 2.
  174. gpsd: exiting.
  175. #</pre>
  176. <p>This time, gpsd stashes the device file and waits for some outside
  177. agency, like udev, to create it. Like so:</p>
  178. <pre># gpsd -N -D3 -F /var/run/gpsd.sock /dev/ttyUSB0
  179. gpsd: launching (Version 2.96~dev)
  180. gpsd: listening on port gpsd
  181. gpsd: running with effective group ID 0
  182. gpsd: running with effective user ID 0
  183. gpsd: stashing device /dev/ttyUSB0 at slot 0
  184. gpsd: control socket connect on fd 6
  185. gpsd: &lt;= control(6): /dev/ttyUSB0 already active
  186. ^Cgpsd: received terminating signal 2.
  187. gpsd: exiting.
  188. #</pre>
  189. <p>If you have udev on your computer, and you don't see gpsd notice
  190. the device (&quot;control socket connect on fd 6&quot;), check to be
  191. sure <a href="#hotplugtroubleshooting">udev is working correctly</a>.</p>
  192. <p>If you pull the plug on the receiver, gpsd will note the change.</p>
  193. <p>With the receiver plugged in and gpsd running as above, you can
  194. launch a client. <code>xgps</code> comes with the distribution.
  195. On some Linuxes, it may be in a separate package, e.g. gpsd-clients.
  196. You should then see a lot of traffic between gpsd and the client in
  197. the gpsd terminal window. For example, here's a fix as reported by
  198. gpsd:</p>
  199. <pre>gpsd: SiRF: MND 0x02: time=1293859466.85 lat=42.64 lon=-118.21 alt=1315.15 track=0.00 speed=0.00 mode=1 status=0 hdop=0.00 used=0 mask={TIME|LATLON|ALTITUDE|SPEED|TRACK|STATUS|MODE|DOP|USED}</pre>
  200. <p>Note that gpsd doesn't try to activate the receiver until it has a
  201. client, and the client asks for data with a ?WATCH request. It also
  202. shuts down its connection to the receiver when it has no clients. This
  203. is a power saving feature.</p>
  204. <p>Another way to verify that gpsd can open the device file is with
  205. lsof(8) (&quot;list open files&quot;):</p>
  206. <pre># lsof | grep ttyU
  207. gpsd 20895 nobody 7u CHR 188,0 0t0 851138 /dev/ttyUSB0
  208. #</pre>
  209. <h1 id="startuptroubleshooting">Troubleshooting Start at Boot</h1>
  210. <p>If gpsd launches at boot, you should be able to start it up or shut
  211. it down with one of the many utilities that manipulate system-V like
  212. startup environments, e.g. service(8). <code>service gpsd
  213. start</code>, etc. works on some Linuxes. sysv-rc-conf(8) is a handy
  214. curses utility for the job. Watch the output.</p>
  215. <p>You can also look at your boot messages with dmesg(1).</p>
  216. <h2>Ubuntu/Debian</h2>
  217. <p>The .deb package supplied for the Debian and Ubuntu Linux
  218. distributions launch at boot either using systemd with gpsd.socket
  219. and gpsd.service, or on older releases from the system V-like script
  220. <code>/etc/init.d/gpsd</code>. However, both are governed by a control
  221. file, <code>/etc/default/gpsd</code>. If necessary, edit the control
  222. file as root.</p>
  223. <p>Please note that systemd will only start gpsd on request
  224. by clients connecting to the unix or tcp socket. In case you need
  225. gpsd to run always, you'll need to configure systemd to start it.
  226. One way would be to create <code>/etc/systemd/system/gpsd.service</code>
  227. with the following content:
  228. </p>
  229. <pre>
  230. [Unit]
  231. Description=GPS (Global Positioning System) Daemon
  232. Requires=gpsd.socket
  233. # Needed with chrony SOCK refclock
  234. After=chronyd.service
  235. [Service]
  236. EnvironmentFile=-/etc/default/gpsd
  237. EnvironmentFile=-/etc/sysconfig/gpsd
  238. ExecStart=/usr/sbin/gpsd -N $GPSD_OPTIONS $DEVICES
  239. [Install]
  240. WantedBy=multi-user.target
  241. Also=gpsd.socket
  242. </pre>
  243. <p>
  244. To ask systemd to reload its config run
  245. <code>systemctl daemon-reload; systemctl reenable gpsd.service</code>.
  246. Instead of using the EnvironmentFile(s) you could just edit the command
  247. line as necessary for your system. Don't forget to run
  248. <code>systemctl daemon-reload</code> after changing the file.
  249. </p>
  250. <p>You will likely want the gpsd-clients package as a debugging
  251. tool. These are the clients maintained as part of the gpsd
  252. project. Other clients may or may not use the right libgpsd or the
  253. right protocol, or something. So make sure gpsd is working correctly
  254. with the gpsd clients. You can always purge them later.</p>
  255. <p>In case you need to debug the gpsd or its clients using gdb or
  256. the python debugger the gpsd-dbg package is provided. It should
  257. contain all necessary debug symbols to create useful backtraces.</p>
  258. <p>If you have a prior installation of gpsd from a deb package, and
  259. are switching to compiling your own, from a recent tarball or from the
  260. git repository, it is not enough to <code>apt-get remove</code> the
  261. prior installation. You must <code>apt-get purge</code> them. This
  262. removes some configuration files left behind by remove.</p>
  263. <p>If you do compile your own gpsd, be aware that installing gpsd
  264. client packages can force installation of gpsd as well. This can also
  265. happen on debian systems when apt is set up to install recommended
  266. packages as dependencies.</p>
  267. <p>One culprit is packages like
  268. <a href="http://www.tangogps.org/">tangogps</a>, which recommendd gpsd.
  269. Fortunately, since it recommends gpsd, you can install it using
  270. <code>apt-get install --no-install-recommends</code> or disable the
  271. installation of recommended packages permanently. Put the following in
  272. a file with a high leading number in <code>/etc/apt/apt.conf.d</code>,
  273. e.g. <code>90no.recommendations</code>:</p>
  274. <pre>APT::Install-Recommends &quot;false&quot;;
  275. </pre>
  276. <p>Other client packages may not be so lenient, but you can use the
  277. tool <b>equivs</b> to create an empty fake package which provides
  278. gpsd.</p>
  279. <h2>Red Hat</h2>
  280. <p>The rpm package made from the gpsd distribution will launch at boot
  281. from the script <code>/etc/init/rc.d/gpsd</code>. It is governed by
  282. the file <code>/etc/sysconfig/gpsd</code>, although it it doesn't find
  283. that file, it will provide its own defaults.</p>
  284. <p>You will likely want the gpsd-clients package as a debugging
  285. tool. These are the clients maintained by the gpsd developers. Other
  286. clients may or may not use the right libgpsd or the right protocol, or
  287. something. So make sure gpsd is working correctly with the gpsd
  288. clients. You can always purge them later.</p>
  289. <h1 id="telnet">Telnet</h1>
  290. <p>Telnet provides a quick and dirty acceptance test for gpsd. Other
  291. clients (<code>cgps</code>, <code>xgps</code>, and other)
  292. are preferable, so consider telnet a last ditch tool. You can telnet
  293. into gpsd:</p>
  294. <pre>$ telnet localhost 2947
  295. Trying ::1...
  296. Trying 127.0.0.1...
  297. Connected to localhost.
  298. Escape character is '^]'.
  299. {&quot;class&quot;:&quot;VERSION&quot;,&quot;release&quot;:&quot;2.96~dev&quot;,&quot;rev&quot;:&quot;2011-03-15T03:05:33&quot;,&quot;proto_major&quot;:3,&quot;proto_minor&quot;:4}
  300. </pre>
  301. <p>Note that the <code>release</code> strings will be different in
  302. your case.</p>
  303. <p>To see data from the receiver in JSON (if any), enter the command
  304. <samp>?WATCH={&quot;enable&quot;:true,&quot;json&quot;:true}</samp>. To
  305. end JSON output, <samp>?WATCH={&quot;enable&quot;:false}</samp>. Then
  306. control-] and &quot;exit&quot; to exit the telnet client.</p>
  307. <p>For more information, see <a
  308. href="client-howto.html#_how_the_gpsd_wire_protocol_works" >How the
  309. GPSD wire protocol works</a> in the <a href="client-howto.html" >GPSD
  310. Client HOWTO</a>.</p>
  311. <h1 id="hotplugtroubleshooting">Udev Hotplug Troubleshooting</h1>
  312. <p>The Linux udev system has been prone to change out from under us,
  313. breaking our hotplug support for USB receivers. Accordingly, here's a
  314. short guide to verifying that the different pieces are working
  315. correctly, with indications of where to troubleshoot on failure.</p>
  316. <p>First, verify that your USB subsystem can see your receiver. Run
  317. lsusb(1). Plug the receiver in and run lsusb(1) again, looking for
  318. the extra line - it will be identified by a serial-to-USB converter
  319. chip type such as a PL2303. Unplug the receiver and verify that the
  320. line describing the device is gone.</p>
  321. <p>If this test fails, something very basic is wrong at hardware
  322. level. If your receiver has a two-section cable joined by something
  323. like a <a
  324. href="https://en.wikipedia.org/wiki/Mini-DIN_connector">6-pin
  325. mini-DIN connector</a>, with a component housing between that and the
  326. USB plug, be aware that the serial converter may live in that housing
  327. and you have to unplug the <b>entire cable</b> from your computer, not
  328. just separate the halves of the mini-DIN connector. If there is no
  329. such joint, it may be that your receiver is defective or dead. See
  330. your vendor documentation for help in diagnosis. The least likely
  331. failure is for the USB hardware on the PC side to be buggy.</p>
  332. <p>The next thing to try is watching the hotplug events in your system
  333. logs. Do <code>tail -f /var/log/syslog</code>; plug in and unplug the
  334. receiver. You should see messages indicating from the USB subsystem
  335. in the kernel indicating device connect and disconnect. If you don't,
  336. check your kernel configuration; USB support may be absent or
  337. misconfigured.</p>
  338. <p>Now we involve the udev system. Unplug the receiver. If you are
  339. compiling gpsd, run <code>make udev-install</code> from the source
  340. directory to install the required udev rules. (There is a <code>make
  341. udev-uninstall</code> for cleaning up after this test.) If you are
  342. using a package, your package manager will install these files for
  343. you. Do <code>tail -f /var/log/syslog</code>. Now plug in the
  344. receiver.</p>
  345. <p>You should see messages that include something like the following
  346. text (the USB device may vary):</p>
  347. <pre>
  348. gpsd.hotplug: gpsd_control(action=add, arg=/dev/ttyUSB0)
  349. gpsd.hotplug: launching gpsd -F /var/run/gpsd.sock
  350. </pre>
  351. <p>These are from the gpsd.hotplug handler called by udev on a hotplug
  352. event matching one of the known udev types for a USB GPS, and indicating
  353. the launch of a gpsd instance.</p>
  354. <p>If you don't see this, several things could be going wrong. The
  355. udev rules may not be installed correctly. Or the handler they call
  356. may be unable to run for some reason; it has two layers, a shell script
  357. wrapper around a little Python program that does the real work. You
  358. may have to figure out where the udev log messages go on your system
  359. and use udevadm(8) to crank up the log level until you can see what's
  360. going on.</p>
  361. <p>If your GPS uses an unusual serial-to-USB converter, the GPSD rules
  362. may not recognize it as a probable GPS. You'll need to look at the
  363. converter type indicated in the lsusb(1) listing and match it against
  364. the rules in the gpsd.rules file. If it's not known, please report
  365. this as a bug to the GPSD developers.</p>
  366. <p>Once you know that udev can launch gpsd, you'll want to watch what
  367. it's doing with the hotplug notifications. Unplug the receiver and
  368. kill the running gpsd instance, if there is one. Now run <code>make
  369. udev-test</code> and plug in the receiver. (For those using packages,
  370. this is the equivalent of &quot;<code>gpsd -N -n -F /var/run/gpsd.sock
  371. -D 5</code>&quot;.) </p>
  372. <p>You can also launch the hotplug code manually: <code>cd /lib/udev
  373. &amp;&amp; ./gpsd.hotplug add /dev/ttyUSB0</code> If this fails, there is
  374. something wrong with the hotplug code. If it succeeds, the problem may
  375. be in how udev is calling gpsd.hotplug, or udev may never call
  376. gpsd.hotplug.</p>
  377. <p>You should see log messages from gpsd indicating that the control
  378. socket has received a command to add the device, and then data
  379. from the device. When you unplug and replug the device, gpsd
  380. should emit messages about the device closes and opens.</p>
  381. <p>If you don't see this, there's a bug or misconfiguration
  382. somewhere. Check to make sure the hotplug handler and gpsd have
  383. matching expectations about the location of the control socket.</p>
  384. <p>If you do see these device file opens and closes logged, the
  385. udev end of the configuration is working.</p>
  386. <h1 id="systemdtroubleshooting">Systemd Troubleshooting</h1>
  387. <h2>Systemd Interaction</h2>
  388. <p>gpsd must be installed. We want gpsd itself and, for testing, the gpsd clients, at least cgps and possibly xgps.</p>
  389. <p>gpsd must running and reading from the GPS receiver. For general gpsd debugging, it is helpful to know that gpsd is running, and that the GPS receiver device file is present. For a u-blox receiver:</p>
  390. <pre>root@orca:~# ps aux | grep -i gpsd | grep -v grep ; ls /dev/ttyA*
  391. gpsd 14547 0.5 0.0 18092 3504 ? S&lt;sl 15:44 0:00 /usr/sbin/gpsd
  392. /dev/ttyACM0
  393. root@orca:~#</pre>
  394. <p>(Devices file names vary. <code>/dev/ttyU*</code> is typical.)</p>
  395. <p>If gpsd isn't running, check other parts of this document, and <a href="https://gitlab.com/gpsd/gpsd/blob/master/INSTALL" >INSTALL</a> in the root of the <a href="https://gitlab.com/gpsd/gpsd" >git repo</a>.</p>
  396. <p>The next question is, is gpsd controlled by systemd?</p>
  397. <h3>Systemd isn't installed</h3>
  398. <p>Your problem lies elsewhere.</p>
  399. <h3>Systemd is present but but does not manage gpsd.</h3>
  400. <p>You can use systemd's tools to check. <code><a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#status%20PATTERN%E2%80%A6%7CPID%E2%80%A6%5D" >systemctl status</a> gpsd</code> should tell you what systemd thinks gpsd's status is.</p>
  401. <pre>
  402. root@orca:~# <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#status%20PATTERN%E2%80%A6%7CPID%E2%80%A6%5D" >systemctl status</a> gpsd
  403. ● gpsd.service - GPS (Global Positioning System) Daemon
  404. Loaded: loaded (/lib/systemd/system/gpsd.service; enabled; vendor preset: enabled)
  405. Active: active (running) since Thu 2019-10-03 15:07:01 MDT; 1 weeks 2 days ago
  406. Main PID: 32454 (gpsd)
  407. Tasks: 1 (limit: 4915)
  408. Memory: 924.0K
  409. CGroup: /system.slice/gpsd.service
  410. └─32454 /usr/sbin/gpsd
  411. Oct 03 15:07:01 orca systemd[1]: Starting GPS (Global Positioning System) Daemon...
  412. Oct 03 15:07:01 orca systemd[1]: Started GPS (Global Positioning System) Daemon.
  413. root@orca:~#
  414. </pre>
  415. <p>This example shows that systemd clearly does control gpsd. If systemd replies something like <code>Unit gpsd.service could not be found.</code>, systemd is present but does not control gpsd.</p>
  416. <p>Alternatively, see if any of the files <code>gpsd.*</code> are present under systemd's directories. That location is system dependent, but <code>/lib/systemd/system/</code> is typical. Or use <code>locate</code> or your package manager to check.</p>
  417. <p>If systemd is present but does not control gpsd, your problem lies elsewhere.</p>
  418. <h3>Systemd is present and controls gpsd</h3>
  419. <p>Your tool for interacting with systemd is <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html" >systemctl</a>. The typical syntax is</p>
  420. <pre>systemctl [OPTIONS...] COMMAND [UNIT...]</pre>
  421. <p>For the gory details, see the <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html" >systemctl man page</a>. Generally useful commands include: <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#daemon-reload" >daemon-reload</a>, <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#disable%20UNIT%E2%80%A6" >disable</a>, <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#enable%20UNIT%E2%80%A6" >enable</a>, <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#reload%20PATTERN%E2%80%A6" >reload</a>, <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#restart%20PATTERN%E2%80%A6" >restart</a>, <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#show%20PATTERN%E2%80%A6%7CJOB%E2%80%A6" >show</a>, <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#start%20PATTERN%E2%80%A6" >start</a>, <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#status%20PATTERN%E2%80%A6%7CPID%E2%80%A6%5D" >status</a>, and <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#stop%20PATTERN%E2%80%A6" >stop</a>. Note that daemon-reload and reload are not the same command. reload tells a unit to reload its configuration file (if it can do so). daemon-reload has systemd reload all unit files and its own configuration file.</p>
  422. <p>If you want to shut gpsd down, you have to shut down both units. Shutting down gpsd.service alone is not sufficient because gpsd.socket could fire it up again.</p>
  423. <pre><a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#stop%20PATTERN%E2%80%A6" >systemctl stop</a> gpsd.socket gpsd.service</pre>
  424. <p>Note: issuing the stop command may not actually stop the service. On a Debian system out of the box, systemd starts gpsd up again.</p>
  425. <h2>Real World Example</h2>
  426. <p>For security, gpsd by default is shipped set up to listen only on the loopback interface, thereby restricting its audience to clients on the same computer. We'd like to allow other computers to listen in as well. This means:</p>
  427. <ul>
  428. <li>Opening the firewall at the gpsd assigned port, 2947. That is beyond the scope of this document.</li>
  429. <li>Adding the appropriate switch to the command line for gpsd. While we're at it, we'll also add the -n switch.</li>
  430. <li>Changing the gpsd.socket unit so that other clients can connect to the daemon.</li>
  431. </ul>
  432. <p>Once we know gpsd is running, we modify <code>/etc/default/gpsd</code> to provide the options we want. One to listen on all the interfaces (-G), and one to tell gpsd not to wait for a client to connect before polling (-n). The GPSD_OPTIONS stanza now looks like:</p>
  433. <pre>
  434. # Other options you want to pass to gpsd
  435. # GPSD_OPTIONS=""
  436. GPSD_OPTIONS="-Gn"
  437. </pre>
  438. <p>We can stop gpsd. Systemd will restart it for us, this time with the options in place. We then verify that the options are there:</p>
  439. <pre>root@orca:~# <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#stop%20PATTERN%E2%80%A6" >systemctl stop</a> gpsd.socket gpsd.service
  440. root@orca:~# ps aux | grep -i gpsd | grep -v grep
  441. gpsd 14547 0.5 0.0 18092 3504 ? S&lt;sl 15:44 0:00 /usr/sbin/gpsd -Gn
  442. root@orca:~#</pre>
  443. <p>But we aren't there yet. gpsd may be listening on all interfaces, but systemd's hold on the socket means gpsd can't hear anything on interfaces other than the loopback. We have to tell systemd to allow gpsd to hear other interfaces. We run <code><a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#edit%20UNIT%E2%80%A6" >systemctl edit --full gpsd.socket</a></code>. Then we can edit it. After editing, the [Socket] stanza looks like so:</p>
  444. <pre>
  445. [Socket]
  446. ListenStream=/var/run/gpsd.sock
  447. ListenStream=[::1]:2947
  448. # ListenStream=127.0.0.1:2947
  449. ListenStream=0.0.0.0:2947
  450. SocketMode=0600
  451. </pre>
  452. <p>When you are done editing, systemctl does what it needs to do internally to preserve your changes from being over-written during upgrades. It also does the equivalent of a <code>systemctl daemon-reload</code> for you.</p>
  453. <p>We now restart both gpsd units like so:</p>
  454. <pre><a href="https://www.freedesktop.org/software/systemd/man/systemctl.html#restart%20PATTERN%E2%80%A6" >systemctl restart</a> gpsd.socket gpsd.service</pre>
  455. <p>Now check with a local client, and a client on the remote computer:</p>
  456. <pre>xgps &lt;host&gt;</pre>
  457. <p>Where &lt;host&gt; in our example is orca. As usual, if you see data in the client, you're done.</p>
  458. <hr>
  459. <script src="datestamp.js"></script>
  460. </div>
  461. </body>
  462. </html>