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-dnsconfd avahi dns configuration daemon 22 # Daemon for ZeroConf 23 # 24 # Authors: <sebastien.estienne (at] gmail.com> 25 # 26 27 if [ -f /lib/lsb/init-functions ] 28 then 29 . /lib/lsb/init-functions 30 else 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 86 fi 87 88 #set -e 89 90 PATH=/sbin:/bin:/usr/sbin:/usr/bin 91 DESC="Avahi Unicast DNS Configuration Daemon" 92 NAME="avahi-dnsconfd" 93 DAEMON="@sbindir@/$NAME" 94 SCRIPTNAME=/etc/init.d/$NAME 95 96 # Gracefully exit if the package has been removed. 97 test -x $DAEMON || exit 0 98 99 # don't start if /etc/default/avahi-dnsconfd says so. 100 AVAHI_DNSCONFD_START=1 101 test -f /etc/default/avahi-dnsconfd && . /etc/default/avahi-dnsconfd 102 103 if [ "$AVAHI_DNSCONFD_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 # 109 # Function that starts the daemon/service. 110 # 111 d_start() { 112 $DAEMON -c 113 [ $? = 0 ] && exit 0 114 115 if [ -s /etc/localtime ]; then 116 if [ ! -d /etc/avahi/etc ]; then 117 mkdir -p @sysconfdir@/avahi/etc >/dev/null 2>&1 118 fi 119 cp -fp /etc/localtime @sysconfdir@/avahi/etc >/dev/null 2>&1 120 fi; 121 122 $DAEMON -D 123 } 124 125 # 126 # Function that stops the daemon/service. 127 # 128 d_stop() { 129 $DAEMON -c 130 [ $? != 0 ] && exit 0 131 132 $DAEMON -k 133 } 134 135 # 136 # Function that reload the config file for the daemon/service. 137 # 138 d_refresh() { 139 $DAEMON -c 140 [ $? != 0 ] && exit 0 141 142 $DAEMON -r 143 } 144 145 # 146 # Function that check the status of the daemon/service. 147 # 148 d_status() { 149 $DAEMON -c 150 [ $? = 0 ] && echo "$DESC is running" || echo "$DESC is not running" 151 } 152 153 case "$1" in 154 start) 155 log_begin_msg "Starting $DESC: $NAME" 156 d_start 157 log_end_msg $? 158 ;; 159 stop) 160 log_begin_msg "Stopping $DESC: $NAME" 161 d_stop 162 log_end_msg $? 163 ;; 164 refresh) 165 log_begin_msg "Refreshing $DESC: $NAME" 166 d_refresh 167 log_end_msg $? 168 ;; 169 reload|restart|force-reload) 170 log_begin_msg "Restarting $DESC: $NAME" 171 $DAEMON -c && d_stop 172 d_start 173 log_end_msg $? 174 ;; 175 status) 176 d_status 177 ;; 178 *) 179 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload}" >&2 180 exit 1 181 ;; 182 esac 183 184 exit 0 185