2008-02-28 01:59:32 +05:30
|
|
|
#!@SHELL@
|
2007-04-05 16:48:42 +05:30
|
|
|
# Shell wrapper for runscript
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-01-11 21:01:10 +05:30
|
|
|
# Copyright 2007-2008 Roy Marples <roy@marples.name>
|
|
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-03-05 17:57:11 +05:30
|
|
|
. @PREFIX@/@SYSCONFDIR@/init.d/functions.sh
|
2007-04-05 16:48:42 +05:30
|
|
|
. "${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
|
|
|
|
|
2008-03-11 20:30:16 +05:30
|
|
|
# So daemons know where to recall us if needed
|
|
|
|
export RC_SERVICE="$1"
|
|
|
|
|
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
|
|
|
|
2008-03-03 16:03:42 +05:30
|
|
|
_conf_d=${1%/*}/../conf.d
|
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
|
2008-03-03 16:03:42 +05:30
|
|
|
if [ -e "${_conf_d}/${_c}.${RC_SOFTLEVEL}" ]; then
|
|
|
|
. "${_conf_d}/${_c}.${RC_SOFTLEVEL}"
|
|
|
|
elif [ -e "${_conf_d}/${_c}" ]; then
|
|
|
|
. "${_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
|
2008-03-03 16:03:42 +05:30
|
|
|
if [ -e "${_conf_d}/${SVCNAME}.${RC_SOFTLEVEL}" ]; then
|
|
|
|
. "${_conf_d}/${SVCNAME}.${RC_SOFTLEVEL}"
|
|
|
|
elif [ -e "${_conf_d}/${SVCNAME}" ]; then
|
|
|
|
. "${_conf_d}/${SVCNAME}"
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2008-03-03 16:03:42 +05:30
|
|
|
unset _conf_d
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Load any system overrides
|
2008-03-05 17:57:11 +05:30
|
|
|
[ -e @PREFIX@/@SYSCONFDIR@/rc.conf ] && . @PREFIX@/@SYSCONFDIR@/rc.conf
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# 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
|
2008-01-23 17:47:50 +05:30
|
|
|
service_inactive && _inactive=true
|
|
|
|
mark_service_inactive
|
2007-12-04 21:45:32 +05:30
|
|
|
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
|
2008-01-23 17:47:50 +05:30
|
|
|
mark_service_stopped
|
2007-12-04 21:45:32 +05:30
|
|
|
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
|
2008-01-23 17:47:50 +05:30
|
|
|
if ! service_started; then
|
2007-11-29 21:53:59 +05:30
|
|
|
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
|
2008-01-26 22:16:53 +05:30
|
|
|
shift
|
|
|
|
continue 2
|
2007-04-05 16:48:42 +05:30
|
|
|
else
|
|
|
|
eerror "${SVCNAME}: function \`$1' defined but does not exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
eerror "${SVCNAME}: unknown function \`$1'"
|
|
|
|
exit 1
|
|
|
|
done
|