From c2648ca5f539c450b27d35c7c0a3d41c6e193d8f Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 27 Feb 2008 20:29:32 +0000 Subject: Makefile SH variable now tweaks the default shell used by our scripts. --- sh/Makefile | 9 +-- sh/functions.in | 86 ----------------------- sh/functions.sh.in | 86 +++++++++++++++++++++++ sh/gendepends.sh | 77 --------------------- sh/gendepends.sh.in | 77 +++++++++++++++++++++ sh/rc-functions.in | 80 ---------------------- sh/rc-functions.sh.in | 80 ++++++++++++++++++++++ sh/runscript.sh | 185 -------------------------------------------------- sh/runscript.sh.in | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 429 insertions(+), 436 deletions(-) delete mode 100644 sh/functions.in create mode 100644 sh/functions.sh.in delete mode 100755 sh/gendepends.sh create mode 100644 sh/gendepends.sh.in delete mode 100644 sh/rc-functions.in create mode 100644 sh/rc-functions.sh.in delete mode 100755 sh/runscript.sh create mode 100644 sh/runscript.sh.in (limited to 'sh') diff --git a/sh/Makefile b/sh/Makefile index 47f431f..364a59b 100644 --- a/sh/Makefile +++ b/sh/Makefile @@ -1,7 +1,5 @@ DIR= ${RC_LIB}/sh -SRCS= functions.in rc-functions.in -OBJS= ${SRCS:.in=.sh} -INC= init-common-post.sh rc-mount.sh ${OBJS} +INC= init-common-post.sh rc-mount.sh functions.sh rc-functions.sh BIN= gendepends.sh net.sh runscript.sh INSTALLAFTER= _installafter @@ -12,11 +10,6 @@ include ${MK}/os.mk include Makefile.${SUBOS} include ${MK}/scripts.mk -# Ensure that the lib name is correct -.SUFFIXES: .in .sh -.in.sh: - sed -e 's:/lib/:/${LIBNAME}/:g' $< > $@ - _installafter: ${INSTALL} -d ${DESTDIR}/etc/init.d @# Provide an init script for the loopback interface diff --git a/sh/functions.in b/sh/functions.in deleted file mode 100644 index effce67..0000000 --- a/sh/functions.in +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -# Allow any sh script to work with einfo functions and friends -# We also provide a few helpful functions for other programs to use - -RC_GOT_FUNCTIONS="yes" - -eindent() -{ - EINFO_INDENT=$((${EINFO_INDENT:-0} + 2)) - [ "${EINFO_INDENT}" -gt 40 ] && EINFO_INDENT=40 - export EINFO_INDENT -} - -eoutdent() -{ - EINFO_INDENT=$((${EINFO_INDENT:-0} - 2)) - [ "${EINFO_INDENT}" -lt 0 ] && EINFO_INDENT=0 - return 0 -} - -yesno() -{ - [ -z "$1" ] && return 1 - - case "$1" in - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; - esac - - local value= - eval value=\$${1} - case "${value}" in - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; - *) vewarn "\$${1} is not set properly"; return 1;; - esac -} - -_sanitize_path() -{ - local IFS=":" p= path= - for p in ${PATH}; do - case "${p}" in - /lib/rc/sbin|/bin|/sbin|/usr/bin|/usr/sbin|/usr/pkg/bin|/usr/pkg/sbin|/usr/local/bin|/usr/local/sbin);; - *) path="${path}:${p}";; - esac - done - - echo "${path}" -} - -# Allow our scripts to support zsh -if [ -n "${ZSH_VERSION}" ]; then - emulate sh - NULLCMD=: - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -fi - -# Add our bin to $PATH -export PATH="/lib/rc/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin$(_sanitize_path "${PATH}")" -unset _sanitize_path - -for arg; do - case "${arg}" in - --nocolor|--nocolour|-C) - export EINFO_COLOR="NO" - ;; - esac -done - -if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then - if [ -z "${GOOD}" ]; then - eval $(eval_ecolors) - fi -else - # We need to have shell stub functions so our init scripts can remember - # the last ecmd - for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \ - vebegin veend veinfo vewarn vewend; do - eval "${_e}() { local _r; /lib/rc/bin/${_e} \"\$@\"; _r=$?; \ - export EINFO_LASTCMD=${_e}; return \$_r; }" - done -fi diff --git a/sh/functions.sh.in b/sh/functions.sh.in new file mode 100644 index 0000000..effce67 --- /dev/null +++ b/sh/functions.sh.in @@ -0,0 +1,86 @@ +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +# Allow any sh script to work with einfo functions and friends +# We also provide a few helpful functions for other programs to use + +RC_GOT_FUNCTIONS="yes" + +eindent() +{ + EINFO_INDENT=$((${EINFO_INDENT:-0} + 2)) + [ "${EINFO_INDENT}" -gt 40 ] && EINFO_INDENT=40 + export EINFO_INDENT +} + +eoutdent() +{ + EINFO_INDENT=$((${EINFO_INDENT:-0} - 2)) + [ "${EINFO_INDENT}" -lt 0 ] && EINFO_INDENT=0 + return 0 +} + +yesno() +{ + [ -z "$1" ] && return 1 + + case "$1" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; + esac + + local value= + eval value=\$${1} + case "${value}" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; + *) vewarn "\$${1} is not set properly"; return 1;; + esac +} + +_sanitize_path() +{ + local IFS=":" p= path= + for p in ${PATH}; do + case "${p}" in + /lib/rc/sbin|/bin|/sbin|/usr/bin|/usr/sbin|/usr/pkg/bin|/usr/pkg/sbin|/usr/local/bin|/usr/local/sbin);; + *) path="${path}:${p}";; + esac + done + + echo "${path}" +} + +# Allow our scripts to support zsh +if [ -n "${ZSH_VERSION}" ]; then + emulate sh + NULLCMD=: + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +fi + +# Add our bin to $PATH +export PATH="/lib/rc/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin$(_sanitize_path "${PATH}")" +unset _sanitize_path + +for arg; do + case "${arg}" in + --nocolor|--nocolour|-C) + export EINFO_COLOR="NO" + ;; + esac +done + +if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then + if [ -z "${GOOD}" ]; then + eval $(eval_ecolors) + fi +else + # We need to have shell stub functions so our init scripts can remember + # the last ecmd + for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \ + vebegin veend veinfo vewarn vewend; do + eval "${_e}() { local _r; /lib/rc/bin/${_e} \"\$@\"; _r=$?; \ + export EINFO_LASTCMD=${_e}; return \$_r; }" + done +fi diff --git a/sh/gendepends.sh b/sh/gendepends.sh deleted file mode 100755 index 712d29f..0000000 --- a/sh/gendepends.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/sh -# Shell wrapper to list our dependencies - -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -. /etc/init.d/functions.sh - -config() { - [ -n "$*" ] && echo "${SVCNAME} config $*" >&3 -} -need() { - [ -n "$*" ] && echo "${SVCNAME} ineed $*" >&3 -} -use() { - [ -n "$*" ] && echo "${SVCNAME} iuse $*" >&3 -} -before() { - [ -n "$*" ] && echo "${SVCNAME} ibefore $*" >&3 -} -after() { - [ -n "$*" ] && echo "${SVCNAME} iafter $*" >&3 -} -provide() { - [ -n "$*" ] && echo "${SVCNAME} iprovide $*" >&3 -} -keyword() { - [ -n "$*" ] && echo "${SVCNAME} keyword $*" >&3 -} -depend() { - : -} - -for _dir in /etc/init.d /usr/local/etc/init.d; do - [ -d "${_dir}" ] || continue - cd "${_dir}" - for SVCNAME in *; do - [ -x "${SVCNAME}" ] || continue - - # Only generate dependencies for runscripts - read one two < "${SVCNAME}" - [ "${one}" = "#!/sbin/runscript" ] || continue - unset one two - - export SVCNAME=${SVCNAME##*/} - ( - # Save stdout in fd3, then remap it to stderr - exec 3>&1 1>&2 - - _rc_c=${SVCNAME%%.*} - if [ -n "${_rc_c}" -a "${_rc_c}" != "${SVCNAME}" ]; then - if [ -e "${_dir}/../conf.d/${_rc_c}" ]; then - . "${_dir}/../conf.d/${_rc_c}" - fi - fi - unset _rc_c - - if [ -e "${_dir}/../conf.d/${SVCNAME}" ]; then - . "${_dir}/../conf.d/${SVCNAME}" - fi - - [ -e /etc/rc.conf ] && . /etc/rc.conf - - if . "${_dir}/${SVCNAME}"; then - echo "${SVCNAME}" >&3 - depend - - # Add any user defined depends - for _deptype in config need use after before provide keyword; do - eval _depends=\$rc_$(shell_var "${SVCNAME}")_${_deptype} - [ -z "${_depends}" ] && eval _depends=\$rc_${_deptype} - ${_deptype} ${_depends} - done - fi - ) - done -done diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in new file mode 100644 index 0000000..8e30a64 --- /dev/null +++ b/sh/gendepends.sh.in @@ -0,0 +1,77 @@ +#!@SHELL@ +# Shell wrapper to list our dependencies + +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +. /etc/init.d/functions.sh + +config() { + [ -n "$*" ] && echo "${SVCNAME} config $*" >&3 +} +need() { + [ -n "$*" ] && echo "${SVCNAME} ineed $*" >&3 +} +use() { + [ -n "$*" ] && echo "${SVCNAME} iuse $*" >&3 +} +before() { + [ -n "$*" ] && echo "${SVCNAME} ibefore $*" >&3 +} +after() { + [ -n "$*" ] && echo "${SVCNAME} iafter $*" >&3 +} +provide() { + [ -n "$*" ] && echo "${SVCNAME} iprovide $*" >&3 +} +keyword() { + [ -n "$*" ] && echo "${SVCNAME} keyword $*" >&3 +} +depend() { + : +} + +for _dir in /etc/init.d /usr/local/etc/init.d; do + [ -d "${_dir}" ] || continue + cd "${_dir}" + for SVCNAME in *; do + [ -x "${SVCNAME}" ] || continue + + # Only generate dependencies for runscripts + read one two < "${SVCNAME}" + [ "${one}" = "#!/sbin/runscript" ] || continue + unset one two + + export SVCNAME=${SVCNAME##*/} + ( + # Save stdout in fd3, then remap it to stderr + exec 3>&1 1>&2 + + _rc_c=${SVCNAME%%.*} + if [ -n "${_rc_c}" -a "${_rc_c}" != "${SVCNAME}" ]; then + if [ -e "${_dir}/../conf.d/${_rc_c}" ]; then + . "${_dir}/../conf.d/${_rc_c}" + fi + fi + unset _rc_c + + if [ -e "${_dir}/../conf.d/${SVCNAME}" ]; then + . "${_dir}/../conf.d/${SVCNAME}" + fi + + [ -e /etc/rc.conf ] && . /etc/rc.conf + + if . "${_dir}/${SVCNAME}"; then + echo "${SVCNAME}" >&3 + depend + + # Add any user defined depends + for _deptype in config need use after before provide keyword; do + eval _depends=\$rc_$(shell_var "${SVCNAME}")_${_deptype} + [ -z "${_depends}" ] && eval _depends=\$rc_${_deptype} + ${_deptype} ${_depends} + done + fi + ) + done +done diff --git a/sh/rc-functions.in b/sh/rc-functions.in deleted file mode 100644 index 2a57709..0000000 --- a/sh/rc-functions.in +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2007 Gentoo Foundation -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -has_addon() -{ - [ -e "${RC_LIBDIR}/addons/$1.sh" ] || [ -e /lib/rcscripts/addons/"$1".sh ] -} - -import_addon() -{ - if [ -e "${RC_LIBDIR}/addons/$1.sh" ]; then - . "${RC_LIBDIR}/addons/$1.sh" - elif [ -e /lib/rcscripts/addons/"$1".sh ]; then - . /lib/rcscripts/addons/"$1".sh - else - return 1 - fi -} - -start_addon() -{ - ( import_addon "$1-start" ) -} - -stop_addon() -{ - ( import_addon "$1-stop" ) -} - -net_fs_list="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" -is_net_fs() -{ - [ -z "$1" ] && return 1 - - # Check OS specific flags to see if we're local or net mounted - mountinfo --quiet --netdev "$1" && return 0 - mountinfo --quiet --nonetdev "$1" && return 1 - - # Fall back on fs types - local t=$(mountinfo --fstype "$1") - for x in ${net_fs_list}; do - [ "${x}" = "${t}" ] && return 0 - done - return 1 -} - -is_union_fs() -{ - [ ! -x /sbin/unionctl ] && return 1 - unionctl "$1" --list >/dev/null 2>&1 -} - -get_bootparam() -{ - local match="$1" - [ -z "${match}" -o ! -r /proc/cmdline ] && return 1 - - set -- $(cat /proc/cmdline) - while [ -n "$1" ]; do - case "$1" in - gentoo=*) - local params="${1##*=}" - local IFS=, x= - for x in ${params}; do - [ "${x}" = "${match}" ] && return 0 - done - ;; - esac - shift - done - - return 1 -} - -# Add our sbin to $PATH -case "${PATH}" in - /lib/rc/sbin|/lib/rc/sbin:*);; - *) export PATH="/lib/rc/sbin:${PATH}";; -esac diff --git a/sh/rc-functions.sh.in b/sh/rc-functions.sh.in new file mode 100644 index 0000000..2a57709 --- /dev/null +++ b/sh/rc-functions.sh.in @@ -0,0 +1,80 @@ +# Copyright 2007 Gentoo Foundation +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +has_addon() +{ + [ -e "${RC_LIBDIR}/addons/$1.sh" ] || [ -e /lib/rcscripts/addons/"$1".sh ] +} + +import_addon() +{ + if [ -e "${RC_LIBDIR}/addons/$1.sh" ]; then + . "${RC_LIBDIR}/addons/$1.sh" + elif [ -e /lib/rcscripts/addons/"$1".sh ]; then + . /lib/rcscripts/addons/"$1".sh + else + return 1 + fi +} + +start_addon() +{ + ( import_addon "$1-start" ) +} + +stop_addon() +{ + ( import_addon "$1-stop" ) +} + +net_fs_list="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" +is_net_fs() +{ + [ -z "$1" ] && return 1 + + # Check OS specific flags to see if we're local or net mounted + mountinfo --quiet --netdev "$1" && return 0 + mountinfo --quiet --nonetdev "$1" && return 1 + + # Fall back on fs types + local t=$(mountinfo --fstype "$1") + for x in ${net_fs_list}; do + [ "${x}" = "${t}" ] && return 0 + done + return 1 +} + +is_union_fs() +{ + [ ! -x /sbin/unionctl ] && return 1 + unionctl "$1" --list >/dev/null 2>&1 +} + +get_bootparam() +{ + local match="$1" + [ -z "${match}" -o ! -r /proc/cmdline ] && return 1 + + set -- $(cat /proc/cmdline) + while [ -n "$1" ]; do + case "$1" in + gentoo=*) + local params="${1##*=}" + local IFS=, x= + for x in ${params}; do + [ "${x}" = "${match}" ] && return 0 + done + ;; + esac + shift + done + + return 1 +} + +# Add our sbin to $PATH +case "${PATH}" in + /lib/rc/sbin|/lib/rc/sbin:*);; + *) export PATH="/lib/rc/sbin:${PATH}";; +esac diff --git a/sh/runscript.sh b/sh/runscript.sh deleted file mode 100755 index 63c780a..0000000 --- a/sh/runscript.sh +++ /dev/null @@ -1,185 +0,0 @@ -#!/bin/sh -# Shell wrapper for runscript - -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -. /etc/init.d/functions.sh -. "${RC_LIBDIR}"/sh/rc-functions.sh - -# Support LiveCD foo -if [ -r /sbin/livecd-functions.sh ]; then - . /sbin/livecd-functions.sh - livecd_read_commandline -fi - -if [ -z "$1" -o -z "$2" ]; then - eerror "${SVCNAME}: not enough arguments" - exit 1 -fi - -# Descript the init script to the user -describe() -{ - if [ -n "${description}" ]; then - einfo "${description}" - else - ewarn "No description for ${SVCNAME}" - fi - - local svc= desc= - for svc in ${extra_commands:-${opts}} ${extra_started_commands}; do - eval desc=\$description_${svc} - if [ -n "${desc}" ]; then - einfo "${HILITE}${svc}${NORMAL}: ${desc}" - else - ewarn "${HILITE}${svc}${NORMAL}: no description" - fi - done -} - -yesno ${RC_DEBUG} && set -x - -# If we're net.eth0 or openvpn.work then load net or openvpn config -_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}" - fi -fi -unset _c - -# Overlay with our specific config -if [ -e "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" ]; then - . "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" -elif [ -e "/etc/conf.d/${SVCNAME}" ]; then - . "/etc/conf.d/${SVCNAME}" -fi - -# Load any system overrides -[ -e /etc/rc.conf ] && . /etc/rc.conf - -# Apply any ulimit defined -[ -n "${rc_ulimit:-${RC_ULIMIT}}" ] && ulimit ${rc_ulimit:-${RC_ULIMIT}} - -# Load our script -. $1 -shift - -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 - -# 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() { - local _background= - ebegin "Starting ${name:-${SVCNAME}}" - if yesno "${command_background}"; then - _background="--background --pidfile" - fi - if yesno "${start_inactive}"; then - local _inactive=false - service_inactive && _inactive=true - mark_service_inactive - fi - start-stop-daemon --start \ - --exec ${command} \ - ${procname:+--name} ${procname} \ - ${pidfile:+--pidfile} ${pidfile} \ - ${_background} ${start_stop_daemon_args} \ - -- ${command_args} - eend $? "Failed to start ${SVCNAME}" && return 0 - if yesno "${start_inactive}"; then - if ! ${_inactive}; then - mark_service_stopped - fi - fi - return 1 - } - 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} - eend $? "Failed to stop ${SVCNAME}" - } - fi -fi - -while [ -n "$1" ]; do - # See if we have the required function and run it - for _cmd in describe start stop ${extra_commands:-${opts}} \ - ${extra_started_commands}; do - if [ "${_cmd}" = "$1" ]; then - if type "$1" >/dev/null 2>&1; then - # 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. - if yesno ${IN_BACKGROUND}; then - for _cmd in ${in_background_fake}; do - if [ "${_cmd}" = "$1" ]; then - shift - continue 3 - fi - done - fi - # Check to see if we need to be started before - # we can run this command - for _cmd in ${extra_started_commands}; do - if [ "${_cmd}" = "$1" ]; then - if ! service_started; then - eerror "${SVCNAME}: cannot \`$1' as it has not been started" - exit 1 - fi - fi - done - unset _cmd - if type "$1"_pre >/dev/null 2>&1; then - "$1"_pre || exit $? - fi - "$1" || exit $? - if type "$1"_post >/dev/null 2>&1; then - "$1"_post || exit $? - fi - shift - continue 2 - else - if [ "${_cmd}" = "start" -o "${_cmd}" = "stop" ]; then - shift - continue 2 - else - eerror "${SVCNAME}: function \`$1' defined but does not exist" - exit 1 - fi - fi - fi - done - eerror "${SVCNAME}: unknown function \`$1'" - exit 1 -done diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in new file mode 100644 index 0000000..6b8c3db --- /dev/null +++ b/sh/runscript.sh.in @@ -0,0 +1,185 @@ +#!@SHELL@ +# Shell wrapper for runscript + +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +. /etc/init.d/functions.sh +. "${RC_LIBDIR}"/sh/rc-functions.sh + +# Support LiveCD foo +if [ -r /sbin/livecd-functions.sh ]; then + . /sbin/livecd-functions.sh + livecd_read_commandline +fi + +if [ -z "$1" -o -z "$2" ]; then + eerror "${SVCNAME}: not enough arguments" + exit 1 +fi + +# Descript the init script to the user +describe() +{ + if [ -n "${description}" ]; then + einfo "${description}" + else + ewarn "No description for ${SVCNAME}" + fi + + local svc= desc= + for svc in ${extra_commands:-${opts}} ${extra_started_commands}; do + eval desc=\$description_${svc} + if [ -n "${desc}" ]; then + einfo "${HILITE}${svc}${NORMAL}: ${desc}" + else + ewarn "${HILITE}${svc}${NORMAL}: no description" + fi + done +} + +yesno ${RC_DEBUG} && set -x + +# If we're net.eth0 or openvpn.work then load net or openvpn config +_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}" + fi +fi +unset _c + +# Overlay with our specific config +if [ -e "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" ]; then + . "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" +elif [ -e "/etc/conf.d/${SVCNAME}" ]; then + . "/etc/conf.d/${SVCNAME}" +fi + +# Load any system overrides +[ -e /etc/rc.conf ] && . /etc/rc.conf + +# Apply any ulimit defined +[ -n "${rc_ulimit:-${RC_ULIMIT}}" ] && ulimit ${rc_ulimit:-${RC_ULIMIT}} + +# Load our script +. $1 +shift + +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 + +# 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() { + local _background= + ebegin "Starting ${name:-${SVCNAME}}" + if yesno "${command_background}"; then + _background="--background --pidfile" + fi + if yesno "${start_inactive}"; then + local _inactive=false + service_inactive && _inactive=true + mark_service_inactive + fi + start-stop-daemon --start \ + --exec ${command} \ + ${procname:+--name} ${procname} \ + ${pidfile:+--pidfile} ${pidfile} \ + ${_background} ${start_stop_daemon_args} \ + -- ${command_args} + eend $? "Failed to start ${SVCNAME}" && return 0 + if yesno "${start_inactive}"; then + if ! ${_inactive}; then + mark_service_stopped + fi + fi + return 1 + } + 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} + eend $? "Failed to stop ${SVCNAME}" + } + fi +fi + +while [ -n "$1" ]; do + # See if we have the required function and run it + for _cmd in describe start stop ${extra_commands:-${opts}} \ + ${extra_started_commands}; do + if [ "${_cmd}" = "$1" ]; then + if type "$1" >/dev/null 2>&1; then + # 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. + if yesno ${IN_BACKGROUND}; then + for _cmd in ${in_background_fake}; do + if [ "${_cmd}" = "$1" ]; then + shift + continue 3 + fi + done + fi + # Check to see if we need to be started before + # we can run this command + for _cmd in ${extra_started_commands}; do + if [ "${_cmd}" = "$1" ]; then + if ! service_started; then + eerror "${SVCNAME}: cannot \`$1' as it has not been started" + exit 1 + fi + fi + done + unset _cmd + if type "$1"_pre >/dev/null 2>&1; then + "$1"_pre || exit $? + fi + "$1" || exit $? + if type "$1"_post >/dev/null 2>&1; then + "$1"_post || exit $? + fi + shift + continue 2 + else + if [ "${_cmd}" = "start" -o "${_cmd}" = "stop" ]; then + shift + continue 2 + else + eerror "${SVCNAME}: function \`$1' defined but does not exist" + exit 1 + fi + fi + fi + done + eerror "${SVCNAME}: unknown function \`$1'" + exit 1 +done -- cgit v1.2.3