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.
 
 
 
 
 
 

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