Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Jun 2009 23:02:03 +0300
From:      Alex Kozlov <spam@rm-rf.kiev.ua>
To:        Kevin Downey <redchin@gmail.com>, Doug Barton <dougb@FreeBSD.org>, Edwin Shao <eshao@ring0.org>, freebsd-ports@freebsd.org, spam@rm-rf.kiev.ua
Subject:   Re: Port of "service" command
Message-ID:  <20090609200203.GA64660@ravenloft.kiev.ua>

next in thread | raw e-mail | index | archive | help
On Tue, Jun 09, 2009 at 12:30:44PM -0700, Doug Barton wrote:
> Kevin Downey wrote:
>> I have a similar shell function I am rather fond of:
>> 
>> rc(){
>>     find /etc/rc.d/"$1" /usr/local/etc/rc.d/"$1" -exec sudo {} `echo
>> "$*"|cut -f 2- -d \ ` \;
>> }
> 
> Wow, that's painful. :) The only reason you don't notice how painful
> is because those two directories have only a few files. Much much more
> efficient would be something like:
> 
> rc () {
> 	local script=$1
> 	shift
> 
> 	if [ -x "/etc/rc.d/$script" ]; then
> 		/etc/rc.d/$script $*
> 	elif [ -x "/usr/local/etc/rc.d/$script" ]; then
> 		/usr/local/etc/rc.d/$script $*
> 	else
> 		echo "$script does not exist in /etc/rc.d or"
> 		echo "/usr/local/etc/rc.d"
> 		return 1
> 	fi
> }

#!/bin/sh

name=$1
cmd=$2

if [ -z "${name}" -o -z "${cmd}" ]; then
	echo ${0##*/} service_name command
	exit 3
fi

. /etc/rc.subr

load_rc_config ${name}

for dir in /etc/rc.d ${local_startup}; do
	if [ -r "${dir}/${name}" ]; then	
		run_rc_script "${dir}/${name}" ${cmd}
		exit 0
	fi

	if [ -r "${dir}/${name}.sh" ]; then	
		run_rc_script "${dir}/${name}.sh" ${cmd}
		exit 0
	fi	
done

echo "service '${name}' not found"
exit 2


Most useful with shell completion.


--
Adios



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090609200203.GA64660>