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