init-babeld 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: babeld
  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: Initscript for babeld
  9. # Description: Babel routing daemon
  10. ### END INIT INFO
  11. # Author: Stéphane Glondu <glondu@debian.org>
  12. # Based on /etc/init.d/skeleton from initscripts_2.87dsf-10 and an
  13. # initscript provided by Juliusz Chroboczek.
  14. # Do NOT "set -e"
  15. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  16. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  17. DESC="Babel routing daemon"
  18. NAME=babeld
  19. DAEMON=/usr/local/bin/$NAME
  20. PIDFILE=/var/run/$NAME.pid
  21. SCRIPTNAME=/etc/init.d/$NAME
  22. # Exit if the package is not installed
  23. [ -x "$DAEMON" ] || exit 0
  24. # Read configuration variable file if it is present
  25. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  26. # Exit if there is no interfaces
  27. if [ -z "$INTERFACES" ]; then
  28. if [ ! -f /etc/babeld.conf ] || [ $(grep -v '^#' /etc/babeld.conf| wc -l) -eq 0 ]; then
  29. echo "$DESC: no interfaces to operate on"
  30. exit 0
  31. fi
  32. fi
  33. # Load the VERBOSE setting and other rcS variables
  34. . /lib/init/vars.sh
  35. # Define LSB log_* functions.
  36. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  37. . /lib/lsb/init-functions
  38. do_start()
  39. {
  40. # Return
  41. # 0 if daemon has been started
  42. # 1 if daemon was already running
  43. # 2 if daemon could not be started
  44. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  45. || return 1
  46. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  47. -D -I $PIDFILE $DAEMON_ARGS $INTERFACES \
  48. || return 2
  49. # Wait for the daemon to be ready
  50. sleep 1
  51. [ -e $PIDFILE ] || sleep 4
  52. [ -e $PIDFILE ] || return 2
  53. }
  54. do_stop()
  55. {
  56. # Return
  57. # 0 if daemon has been stopped
  58. # 1 if daemon was already stopped
  59. # 2 if daemon could not be stopped
  60. # other if a failure occurred
  61. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  62. }
  63. case "$1" in
  64. start)
  65. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  66. do_start
  67. case "$?" in
  68. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  69. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  70. esac
  71. ;;
  72. stop)
  73. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  74. do_stop
  75. case "$?" in
  76. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  77. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  78. esac
  79. ;;
  80. status)
  81. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  82. ;;
  83. restart|force-reload)
  84. log_daemon_msg "Restarting $DESC" "$NAME"
  85. do_stop
  86. case "$?" in
  87. 0|1)
  88. do_start
  89. case "$?" in
  90. 0) log_end_msg 0 ;;
  91. 1) log_end_msg 1 ;; # Old process is still running
  92. *) log_end_msg 1 ;; # Failed to start
  93. esac
  94. ;;
  95. *)
  96. # Failed to stop
  97. log_end_msg 1
  98. ;;
  99. esac
  100. ;;
  101. *)
  102. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  103. exit 3
  104. ;;
  105. esac
  106. :