Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | ### BEGIN INIT INFO |
| 3 | # Provides: gpsd |
| 4 | # Required-Start: $remote_fs $network |
| 5 | # Should-Start: bluetooth dbus udev |
| 6 | # Required-Stop: $remote_fs $network |
| 7 | # Default-Start: 2 3 4 5 |
| 8 | # Default-Stop: 0 1 6 |
| 9 | # Short-Description: GPS (Global Positioning System) daemon start/stop script |
| 10 | # Description: Start/Stop script for the gpsd service daemon, |
| 11 | # which is able to monitor one or more GPS devices |
| 12 | # connected to a host computer, making all data on |
| 13 | # the location and movements of the sensors available |
| 14 | # to be queried on TCP port 2947. |
| 15 | ### END INIT INFO |
| 16 | |
| 17 | # Author: Bernd Zeimetz <bzed@debian.org> |
| 18 | # |
| 19 | # Please remove the "Author" lines above and replace them |
| 20 | # with your own name if you copy and modify this script. |
| 21 | |
| 22 | # Do NOT "set -e" |
| 23 | |
| 24 | # PATH should only include /usr/* if it runs after the mountnfs.sh script |
| 25 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 26 | DESC="GPS (Global Positioning System) daemon" |
| 27 | NAME=gpsd |
| 28 | DAEMON=/usr/sbin/$NAME |
| 29 | PIDFILE=/var/run/$NAME.pid |
| 30 | SCRIPTNAME=/etc/init.d/$NAME |
| 31 | |
| 32 | # Exit if the package is not installed |
| 33 | [ -x "$DAEMON" ] || exit 0 |
| 34 | |
| 35 | # Read configuration, if present |
| 36 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME |
| 37 | |
| 38 | if [ -z "$GPSD_SOCKET" ] && [ -z "$DEVICES" ]; then |
| 39 | GPSD_SOCKET=/var/run/gpsd.sock |
| 40 | fi |
| 41 | |
| 42 | if [ -n "$GPSD_SOCKET" ]; then |
| 43 | GPSD_OPTIONS="$GPSD_OPTIONS -F $GPSD_SOCKET" |
| 44 | fi |
| 45 | |
| 46 | # |
| 47 | # Function that starts the daemon/service |
| 48 | # |
| 49 | do_start() |
| 50 | { |
| 51 | # Return |
| 52 | # 0 if daemon has been started |
| 53 | # 1 if daemon was already running |
| 54 | # 2 if daemon could not be started |
| 55 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test \ |
| 56 | -- $GPSD_OPTIONS -P $PIDFILE $GPS_DEVICES > /dev/null \ |
| 57 | || return 1 |
| 58 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ |
| 59 | $GPSD_OPTIONS -P $PIDFILE $GPS_DEVICES \ |
| 60 | || return 2 |
| 61 | } |
| 62 | |
| 63 | # |
| 64 | # Function that stops the daemon/service |
| 65 | # |
| 66 | do_stop() |
| 67 | { |
| 68 | # Return |
| 69 | # 0 if daemon has been stopped |
| 70 | # 1 if daemon was already stopped |
| 71 | # 2 if daemon could not be stopped |
| 72 | # other if a failure occurred |
| 73 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME |
| 74 | RETVAL="$?" |
| 75 | [ "$RETVAL" = 2 ] && return 2 |
| 76 | # Many daemons don't delete their pidfiles when they exit. |
| 77 | rm -f $PIDFILE |
| 78 | return "$RETVAL" |
| 79 | } |
| 80 | |
| 81 | # |
| 82 | # Function that sends a SIGHUP to the daemon/service |
| 83 | # |
| 84 | do_reload() { |
| 85 | # |
| 86 | # If the daemon can reload its configuration without |
| 87 | # restarting (for example, when it is sent a SIGHUP), |
| 88 | # then implement that here. |
| 89 | # |
| 90 | start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME |
| 91 | return 0 |
| 92 | } |
| 93 | |
| 94 | case "$1" in |
| 95 | start) |
| 96 | echo "Starting $DESC" "$NAME" |
| 97 | do_start |
| 98 | exit $? |
| 99 | ;; |
| 100 | stop) |
| 101 | echo "Stopping $DESC" "$NAME" |
| 102 | do_stop |
| 103 | exit $? |
| 104 | ;; |
| 105 | status) |
| 106 | ;; |
| 107 | reload|force-reload) |
| 108 | echo "Reloading $DESC" "$NAME" |
| 109 | do_reload |
| 110 | exit $? |
| 111 | ;; |
| 112 | restart) |
| 113 | # |
| 114 | # If the "reload" option is implemented then remove the |
| 115 | # 'force-reload' alias |
| 116 | # |
| 117 | echo "Restarting $DESC" "$NAME" |
| 118 | do_stop |
| 119 | case "$?" in |
| 120 | 0|1) |
| 121 | do_start |
| 122 | exit $? |
| 123 | ;; |
| 124 | *) |
| 125 | # Failed to stop |
| 126 | exit 1 |
| 127 | ;; |
| 128 | esac |
| 129 | ;; |
| 130 | *) |
| 131 | echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 |
| 132 | exit 3 |
| 133 | ;; |
| 134 | esac |
| 135 | |
| 136 | : |