From owner-freebsd-ports@FreeBSD.ORG Wed Jun 10 07:18:10 2009 Return-Path: Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EDDB8106566B; Wed, 10 Jun 2009 07:18:10 +0000 (UTC) (envelope-from kozlov@ravenloft.kiev.ua) Received: from istc.kiev.ua (wolf.istc.kiev.ua [193.108.236.1]) by mx1.freebsd.org (Postfix) with ESMTP id A540B8FC14; Wed, 10 Jun 2009 07:18:10 +0000 (UTC) (envelope-from kozlov@ravenloft.kiev.ua) Received: from [91.123.146.100] (helo=ravenloft.kiev.ua) by istc.kiev.ua with esmtp (Exim 4.52) id 1MEGxn-0003dV-5z; Wed, 10 Jun 2009 09:07:09 +0300 Date: Tue, 9 Jun 2009 23:02:03 +0300 From: Alex Kozlov To: Kevin Downey , Doug Barton , Edwin Shao , freebsd-ports@freebsd.org, spam@rm-rf.kiev.ua Message-ID: <20090609200203.GA64660@ravenloft.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Score: 0.7 (/) X-Spam-Report: Content analysis detailz: (0.7 points, 10.0 required) * 0.7 DATE_IN_PAST_06_12 Date: is 6 to 12 hours before Received: date Cc: Subject: Re: Port of "service" command X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jun 2009 07:18:11 -0000 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