147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#!/bin/sh
247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# Emacs settings: -*- tab-width: 4 -*-
347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#
447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# Copyright (c) 2002-2006 Apple Computer, Inc. All rights reserved.
547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#
647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# Licensed under the Apache License, Version 2.0 (the "License");
747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# you may not use this file except in compliance with the License.
847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# You may obtain a copy of the License at
947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# 
1047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#     http://www.apache.org/licenses/LICENSE-2.0
1147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# 
1247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# Unless required by applicable law or agreed to in writing, software
1347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# distributed under the License is distributed on an "AS IS" BASIS,
1447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# See the License for the specific language governing permissions and
1647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# limitations under the License.
1747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#
1847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# Linux /etc/init.d script to start/stop the mdnsd daemon.
1947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#
2047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# The following lines are used by the *BSD rcorder system to decide
2147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# the order it's going to run the rc.d scripts at startup time.
2247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# PROVIDE: mdnsd
2347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# REQUIRE: NETWORKING
2447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt
2547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltif [ -r /usr/sbin/mdnsd ]; then
2647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt    DAEMON=/usr/sbin/mdnsd
2747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltelse
2847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt    DAEMON=/usr/local/sbin/mdnsd
2947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltfi
3047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt
3147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalttest -r $DAEMON || exit 0
3247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt
3347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt# Some systems have start-stop-daemon, some don't. 
3447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltif [ -r /sbin/start-stop-daemon ]; then
3547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	START="start-stop-daemon --start --quiet --exec"
3647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	# Suse Linux doesn't work with symbolic signal names, but we really don't need
3747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	# to specify "-s TERM" since SIGTERM (15) is the default stop signal anway
3847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	# STOP="start-stop-daemon --stop -s TERM --quiet --oknodo --exec"
3947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	STOP="start-stop-daemon --stop --quiet --oknodo --exec"
4047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltelse
4147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	killmdnsd() {
4247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt		kill -TERM `cat /var/run/mdnsd.pid`
4347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	}
4447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	START=
4547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	STOP=killmdnsd
4647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltfi
4747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt
4847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltcase "$1" in
4947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt    start)
5047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	echo -n "Starting Apple Darwin Multicast DNS / DNS Service Discovery daemon:"
5147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	echo -n " mdnsd"
5247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt        $START $DAEMON
5347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	echo "."
5447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	;;
5547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt    stop)
5647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt        echo -n "Stopping Apple Darwin Multicast DNS / DNS Service Discovery daemon:"
5747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt        echo -n " mdnsd" ; $STOP $DAEMON
5847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt        echo "."
5947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	;;
6047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt    reload|restart|force-reload)
6147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt		echo -n "Restarting Apple Darwin Multicast DNS / DNS Service Discovery daemon:"
6247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt		$STOP $DAEMON
6347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt		sleep 1
6447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt		$START $DAEMON
6547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt		echo -n " mdnsd"
6647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	;;
6747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt    *)
6847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	echo "Usage: /etc/init.d/mDNS {start|stop|reload|restart}"
6947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	exit 1
7047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt	;;
7147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltesac
7247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt
7347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltexit 0
74