Niana
Niana

Reputation: 1047

Start gpsd service at reboot

I am using a GPS hat from adafruit.

According to the document

Start gpsd and direct it to use HW UART. Simply entering the following command:

sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock

While this does in fact work, I am trying to find a way to automatically call this on a reboot. I've tried putting it in a .py file and calling it when the machine restarts in a cronjob but that doesn't work. (Invalid Syntax). Hoping I could be assisted in accomplishing this.

Thank you

Upvotes: 4

Views: 6118

Answers (1)

urban
urban

Reputation: 5682

The fastest and easiest way is to put the above command in /etc/rc.local file (without sudo!). This is a shell script invoked on boot.

A more proper way of doing this is to create a service file into /etc/init.d directory. To start see any simple file into that directory, copy and modify it and make sure is executable. Basic (untested) example:

#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          gpsd
# Required-Start:    
# Required-Stop:
# Default-Start:     1 2 3 4 5
# Default-Stop:
# Short-Description: Run my GPSd
### END INIT INFO
#

case "$1" in
  start)
    gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock
    ;;
  stop)
    killall -KILL gpsd
    ;;
  restart|force-reload)
    killall -KILL gpsd
    sleep 3
    gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock
    ;;
  *) echo "Usage: $0 {start|stop|restart|force-reload}" >&2; exit 1 ;;
esac

Once you have that make sure it is enabled on boot, so your system will automatically call service gpsd start. This is done with the update-rc.d command on Debian-base distros and systemctl on RHEL.

If you let us know your linux distro we can be more specific.

Upvotes: 2

Related Questions