summaryrefslogtreecommitdiff
path: root/system/gpsd/rc.gpsd.new
blob: 0eee30306a15a080266ccb5ff6be244a10e8a1f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh

# /etc/rc.d/rc.gpsd
# Start/stop/restart gpsd
# Sebastian Arcus and David Spencer
#
# To enable automatic discovery of your GPS device by udev, uncomment the
# appropriate line of /etc/udev/rules.d/97-gpsd.rules
#
# Configuration options may be set in /etc/rc.d/rc.gpsd.conf
# but the defaults will usually be adequate.

gpsd_start() {

  if [ ! -x /lib/udev/gpsd.hotplug.wrapper ]; then
    echo "$(basename $0): /lib/udev/gpsd.hotplug.wrapper not found (or not executable); cannot start."
  fi

  if [ -r /etc/rc.d/rc.gpsd.conf ]; then
    . /etc/rc.d/rc.gpsd.conf
  fi
  # Set config defaults in case the .conf file was absent or bogus
  GPSD_DEVICES="${GPSD_DEVICES:-/dev/gps*}"
  GPSD_OPTIONS="${GPSD_OPTIONS:-}"
  GPSD_SOCKET="${GPSD_SOCKET:-/var/run/gpsd.sock}"

  for DEVNAME in $GPSD_DEVICES; do
    if [ -e $DEVNAME ]; then
      echo "$(basename $0): Starting gpsd for $DEVNAME"
      ACTION=add DEVNAME=$DEVNAME /lib/udev/gpsd.hotplug.wrapper
    else
      echo "$(basename $0): $DEVNAME not found, gpsd not started"
    fi
  done

}

gpsd_stop() {
  echo "Stopping gpsd..."
  killall gpsd >/dev/null 2>&1
  return 0
}

case "$1" in
  start)
    gpsd_start
    ;;
  stop)
    gpsd_stop
    ;;
  restart)
    gpsd_stop
    sleep 1
    gpsd_start
    ;;
  *)
    echo "Usage: $0 start|stop|restart"
    exit 1
    ;;
esac