[Cialug] debian sarge

David Champion dave at visionary.com
Fri Jun 3 15:08:43 CDT 2005


Bryan Baker wrote:
> Here's a dump from a RHEL 3 box:
[snip: see Bryan's email for script]

Looks like Mandrake'd up version has more stuff in it for xinetd and 
such. From Mandriva 2005 LE (watch out for word wrap if you actually try 
to run this)  :

#!/bin/bash
# -*- Mode: shell-script -*-
# Copyright (C) 2001 by Chmouel Boudjnah <chmouel at mandrakesoft.com>
#			MandrakeSoft.
# Redistribution of this file is permitted under the terms of the GNU
# Public License (GPL)
# Original version writen by RedHat.

debug=
service=
opt=
fullrestart=
fullrestartall=
statusall=

servicedir=/etc/init.d
xinetddir=/etc/xinetd.d

version=$(echo '$Id: service,v 1.14 2002/12/17 13:07:48 gbeauchesne Exp 
$'|cut -d" " -f3)
basename=${0##*/}

function service_available () {
	local subsys
     cd $servicedir
	
     for subsys in *;do
		case $subsys in
			kheader|numlock|sound|usb|netfs|kudzu|local|pcmcia| \
			network|local|dm|harddrake|xfs|*~|*.*|*,*) continue;;
		esac
		grep -q chkconfig $subsys || continue
		egrep -q 'restart.*\)' $subsys || continue
		[[ -x $subsys ]] || continue
		[[ -e /var/lock/subsys/$subsys ]] || continue
		echo $(egrep -a '^#.*chkconfig: ' $subsys|awk '{print $4}') $subsys
     done | sort -n|cut -d" " -f2
}

function usage () {
     cat <<EOF 1>&2
Usage: $basename -[Rfshv] SERVICE ARGUMENTS
	-f|--full-restart:	Do a fullrestart of the service.
	-R|--full-restart-all:	Do a fullrestart of all services currently running.
	-s|--status-all:	Print a status of all services.
	-d|--debug:		Launch with debug.
	-h|--help:		This help.
	-v|--version:		Print version.

version $version
EOF
exit 1
}
function check_if_inetd() {
     local serv=$1
     if [[ ! -f ${servicedir}/${serv} ]];then
	if [[ -f ${xinetddir}/${serv} ]];then
	    if egrep -q ".*disable.*yes.*" ${xinetddir}/${serv};then
		echo "$serv is a xinetd service and it is disabled"
		echo "to activate it do the following command:"
		echo "chkconfig ${serv} on"
		service=
		return
	    fi
	    service=xinetd
	    [[ $options = "start" ]] && options=reload
	    if [[ $options != reload ]] && [[ -z $fullrestart ]];then
		echo "There is no such option for an xinetd services"
		echo "You can only use the start option to reload a xinetd services"
		service=
	    fi
	    echo "${serv} is a xinetd service"
	fi
     fi
     return
}

while [[ $1 = --* ]] || [[ $1 = -* ]];do
     opt=$1
     shift
     case $opt in
	--full-restart|-f) fullrestart=yes;;
	--full-restart-all|-R) fullrestartall=yes;;
	--status-all|-s) statusall=yes;;
	--debug|-d) set -x ; debug="/bin/bash -x";;
	--help|-h) usage;;
	*) echo "Unknow option $opt"; usage;
     esac
done

service=${1##*/}; shift;
options="$@"

#nuts ? (yes)
while :;do
     [[ -z $service && -n $statusall ]] && break
     [[ -z $service && -n $fullrestartall ]] && break
     [[ -n $service && -n $statusall ]] && { echo "--status-sall doen't 
need arguments"; usage ;}
     [[ -n $service && -n $fullrestartall ]] && { echo 
"--full-restart-alll doen't need arguments"; usage ;}
     [[ -z $service ]] && usage
     [[ -n $service ]] && break
done

if [[ -n $fullrestartall ]];then
     for subsys in $(service_available);do $0 -f $subsys;done
     exit 0 #for glibc post upgrades
fi

if [[ -n $statusall ]];then
     cd $servicedir
     for service in *;do
	case $service in
	    functions | halt | killall | single| linuxconf| kudzu | \
		mandrake_firstime | mandrake_everytime | mandrake_consmap | \
		*~ | *.* | *,*)
		continue ;;
	esac
	if egrep -q '^([^#]*)status\)' $service;then
	    $debug $servicedir/$service status
	fi
     done
     exit 0;
fi

if [[ -n $fullrestart ]];then
     check_if_inetd "$service"
     cd "$servicedir"
     if [[ -f ./$service ]];then
	$debug ./$service stop
	$debug ./$service start
	exit $?
     else
	echo "Cannot find $servicedir/$service"
	usage
     fi
     exit 1
fi

[[ -z $options ]] && { echo  "I need an action"; options="--help" ;}

check_if_inetd "$service" ; [[ -z $service ]] && exit 1

if [[ -x $servicedir/$service ]]; then
     $debug $servicedir/$service $options
     exit $?
else
     echo "Cannot find $service service"
     usage
fi

# end script...

> On Jun 3, 2005, at 12:35 PM, James Shoemaker wrote:
> 
>>     How would it know which is which, does it parse the files and look or
>> is it hardcoded somehow?
>>     What does it do about restarting inetd services, just kill them and
>> expect them to respawn?  Restart inetd to reload the config file?



More information about the Cialug mailing list