home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / init.d / avahi-daemon < prev    next >
Encoding:
Text File  |  2007-03-27  |  4.2 KB  |  189 lines

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