]> git.meshlink.io Git - catta/blob - initscript/debian/avahi-daemon.in
30a2c2f2bba0caa0951fa8463b5185c6f04b111f
[catta] / initscript / debian / avahi-daemon.in
1 #!/bin/sh
2
3 # $Id$
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 if [ -f /lib/lsb/init-functions ]
30 then
31     . /lib/lsb/init-functions
32 else
33     # int log_begin_message (char *message)
34     log_begin_msg () {
35         if [ -z "$1" ]; then
36             return 1
37         fi
38         echo " * $@"
39     }
40
41     # int log_end_message (int exitstatus)
42     log_end_msg () {
43         
44     # If no arguments were passed, return
45         [ -z "$1" ] && return 1
46         
47     # Only do the fancy stuff if we have an appropriate terminal
48     # and if /usr is already mounted
49         TPUT=/usr/bin/tput
50         EXPR=/usr/bin/expr
51         if [ -x $TPUT ] && [ -x $EXPR ] && $TPUT hpa 60 >/dev/null 2>&1; then
52             COLS=`$TPUT cols`
53             if [ -n "$COLS" ]; then
54                 COL=`$EXPR $COLS - 7`
55             else
56                 COL=73
57             fi
58             UP=`$TPUT cuu1`
59             END=`$TPUT hpa $COL`
60             START=`$TPUT hpa 0`
61             RED=`$TPUT setaf 1`
62             NORMAL=`$TPUT op`
63             if [ $1 -eq 0 ]; then
64                 echo "$UP$END[ ok ]"
65             else
66                 echo -e "$UP$START $RED*$NORMAL$END[${RED}fail${NORMAL}]"
67             fi
68         else
69             if [ $1 -eq 0 ]; then
70                 echo "   ...done."
71             else
72                 echo "   ...fail!"
73             fi
74         fi
75         return $1
76     }
77     
78     log_warning_msg () {
79         if log_use_fancy_output; then
80             YELLOW=`$TPUT setaf 3`
81             NORMAL=`$TPUT op`
82             echo "$YELLOW*$NORMAL $@"
83         else
84             echo "$@"
85         fi
86     }
87
88 fi
89
90 #set -e
91
92 PATH=/sbin:/bin:/usr/sbin:/usr/bin
93 DESC="Avahi mDNS/DNS-SD Daemon"
94 NAME="avahi-daemon"
95 DAEMON="@sbindir@/$NAME"
96 SCRIPTNAME=/etc/init.d/$NAME
97
98 # Gracefully exit if the package has been removed.
99 test -x $DAEMON || exit 0
100
101 # don't start if /etc/default/avahi-daemon says so.
102 AVAHI_DAEMON_START=1
103 test -f /etc/default/avahi-daemon && . /etc/default/avahi-daemon
104
105 if [ "$AVAHI_DAEMON_START" != "1" -a "$1" != "stop" ]; then
106     log_warning_msg "Not starting $DESC $NAME, disabled via /etc/default/$NAME"
107     exit 0
108 fi
109
110 #
111 #       Function that starts the daemon/service.
112 #
113 d_start() {
114     modprobe capability >/dev/null 2>&1 || true
115
116     $DAEMON -c && return 0
117
118     if [ -s /etc/localtime ]; then
119         if [ ! -d /etc/avahi/etc ]; then
120             mkdir -p @sysconfdir@/avahi/etc >/dev/null 2>&1
121         fi
122         cp -fp /etc/localtime @sysconfdir@/avahi/etc >/dev/null 2>&1
123     fi;
124     
125     $DAEMON -D
126 }
127
128 #
129 #       Function that stops the daemon/service.
130 #
131 d_stop() {
132     $DAEMON -c && $DAEMON -k
133 }
134
135 #
136 #       Function that reload the config file for the daemon/service.
137 #
138 d_reload() {
139     $DAEMON -c && $DAEMON -r
140 }
141
142 #
143 #       Function that check the status of the daemon/service.
144 #
145 d_status() {
146     $DAEMON -c && echo "$DESC is running" || echo "$DESC is not running"
147 }
148
149 case "$1" in
150     start)
151         log_begin_msg "Starting $DESC: $NAME"
152         d_start
153         log_end_msg $?
154         ;;
155     stop)
156         log_begin_msg "Stopping $DESC: $NAME"
157         d_stop
158         log_end_msg $?
159         ;;
160     reload)
161         log_begin_msg "Reloading services for $DESC: $NAME"
162         d_reload
163         log_end_msg $?
164         ;;
165     restart|force-reload)
166         log_begin_msg "Restarting $DESC: $NAME"
167         $DAEMON -c && d_stop
168         d_start
169         log_end_msg $?
170         ;;
171     status)
172         d_status
173         ;;
174     *)
175         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload}" >&2
176         exit 1
177         ;;
178 esac
179
180 exit 0