2007-04-05 16:48:42 +05:30
|
|
|
#!/bin/sh
|
|
|
|
# Shell wrapper for runscript
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-01-11 17:15:59 +05:30
|
|
|
# Copyright 2007-2008 Roy Marples
|
2007-11-14 20:52:04 +05:30
|
|
|
# All rights reserved
|
|
|
|
|
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
|
2008-01-11 17:43:46 +05:30
|
|
|
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-12-17 19:59:19 +05:30
|
|
|
for svc in ${extra_commands:-${opts}} ${extra_started_commands}; 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-11-24 03:52:18 +05:30
|
|
|
yesno ${RC_DEBUG} && set -x
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# If we're net.eth0 or openvpn.work then load net or openvpn config
|
2007-11-23 17:34:11 +05:30
|
|
|
_c=${SVCNAME%%.*}
|
|
|
|
if [ -n "${_c}" -a "${_c}" != "${SVCNAME}" ]; then
|
|
|
|
if [ -e "/etc/conf.d/${_c}.${RC_SOFTLEVEL}" ]; then
|
|
|
|
. "/etc/conf.d/${_c}.${RC_SOFTLEVEL}"
|
|
|
|
elif [ -e "/etc/conf.d/${_c}" ]; then
|
|
|
|
. "/etc/conf.d/${_c}"
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
fi
|
2007-11-23 17:34:11 +05:30
|
|
|
unset _c
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# 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
|
2007-11-23 17:34:11 +05:30
|
|
|
[ -n "${rc_ulimit:-${RC_ULIMIT}}" ] && ulimit ${rc_ulimit:-${RC_ULIMIT}}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Load our script
|
|
|
|
. $1
|
|
|
|
shift
|
|
|
|
|
2007-11-28 18:38:25 +05:30
|
|
|
for _d in ${required_dirs}; do
|
|
|
|
if [ ! -d ${_d} ]; then
|
|
|
|
eerror "${SVCNAME}: \`${_d}' is not a directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset _d
|
|
|
|
|
|
|
|
for _f in ${required_files}; do
|
|
|
|
if [ ! -r ${_f} ]; then
|
|
|
|
eerror "${SVCNAME}: \`${_f}' is not readable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset _f
|
|
|
|
|
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() {
|
2007-12-04 21:45:32 +05:30
|
|
|
local _background=
|
2007-11-20 15:54:40 +05:30
|
|
|
ebegin "Starting ${name:-${SVCNAME}}"
|
2007-12-04 21:45:32 +05:30
|
|
|
if yesno "${command_background}"; then
|
|
|
|
_background="--background --pidfile"
|
|
|
|
fi
|
|
|
|
if yesno "${start_inactive}"; then
|
|
|
|
local _inactive=false
|
|
|
|
service_inactive "${SVCNAME}" && _inactive=true
|
|
|
|
mark_service_inactive "${SVCNAME}"
|
|
|
|
fi
|
2007-11-20 15:54:40 +05:30
|
|
|
start-stop-daemon --start \
|
|
|
|
--exec ${command} \
|
|
|
|
${procname:+--name} ${procname} \
|
|
|
|
${pidfile:+--pidfile} ${pidfile} \
|
2007-12-04 21:45:32 +05:30
|
|
|
${_background} ${start_stop_daemon_args} \
|
2007-11-20 15:54:40 +05:30
|
|
|
-- ${command_args}
|
2007-12-04 21:45:32 +05:30
|
|
|
eend $? "Failed to start ${SVCNAME}" && return 0
|
|
|
|
if yesno "${start_inactive}"; then
|
|
|
|
if ! ${_inactive}; then
|
|
|
|
mark_service_stopped "${SVCNAME}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
return 1
|
2007-11-20 15:54:40 +05:30
|
|
|
}
|
|
|
|
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-29 21:53:59 +05:30
|
|
|
for _cmd in describe start stop ${extra_commands:-${opts}} \
|
|
|
|
${extra_started_commands}; do
|
2007-11-23 17:34:11 +05:30
|
|
|
if [ "${_cmd}" = "$1" ]; then
|
2007-11-20 15:54:40 +05:30
|
|
|
if type "$1" >/dev/null 2>&1; then
|
2008-01-11 17:43:46 +05:30
|
|
|
# If we're in the background, we may wish to
|
|
|
|
# fake some commands. We do this so we can
|
|
|
|
# "start" ourselves from inactive which then
|
|
|
|
# triggers other services to start which depend
|
|
|
|
# on us. A good example of this is openvpn.
|
2007-11-28 18:38:25 +05:30
|
|
|
if yesno ${IN_BACKGROUND}; then
|
|
|
|
for _cmd in ${in_background_fake}; do
|
|
|
|
if [ "${_cmd}" = "$1" ]; then
|
|
|
|
shift
|
|
|
|
continue 3
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2008-01-11 17:43:46 +05:30
|
|
|
# Check to see if we need to be started before
|
|
|
|
# we can run this command
|
2007-11-29 21:53:59 +05:30
|
|
|
for _cmd in ${extra_started_commands}; do
|
|
|
|
if [ "${_cmd}" = "$1" ]; then
|
|
|
|
if ! service_started "${SVCNAME}"; then
|
|
|
|
eerror "${SVCNAME}: cannot \`$1' as it has not been started"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2007-11-28 18:38:25 +05:30
|
|
|
unset _cmd
|
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-23 17:34:11 +05:30
|
|
|
if [ "${_cmd}" = "start" -o "${_cmd}" = "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
|