Devuan fork of gpsd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

161 lines
4.0 KiB

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