rtl_airband-debian.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: rtl_airband
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: rtl_airband initscript
  9. ### END INIT INFO
  10. # Author: Tomasz Lemiech <szpajder@gmail.com>
  11. PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
  12. DESC="RTLSDR airband receiver"
  13. NAME=rtl_airband
  14. DAEMON=/usr/local/bin/$NAME
  15. DAEMON_ARGS=""
  16. PIDFILE=/run/$NAME.pid
  17. SCRIPTNAME=/etc/init.d/$NAME
  18. # Exit if the package is not installed
  19. [ -x "$DAEMON" ] || exit 0
  20. # Read configuration variable file if it is present
  21. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  22. # Load the VERBOSE setting and other rcS variables
  23. . /lib/init/vars.sh
  24. # Define LSB log_* functions.
  25. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  26. # and status_of_proc is working.
  27. . /lib/lsb/init-functions
  28. #
  29. # Function that starts the daemon/service
  30. #
  31. do_start()
  32. {
  33. # Return
  34. # 0 if daemon has been started
  35. # 1 if daemon was already running
  36. # 2 if daemon could not be started
  37. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  38. || return 1
  39. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  40. $DAEMON_ARGS \
  41. || return 2
  42. # on this one. As a last resort, sleep for some time.
  43. }
  44. do_stop()
  45. {
  46. # Return
  47. # 0 if daemon has been stopped
  48. # 1 if daemon was already stopped
  49. # 2 if daemon could not be stopped
  50. # other if a failure occurred
  51. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  52. RETVAL="$?"
  53. [ "$RETVAL" = 2 ] && return 2
  54. # Wait for children to finish too if this is a daemon that forks
  55. # and if the daemon is only ever run from this initscript.
  56. # If the above conditions are not satisfied then add some other code
  57. # that waits for the process to drop all resources that could be
  58. # needed by services started subsequently. A last resort is to
  59. # sleep for some time.
  60. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  61. [ "$?" = 2 ] && return 2
  62. rm -f $PIDFILE
  63. return "$RETVAL"
  64. }
  65. case "$1" in
  66. start)
  67. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  68. do_start
  69. case "$?" in
  70. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  71. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  72. esac
  73. ;;
  74. stop)
  75. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  76. do_stop
  77. case "$?" in
  78. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  79. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  80. esac
  81. ;;
  82. status)
  83. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  84. ;;
  85. restart|force-reload)
  86. log_daemon_msg "Restarting $DESC" "$NAME"
  87. do_stop
  88. case "$?" in
  89. 0|1)
  90. do_start
  91. case "$?" in
  92. 0) log_end_msg 0 ;;
  93. 1) log_end_msg 1 ;; # Old process is still running
  94. *) log_end_msg 1 ;; # Failed to start
  95. esac
  96. ;;
  97. *)
  98. # Failed to stop
  99. log_end_msg 1
  100. ;;
  101. esac
  102. ;;
  103. *)
  104. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  105. exit 3
  106. ;;
  107. esac
  108. :