From 7dfc87445026c54d5faa592b18919226cc05930c Mon Sep 17 00:00:00 2001 From: Roman Kyrylych Date: Mon, 5 Nov 2007 19:19:32 +0200 Subject: [PATCH] Add 'service' script This is a slightly improved (FS#5721) version of 'service' script written by Alessio 'mOLOk' Bolognino (FS#8491) Signed-off-by: Roman Kyrylych --- install.sh | 2 ++ service | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 0 deletions(-) create mode 100755 service diff --git a/install.sh b/install.sh index 6d5b2dc..2ff9ebf 100755 --- a/install.sh +++ b/install.sh @@ -21,3 +21,5 @@ install -D -m755 netcfg ${DESTDIR}/usr/bin/netcfg || exit 1 install -D -m644 profile-template ${DESTDIR}/etc/network-profiles/template || exit 1 install -D -m755 makedevs ${DESTDIR}/sbin/makedevs || exit 1 + +install -D -m755 service ${DESTDIR}/usr/bin/service || exit 1 diff --git a/service b/service new file mode 100755 index 0000000..fa5a552 --- /dev/null +++ b/service @@ -0,0 +1,52 @@ +#!/bin/bash + +. /etc/rc.conf +. /etc/rc.d/functions + +SERVICEDIR=/etc/rc.d +SERVICE=$1 +COMMAND=$2 +SUPPORTED= + +usage() { + echo "Usage: $( basename $0 ) [command]" +} + +if [ $# -eq 0 ]; then + usage + exit 1 +elif [ $# -eq 1 ]; then + ck_daemon ${SERVICE} + if [ $? -gt 0 ]; then + echo "${SERVICE} is running" + exit + else + echo "${SERVICE} is not running" + exit + fi +elif [ $# -gt 2 ]; then + echo "Error: Wrong number of parameters" >&2 + usage + exit 2 +fi + +if [ ! -x "${SERVICEDIR}/${SERVICE}" ]; then + echo "Error: Service ${SERVICE} not recognized" >&2 + exit 3 +fi + +for action in $( sed -ne "y/|/ /; s/^.*usage.*{\(.*\)}.*$/\1/p" ${SERVICEDIR}/${SERVICE} ); do + if [ "${COMMAND}" = "${action}" ]; then + SUPPORTED=y + fi +done + +if [ "${SUPPORTED}" != "y" ]; then + echo "Error: Command ${COMMAND} is not supported by service ${SERVICE}" >&2 + exit 4 +fi + +env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" \ + "${SERVICEDIR}/${SERVICE}" "${COMMAND}" + +# vim: set ts=2 sw=2 noet: -- 1.5.3.5