Start the GPSD daemon programmatically in Linux
I’m working on a project to read the GPS value output from a GPS dongle, needed
Start the gpsd daemon programmatically.
i.e. I need to automate the following command;
sudo gpsd/dev/ttyUSB0 -F/var/run/gpsd.sock
After manually starting the daemon as mentioned above, I was able to read the coordinates through the code. But don’t know how to start the daemon through his code.
Because GPSD is a daemon, you can set the daemon to run automatically at startup. How you do this depends on the boot system you have. For example, if you have systemd, you have to write a gpsd.service file, like this
[Unit] Description=GPSd daemon service file [Service] Type=forking User=root Group=dialout TimeoutStartSec=0 ExecStart=/usr/local/sbin/gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock [Install] # Grouping mechanism that let systemd start groups of processes up at the same time WantedBy=multi-user.target
Then install it to /
lib/systemd/system, and finally use the following command
$ sudo systemctl enable gpsd $ sudo systemctl start gpsd
The startup command simply runs gpsd as a systemd daemon without restarting the system.