2007-04-05 16:48:42 +05:30
|
|
|
#!/bin/sh
|
|
|
|
# Shell wrapper for runscript
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
# Copyright 1999-2007 Gentoo Foundation
|
2007-11-14 20:52:04 +05:30
|
|
|
# Copyright 2007 Roy Marples
|
|
|
|
# All rights reserved
|
|
|
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
. /etc/init.d/functions.sh
|
|
|
|
. "${RC_LIBDIR}"/sh/rc-functions.sh
|
|
|
|
|
|
|
|
# Support LiveCD foo
|
2007-11-20 15:54:40 +05:30
|
|
|
if [ -r /sbin/livecd-functions.sh ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
. /sbin/livecd-functions.sh
|
|
|
|
livecd_read_commandline
|
|
|
|
fi
|
|
|
|
|
2007-11-20 15:54:40 +05:30
|
|
|
if [ -z "$1" -o -z "$2" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "${SVCNAME}: not enough arguments"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2007-07-11 00:39:41 +05:30
|
|
|
# Descript the init script to the user
|
|
|
|
describe() {
|
2007-11-20 15:54:40 +05:30
|
|
|
if [ -n "${description}" ]; then
|
2007-07-11 00:39:41 +05:30
|
|
|
einfo "${description}"
|
|
|
|
else
|
|
|
|
ewarn "No description for ${SVCNAME}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
local svc= desc=
|
2007-11-20 15:54:40 +05:30
|
|
|
for svc in ${opts}; do
|
2007-07-11 00:39:41 +05:30
|
|
|
eval desc=\$description_${svc}
|
2007-11-20 15:54:40 +05:30
|
|
|
if [ -n "${desc}" ]; then
|
2007-07-11 00:39:41 +05:30
|
|
|
einfo "${HILITE}${svc}${NORMAL}: ${desc}"
|
|
|
|
else
|
|
|
|
ewarn "${HILITE}${svc}${NORMAL}: no description"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
[ "${RC_DEBUG}" = "yes" ] && set -x
|
|
|
|
|
|
|
|
# If we're net.eth0 or openvpn.work then load net or openvpn config
|
|
|
|
rc_c=${SVCNAME%%.*}
|
2007-11-20 15:54:40 +05:30
|
|
|
if [ -n "${rc_c}" -a "${rc_c}" != "${SVCNAME}" ]; then
|
|
|
|
if [ -e "/etc/conf.d/${rc_c}.${RC_SOFTLEVEL}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
. "/etc/conf.d/${rc_c}.${RC_SOFTLEVEL}"
|
2007-11-20 15:54:40 +05:30
|
|
|
elif [ -e "/etc/conf.d/${rc_c}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
. "/etc/conf.d/${rc_c}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
unset rc_c
|
|
|
|
|
|
|
|
# Overlay with our specific config
|
2007-11-20 15:54:40 +05:30
|
|
|
if [ -e "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
. "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}"
|
2007-11-20 15:54:40 +05:30
|
|
|
elif [ -e "/etc/conf.d/${SVCNAME}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
. "/etc/conf.d/${SVCNAME}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Load any system overrides
|
|
|
|
[ -e /etc/rc.conf ] && . /etc/rc.conf
|
|
|
|
|
|
|
|
# Apply any ulimit defined
|
|
|
|
[ -n "${RC_ULIMIT}" ] && ulimit ${RC_ULIMIT}
|
|
|
|
|
|
|
|
# Load our script
|
|
|
|
. $1
|
|
|
|
|
|
|
|
shift
|
|
|
|
|
2007-11-20 15:54:40 +05:30
|
|
|
# If we have a default command then supply a default start function
|
|
|
|
if [ -n "${command}" ]; then
|
|
|
|
if ! type start >/dev/null 2>&1; then
|
|
|
|
start() {
|
|
|
|
ebegin "Starting ${name:-${SVCNAME}}"
|
2007-11-20 22:40:35 +05:30
|
|
|
case "${command_background}" in
|
|
|
|
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
|
|
|
|
start_stop_daemon_args="${start_stop_daemon_args} --background --pidfile"
|
|
|
|
;;
|
|
|
|
esac
|
2007-11-20 15:54:40 +05:30
|
|
|
start-stop-daemon --start \
|
|
|
|
--exec ${command} \
|
|
|
|
${procname:+--name} ${procname} \
|
|
|
|
${pidfile:+--pidfile} ${pidfile} \
|
2007-11-20 22:40:35 +05:30
|
|
|
${start_stop_daemon_args} \
|
2007-11-20 15:54:40 +05:30
|
|
|
-- ${command_args}
|
|
|
|
eend $? "Failed to start ${SVCNAME}"
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If we have a default command, procname or pidfile then supply a default stop
|
|
|
|
# function
|
|
|
|
if [ -n "${command}" -o -n "${procname}" -o -n "${pidfile}" ]; then
|
|
|
|
if ! type stop >/dev/null 2>&1; then
|
|
|
|
stop() {
|
|
|
|
ebegin "Stopping ${name:-${SVCNAME}}"
|
|
|
|
start-stop-daemon --stop \
|
|
|
|
${command:+--exec} ${command} \
|
|
|
|
${procname:+--name} ${procname} \
|
|
|
|
${pidfile:+--pidfile} ${pidfile}
|
2007-11-20 16:02:47 +05:30
|
|
|
eend $? "Failed to stop ${SVCNAME}"
|
2007-11-20 15:54:40 +05:30
|
|
|
}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
while [ -n "$1" ]; do
|
2007-04-05 16:48:42 +05:30
|
|
|
# See if we have the required function and run it
|
2007-11-20 15:54:40 +05:30
|
|
|
for rc_x in describe start stop ${opts}; do
|
|
|
|
if [ "${rc_x}" = "$1" ]; then
|
|
|
|
if type "$1" >/dev/null 2>&1; then
|
2007-04-05 16:48:42 +05:30
|
|
|
unset rc_x
|
2007-11-20 15:54:40 +05:30
|
|
|
if type "$1"_pre >/dev/null 2>&1; then
|
|
|
|
"$1"_pre || exit $?
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
"$1" || exit $?
|
2007-11-20 15:54:40 +05:30
|
|
|
if type "$1"_post >/dev/null 2>&1; then
|
|
|
|
"$1"_post || exit $?
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
shift
|
|
|
|
continue 2
|
|
|
|
else
|
2007-11-20 15:54:40 +05:30
|
|
|
if [ "${rc_x}" = "start" -o "${rc_x}" = "stop" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
eerror "${SVCNAME}: function \`$1' defined but does not exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
eerror "${SVCNAME}: unknown function \`$1'"
|
|
|
|
exit 1
|
|
|
|
done
|
|
|
|
|
|
|
|
# vim: set ts=4 :
|