1#! /bin/sh 2# Copyright (c) 2001 J�rg Mayer 3# based on /etc/init.d/skeleton which is 4# Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany. 5# 6# 7# Author: J�rg Mayer <jmayer@loplof.de> 8# 9# init.d/dnsmasq 10# 11# and symbolic its link 12# 13# /usr/sbin/rcdnsmasq 14# 15# System startup script for the nessus backend nessusd 16# 17### BEGIN INIT INFO 18# Provides: dnsmasq 19# Required-Start: $network $remote_fs $syslog 20# Required-Stop: $remote_fs $syslog 21# Default-Start: 3 5 22# Default-Stop: 0 1 2 6 23# Description: This script starts your DNS caching server 24### END INIT INFO 25 26# Source SuSE config 27. /etc/rc.config 28 29# Determine the base and follow a runlevel link name. 30base=${0##*/} 31link=${base#*[SK][0-9][0-9]} 32 33# Force execution if not called by a runlevel directory. 34test $link = $base && START_DNSMASQ=yes 35test "$START_DNSMASQ" = yes || exit 0 36 37DNSMASQ=/usr/sbin/dnsmasq 38test -x $DNSMASQ || exit 5 39 40# Shell functions sourced from /etc/rc.status: 41# rc_check check and set local and overall rc status 42# rc_status check and set local and overall rc status 43# rc_status -v ditto but be verbose in local rc status 44# rc_status -v -r ditto and clear the local rc status 45# rc_failed set local and overall rc status to failed 46# rc_failed <num> set local and overall rc status to <num><num> 47# rc_reset clear local rc status (overall remains) 48# rc_exit exit appropriate to overall rc status 49. /etc/rc.status 50 51# First reset status of this service 52rc_reset 53 54# Return values acc. to LSB for all commands but status: 55# 0 - success 56# 1 - generic or unspecified error 57# 2 - invalid or excess argument(s) 58# 3 - unimplemented feature (e.g. "reload") 59# 4 - insufficient privilege 60# 5 - program is not installed 61# 6 - program is not configured 62# 7 - program is not running 63# 64# Note that starting an already running service, stopping 65# or restarting a not-running service as well as the restart 66# with force-reload (in case signalling is not supported) are 67# considered a success. 68 69 70# Build command line: 71 72# change this line if you want dnsmasq to serve an MX record for 73# the host it is running on. 74MAILHOSTNAME="" 75# change this line if you want dns to get its upstream servers 76# from somewhere other that /etc/resolv.conf 77RESOLV_CONF="" 78# change this if you want dnsmasq to cache any "hostname" or 79# "client-hostname" from a dhcpd's lease file 80DHCP_LEASE="/var/lib/dhcp/dhcpd.leases" 81DOMAIN_SUFFIX=`dnsdomainname` 82 83OPTIONS="" 84 85if [ ! -z "${MAILHOSTNAME}" ]; then 86 OPTIONS="$OPTIONS -m $MAILHOSTNAME" 87fi 88 89if [ ! -z "${RESOLV_CONF}" ]; then 90 OPTIONS="$OPTIONS -r $RESOLV_CONF" 91fi 92 93if [ ! -z "${DHCP_LEASE}" ]; then 94 OPTIONS="$OPTIONS -l $DHCP_LEASE" 95fi 96 97if [ ! -z "${DOMAIN_SUFFIX}" ]; then 98 OPTIONS="$OPTIONS -s $DOMAIN_SUFFIX" 99fi 100 101case "$1" in 102 start) 103 echo -n "Starting dnsmasq" 104 ## Start daemon with startproc(8). If this fails 105 ## the echo return value is set appropriate. 106 107 # NOTE: startproc returns 0, even if service is 108 # already running to match LSB spec. 109 startproc $DNSMASQ $OPTIONS 110 111 # Remember status and be verbose 112 rc_status -v 113 ;; 114 stop) 115 echo -n "Shutting down dnsmasq" 116 ## Stop daemon with killproc(8) and if this fails 117 ## set echo the echo return value. 118 119 killproc -TERM $DNSMASQ 120 121 # Remember status and be verbose 122 rc_status -v 123 ;; 124 try-restart) 125 ## Stop the service and if this succeeds (i.e. the 126 ## service was running before), start it again. 127 ## Note: try-restart is not (yet) part of LSB (as of 0.7.5) 128 $0 status >/dev/null && $0 restart 129 130 # Remember status and be quiet 131 rc_status 132 ;; 133 restart) 134 ## Stop the service and regardless of whether it was 135 ## running or not, start it again. 136 $0 stop 137 $0 start 138 139 # Remember status and be quiet 140 rc_status 141 ;; 142 force-reload) 143 ## Signal the daemon to reload its config. 144 145 echo -n "Reload service dnsmasq" 146 killproc -HUP $DNSMASQ 147 #touch /var/run/dnsmasq.pid 148 rc_status -v 149 ;; 150 reload) 151 ## Like force-reload, but if daemon does not support 152 ## signalling, do nothing (!) 153 154 echo -n "Reload service dnsmasq" 155 killproc -HUP $DNSMASQ 156 #touch /var/run/dnsmasq.pid 157 rc_status -v 158 ;; 159 status) 160 echo -n "Checking for dnsmasq: " 161 ## Check status with checkproc(8), if process is running 162 ## checkproc will return with exit status 0. 163 164 # Status has a slightly different for the status command: 165 # 0 - service running 166 # 1 - service dead, but /var/run/ pid file exists 167 # 2 - service dead, but /var/lock/ lock file exists 168 # 3 - service not running 169 170 # NOTE: checkproc returns LSB compliant status values. 171 checkproc $DNSMASQ 172 rc_status -v 173 ;; 174 *) 175 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}" 176 exit 1 177 ;; 178esac 179rc_exit 180 181########################################################################### 182 183 184## FIXME: 185## The stuff from the RedHat startup script 186## I keep it for the moment because I haven't checked 187## the stuff with the lock/subsys/ file yet. JM 188 189RETVAL=0 190 191# See how we were called. 192case "$1" in 193 start) 194 echo -n "Starting dnsmasq: " 195 daemon dnsmasq $OPTIONS 196 RETVAL=$? 197 echo 198 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dnsmasq 199 ;; 200 stop) 201 if test "x`pidof dnsmasq`" != x; then 202 echo -n "Shutting down dnsmasq: " 203 killproc dnsmasq 204 fi 205 RETVAL=$? 206 echo 207 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dnsmasq /var/run/dnsmasq.pid 208 ;; 209 status) 210 status dnsmasq 211 RETVAL=$? 212 ;; 213 restart|reload) 214 $0 stop 215 $0 start 216 RETVAL=$? 217 ;; 218 condrestart) 219 if test "x`/sbin/pidof dnsmasq`" != x; then 220 $0 stop 221 $0 start 222 RETVAL=$? 223 fi 224 ;; 225 *) 226 echo "Usage: $0 {start|stop|restart|reload|condrestart|status}" 227 exit 1 228esac 229 230exit $RETVAL 231 232