#!/bin/bash # Placed in the public domain 2002 by Sam Trenholme # chkconfig: 345 55 45 # description: This shell script takes care of starting and stopping \ # the MaraDNS process. # A DNS server is a program that performs the DNS \ # conversion from hostnames in to ipadresses. . /etc/sysconfig/maradns # Show usage information if this script is invoked with no arguments if [ $# -lt 1 ] ; then echo Usage: $0 \(start\|stop\|restart\) exit 1 fi # If invoked as stop or restart, kill *all* MaraDNS processes if [ $1 = "stop" -o $1 = "restart" ] ; then echo Sending all MaraDNS processes the TERM signal ps -ef | awk '{print $2":"$8}' | grep maradns | grep -v $$ | \ cut -f1 -d: | xargs kill > /dev/null 2>&1 echo waiting 1 second sleep 1 echo Sending all MaraDNS processes the KILL signal ps -e | awk '{print $1":"$NF}' | grep maradns | grep -v $$ | \ cut -f1 -d: | xargs kill -9 > /dev/null 2>&1 echo MaraDNS should have been stopped fi # If invoked as start ot restart, start the MaraDNS processes if [ $1 = "start" -o $1 = "restart" ] ; then echo Starting all maradns processes for a in $MARARCS ; do echo Starting maradns process which uses Mararc file $a # The name of the logfile is determined by the name of the # mararc file; it is the name of the mararc file with all slashes # converted in to underlines; with all leading underlines removed. # If the mararc file has a dot in it (e.g. /etc/mararc.1), we only # use the portion of the logfile which is after the dot. # Finally, we put the word "maradns." at the front of the logfile # name # Examples: a mararc file of /etc/mararc results in a logfile name of # maradns.etc_mararc # A mararc file if /etc/mararc.1 resuls in a logfile name of # maradns.1 LOGFILE=`echo $a | sed 's/\//_/g;s/^_*//;' | awk -F. '{print $NF}'` LOGFILE=maradns.$LOGFILE echo Logfile for this maradns process is $LOGDIR/$LOGFILE # This is the only reason why need need Bash: job control touch $LOGDIR/$LOGFILE nohup $MARADNS -f $a >> $LOGDIR/$LOGFILE & # For people that prefer human-readable time stamps, comment out # the above line and uncomment the following four lines #nohup $MARADNS -f $a | awk '/Timestamp/{ #gsub(/Timestamp: ([0-9]+)/, #strftime("%a, %d %b %Y %H:%M:%S",$2),$0)} #{print}' >> $LOGDIR/$LOGFILE & done fi