1 #!/sbin/sh 2 # 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License (the "License"). 7 # You may not use this file except in compliance with the License. 8 # 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 # or http://www.opensolaris.org/os/licensing. 11 # See the License for the specific language governing permissions 12 # and limitations under the License. 13 # 14 # When distributing Covered Code, include this CDDL HEADER in each 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 # If applicable, add the following below this CDDL HEADER, with the 17 # fields enclosed by brackets "[]" replaced with your own identifying 18 # information: Portions Copyright [yyyy] [name of copyright owner] 19 # 20 # CDDL HEADER END 21 # 22 23 # 24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved. 25 # Use is subject to license terms. 26 # 27 28 #pragma ident "@(#)dns-server.sh 1.2 09/07/12 SMI" 29 30 # smf_method(5) start/stop script required for server DNS 31 32 . /lib/svc/share/smf_include.sh 33 34 result=${SMF_EXIT_OK} 35 36 # Read command line arguments 37 method="$1" # %m 38 instance="$2" # %i 39 40 # Set defaults; SMF_FMRI should have been set, but just in case. 41 if [ -z "$SMF_FMRI" ]; then 42 SMF_FMRI="svc:/network/dns/server:${instance}" 43 fi 44 server="/usr/sbin/named" 45 I=`/usr/bin/basename $0` 46 47 case "$method" in 48 'start') 49 configuration_file=/etc/named.conf 50 cmdopts="" 51 properties="debug_level ip_interfaces listen_on_port 52 threads chroot_dir configuration_file server" 53 54 for prop in $properties 55 do 56 value=`/usr/bin/svcprop -p options/${prop} ${SMF_FMRI}` 57 if [ -z "${value}" -o "${value}" = '""' ]; then 58 continue; 59 fi 60 61 case $prop in 62 'debug_level') 63 if [ ${value} -gt 0 ]; then 64 cmdopts="${cmdopts} -d ${value}" 65 fi 66 ;; 67 'ip_interfaces') 68 case ${value} in 69 'IPv4') 70 cmdopts="${cmdopts} -4";; 71 'IPv6') 72 cmdopts="${cmdopts} -6";; 73 'all') 74 : # Default is all, therefore ignore. 75 ;; 76 *) 77 echo "$I: Unrecognised value in service instance property" >&2 78 echo "$I: options/${prop} : ${value}" >&2 79 ;; 80 esac 81 ;; 82 'listen_on_port') 83 if [ ${value} -gt 0 ]; then 84 cmdopts="${cmdopts} -p ${value}" 85 fi 86 ;; 87 'threads') 88 if [ ${value} -gt 0 ]; then 89 cmdopts="${cmdopts} -n ${value}" 90 fi 91 ;; 92 'chroot_dir') 93 cmdopts="${cmdopts} -t ${value}" 94 chroot_dir=${value}; 95 ;; 96 'configuration_file') 97 cmdopts="${cmdopts} -c ${value}" 98 configuration_file=${value}; 99 ;; 100 'server') 101 set -- `echo ${value} | /usr/bin/sed -e 's/\\\\//g'` 102 server=$@ 103 ;; 104 esac 105 done 106 107 # If chroot option is set, note zones(5) are preferred, then 108 # configuration file lives under chroot directory. 109 if [ "${chroot_dir}" != "" ]; then 110 configuration_file=${chroot_dir}/${configuration_file} 111 fi 112 113 # Check configuration file exists. 114 if [ ! -f ${configuration_file} ]; then 115 msg="$I : Configuration file ${configuration_file} does not exist!" 116 echo ${msg} >&2 117 /usr/bin/logger -p daemon.error ${msg} 118 # dns-server should be placed in maintenance state. 119 result=${SMF_EXIT_ERR_CONFIG} 120 fi 121 122 if [ ${result} = ${SMF_EXIT_OK} ]; then 123 echo "$I: Executing: ${server} ${cmdopts}" 124 # Execute named(1M) with relevant command line options. Note 125 # the server forks before reading named.conf(4) and so a 126 # good exit code here does not mean the service is ready. 127 ${server} ${cmdopts} 128 result=$? 129 if [ $result -ne 0 ]; then 130 echo "$I : start failed! Check syslog for further information." >&2 131 fi 132 fi 133 ;; 134 'stop') 135 smf_kill_contract ${contract} TERM 1 136 [ $? -ne 0 ] && exit 1 137 ;; 138 *) 139 echo "Usage: $I [stop|start] <instance>" >&2 140 exit 1 141 ;; 142 esac 143 exit ${result} 144