avahi-daemon 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: avahi
  4. # Required-Start: $remote_fs dbus
  5. # Required-Stop: $remote_fs dbus
  6. # Should-Start: $syslog
  7. # Should-Stop: $syslog
  8. # Default-Start: 2 3 4 5
  9. # Default-Stop: 0 1 6
  10. # Short-Description: Avahi mDNS/DNS-SD Daemon
  11. # Description: Zeroconf daemon for configuring your network
  12. # automatically
  13. ### END INIT INFO
  14. #
  15. # This file is part of avahi.
  16. #
  17. # avahi is free software; you can redistribute it and/or modify it
  18. # under the terms of the GNU Lesser General Public License as
  19. # published by the Free Software Foundation; either version 2 of the
  20. # License, or (at your option) any later version.
  21. #
  22. # avahi is distributed in the hope that it will be useful, but WITHOUT
  23. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  24. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  25. # License for more details.
  26. #
  27. # You should have received a copy of the GNU Lesser General Public
  28. # License along with avahi; if not, write to the Free Software
  29. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  30. # USA.
  31. #
  32. # avahi avahi daemon
  33. # Daemon for ZeroConf
  34. #
  35. # Authors: <sebastien.estienne@gmail.com>
  36. #
  37. if [ -f /lib/lsb/init-functions ]
  38. then
  39. . /lib/lsb/init-functions
  40. else
  41. # int log_begin_message (char *message)
  42. log_begin_msg () {
  43. if [ -z "$1" ]; then
  44. return 1
  45. fi
  46. echo " * $@"
  47. }
  48. # int log_end_message (int exitstatus)
  49. log_end_msg () {
  50. # If no arguments were passed, return
  51. [ -z "$1" ] && return 1
  52. # Only do the fancy stuff if we have an appropriate terminal
  53. # and if /usr is already mounted
  54. TPUT=/usr/bin/tput
  55. EXPR=/usr/bin/expr
  56. if [ -x $TPUT ] && [ -x $EXPR ] && $TPUT hpa 60 >/dev/null 2>&1; then
  57. COLS=`$TPUT cols`
  58. if [ -n "$COLS" ]; then
  59. COL=`$EXPR $COLS - 7`
  60. else
  61. COL=73
  62. fi
  63. UP=`$TPUT cuu1`
  64. END=`$TPUT hpa $COL`
  65. START=`$TPUT hpa 0`
  66. RED=`$TPUT setaf 1`
  67. NORMAL=`$TPUT op`
  68. if [ $1 -eq 0 ]; then
  69. echo "$UP$END[ ok ]"
  70. else
  71. echo -e "$UP$START $RED*$NORMAL$END[${RED}fail${NORMAL}]"
  72. fi
  73. else
  74. if [ $1 -eq 0 ]; then
  75. echo " ...done."
  76. else
  77. echo " ...fail!"
  78. fi
  79. fi
  80. return $1
  81. }
  82. log_warning_msg () {
  83. if log_use_fancy_output; then
  84. YELLOW=`$TPUT setaf 3`
  85. NORMAL=`$TPUT op`
  86. echo "$YELLOW*$NORMAL $@"
  87. else
  88. echo "$@"
  89. fi
  90. }
  91. fi
  92. #set -e
  93. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  94. DESC="Avahi mDNS/DNS-SD Daemon"
  95. NAME="avahi-daemon"
  96. DAEMON="/usr/sbin/$NAME"
  97. SCRIPTNAME=/etc/init.d/$NAME
  98. # Gracefully exit if the package has been removed.
  99. test -x $DAEMON || exit 0
  100. # don't start if /etc/default/avahi-daemon says so.
  101. AVAHI_DAEMON_START=1
  102. test -f /etc/default/avahi-daemon && . /etc/default/avahi-daemon
  103. if [ "$AVAHI_DAEMON_START" != "1" -a "$1" != "stop" ]; then
  104. log_warning_msg "Not starting $DESC $NAME, disabled via /etc/default/$NAME"
  105. exit 0
  106. fi
  107. #
  108. # Function that starts the daemon/service.
  109. #
  110. d_start() {
  111. modprobe capability >/dev/null 2>&1 || true
  112. $DAEMON -c && return 0
  113. if [ -s /etc/localtime ]; then
  114. if [ ! -d /etc/avahi/etc ]; then
  115. mkdir -p /etc/avahi/etc >/dev/null 2>&1
  116. fi
  117. cp -fp /etc/localtime /etc/avahi/etc >/dev/null 2>&1
  118. fi;
  119. $DAEMON -D
  120. }
  121. #
  122. # Function that stops the daemon/service.
  123. #
  124. d_stop() {
  125. $DAEMON -c && $DAEMON -k
  126. }
  127. #
  128. # Function that reload the config file for the daemon/service.
  129. #
  130. d_reload() {
  131. $DAEMON -c && $DAEMON -r
  132. }
  133. #
  134. # Function that check the status of the daemon/service.
  135. #
  136. d_status() {
  137. $DAEMON -c
  138. status=$?
  139. if [ $status = 0 ]; then
  140. echo "$DESC is running"
  141. return 0
  142. else
  143. echo "$DESC is not running"
  144. return 3
  145. fi
  146. }
  147. case "$1" in
  148. start)
  149. log_begin_msg "Starting $DESC: $NAME"
  150. d_start
  151. log_end_msg $?
  152. ;;
  153. stop)
  154. log_begin_msg "Stopping $DESC: $NAME"
  155. d_stop
  156. log_end_msg $?
  157. ;;
  158. reload)
  159. log_begin_msg "Reloading services for $DESC: $NAME"
  160. d_reload
  161. log_end_msg $?
  162. ;;
  163. restart|force-reload)
  164. log_begin_msg "Restarting $DESC: $NAME"
  165. $DAEMON -c && d_stop
  166. d_start
  167. log_end_msg $?
  168. ;;
  169. status)
  170. d_status
  171. ;;
  172. *)
  173. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload|status}" >&2
  174. exit 1
  175. ;;
  176. esac
  177. exit $?