summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorChristian Heim <phreak@gentoo.org>2006-04-07 11:56:04 +0000
committerChristian Heim <phreak@gentoo.org>2006-04-07 11:56:04 +0000
commit7978075fa644e5de43d6ea3433b40549a31fe342 (patch)
treedec7584dbf162325a6a0b0f6903bad30a1dc0753 /sbin
parentMerging r1948 (diff)
downloadbaselayout-vserver-7978075fa644e5de43d6ea3433b40549a31fe342.tar.gz
baselayout-vserver-7978075fa644e5de43d6ea3433b40549a31fe342.tar.bz2
baselayout-vserver-7978075fa644e5de43d6ea3433b40549a31fe342.zip
Merging r1959
svn path=/baselayout-vserver/trunk/; revision=313
Diffstat (limited to 'sbin')
-rwxr-xr-xsbin/functions.sh48
-rwxr-xr-xsbin/rc12
-rwxr-xr-xsbin/rc-daemon.sh2
-rwxr-xr-xsbin/rc-services.sh31
-rwxr-xr-xsbin/runscript.sh163
5 files changed, 148 insertions, 108 deletions
diff --git a/sbin/functions.sh b/sbin/functions.sh
index 1911236..e8d2d4e 100755
--- a/sbin/functions.sh
+++ b/sbin/functions.sh
@@ -214,8 +214,10 @@ ewarn() {
echo -e " ${WARN}*${NORMAL} ${RC_INDENTATION}$*"
fi
+ local name="rc-scripts"
+ [[ $0 != "/sbin/runscript.sh" ]] && name="${0##*/}"
# Log warnings to system log
- esyslog "daemon.warning" "rc-scripts" "$*"
+ esyslog "daemon.warning" "${name}" "$*"
LAST_E_CMD="ewarn"
return 0
@@ -233,6 +235,8 @@ eerror() {
echo -e " ${BAD}*${NORMAL} ${RC_INDENTATION}$*"
fi
+ local name="rc-scripts"
+ [[ $0 != "/sbin/runscript.sh" ]] && name="${0##*/}"
# Log errors to system log
esyslog "daemon.err" "rc-scripts" "$*"
@@ -466,35 +470,6 @@ dolisting() {
echo "${mylist}"
}
-# void save_options(char *option, char *optstring)
-#
-# save the settings ("optstring") for "option"
-#
-save_options() {
- local myopts="$1"
-
- shift
- if [[ ! -d "${svcdir}/options/${SVCNAME}" ]] ; then
- mkdir -p -m 0755 "${svcdir}/options/${SVCNAME}"
- fi
-
- echo "$*" > "${svcdir}/options/${SVCNAME}/${myopts}"
-
- return 0
-}
-
-# char *get_options(char *option)
-#
-# get the "optstring" for "option" that was saved
-# by calling the save_options function
-#
-get_options() {
- if [[ -f "${svcdir}/options/${SVCNAME}/$1" ]] ; then
- echo "$(< ${svcdir}/options/${SVCNAME}/$1)"
- fi
-
- return 0
-}
# char *add_suffix(char * configfile)
#
@@ -669,6 +644,19 @@ requote() {
echo "$*"
}
+# char* uniqify(char *arg, ...)
+#
+# Ensure that params are unique
+#
+uniqify() {
+ local result= x=
+ while [[ -n "$1" ]] ; do
+ [[ " ${result} " != *" $1 "* ]] && result="${result} $1"
+ shift
+ done
+ echo "${result# *}"
+}
+
##############################################################################
# #
# This should be the last code in here, please add all functions above!! #
diff --git a/sbin/rc b/sbin/rc
index eb4a78d..ca7c710 100755
--- a/sbin/rc
+++ b/sbin/rc
@@ -119,7 +119,17 @@ else
else
# Non-normal runlevels don't include boot scripts as default
mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")"
- fi
+
+ # As we're in the bootlevel, add any services that failed due
+ # to /dev/.rcsysinit existing to the list
+ if [[ -d /dev/.rcafterinit ]] ; then
+ for x in $(dolisting /dev/.rcafterinit/) ; do
+ [[ -L ${x} ]] && myscripts="${myscripts} ${x##*/}"
+ done
+ einfo "Device initiated services:${HILITE}${myscripts}${NORMAL}"
+ rm -rf /dev/.rcafterinit
+ fi
+ fi
for x in ${mylevels} ; do
[[ -L ${x} ]] && myscripts="${myscripts} ${x##*/}"
diff --git a/sbin/rc-daemon.sh b/sbin/rc-daemon.sh
index 81ca457..3d89447 100755
--- a/sbin/rc-daemon.sh
+++ b/sbin/rc-daemon.sh
@@ -265,7 +265,7 @@ rc_start_daemon() {
# Returns 0 if everything was successful otherwise 1
rc_stop_daemon() {
local pid pids retval="0"
-
+
if [[ -n ${cmd} ]]; then
if ! is_daemon_running ${cmd} "${pidfile}" ; then
[[ ${RC_FAIL_ON_ZOMBIE} == "yes" ]] && return 1
diff --git a/sbin/rc-services.sh b/sbin/rc-services.sh
index 199a8d2..df0b557 100755
--- a/sbin/rc-services.sh
+++ b/sbin/rc-services.sh
@@ -255,11 +255,40 @@ is_runlevel_stop() {
[[ -d "${svcdir}/softscripts.new" ]]
}
+# void save_options(char *option, char *optstring)
+#
+# save the settings ("optstring") for "option"
+#
+save_options() {
+ local myopts="$1"
+
+ shift
+ if [[ ! -d "${svcdir}/options/${SVCNAME}" ]] ; then
+ mkdir -p -m 0755 "${svcdir}/options/${SVCNAME}"
+ fi
+
+ echo "$*" > "${svcdir}/options/${SVCNAME}/${myopts}"
+}
+
+# char *get_options(char *option)
+#
+# get the "optstring" for "option" that was saved
+# by calling the save_options function
+#
+get_options() {
+ local svc="${SVCNAME}"
+ [[ -n $2 ]] && svc="$2"
+
+ if [[ -f "${svcdir}/options/${svc}/$1" ]] ; then
+ echo "$(< ${svcdir}/options/${svc}/$1)"
+ fi
+}
+
# void sevice_message([char *type] char *message)
#
# Print out a service message if we are on parallel
service_message() {
- [[ ${RC_PARALLEL_STARTUP} != "yes" ]] && return
+ [[ ${RC_PARALLEL_STARTUP} != "yes" || ${RC_QUIET} == "yes" ]] && return
local cmd="einfo"
case "$1" in
diff --git a/sbin/runscript.sh b/sbin/runscript.sh
index 2c184c8..3a4dd6f 100755
--- a/sbin/runscript.sh
+++ b/sbin/runscript.sh
@@ -26,6 +26,9 @@ myservice="${SVCNAME}"
# Stop init scripts from working until sysinit completes
if [[ -e /dev/.rcsysinit ]] ; then
eerror "ERROR: cannot run ${SVCNAME} until sysinit completes"
+ # Try to add this service to a queue when sysinit has completed
+ [[ ! -d /dev/.rcafterinit ]] && mkdir /dev/.rcafterinit
+ ln -snf "$1" /dev/.rcafterinit/"${SVCNAME}"
exit 1
fi
@@ -85,9 +88,9 @@ service_inactive "${SVCNAME}"
svcinactive="$?"
svc_quit() {
eerror "ERROR: ${SVCNAME} caught an interrupt"
- if service_inactive "${SVCNAME}" || [[ ${svcinactive} == 0 ]] ; then
+ if service_inactive "${SVCNAME}" || [[ ${svcinactive} == "0" ]] ; then
mark_service_inactive "${SVCNAME}"
- elif [[ ${svcstarted} == 0 ]] ; then
+ elif [[ ${svcstarted} == "0" ]] ; then
mark_service_started "${SVCNAME}"
else
mark_service_stopped "${SVCNAME}"
@@ -175,7 +178,7 @@ svc_stop() {
ewarn "WARNING: you are stopping a boot service."
fi
- if [[ ${svcpause} != "yes" ]] ; then
+ if [[ ${svcpause} != "yes" && ${RC_NO_DEPS} != "yes" ]] ; then
if [[ ${NETSERVICE} == "yes" ]] ; then
# A net.* service
if in_runlevel "${SVCNAME}" "${BOOTLEVEL}" || \
@@ -219,7 +222,7 @@ svc_stop() {
IN_BACKGROUND="${ib_save}"
- if [[ ${retval} != 0 ]] ; then
+ if [[ ${retval} != "0" ]] ; then
eerror "ERROR: problems stopping dependent services."
eerror " ${SVCNAME} is still up."
else
@@ -240,7 +243,7 @@ svc_stop() {
# If a service has been marked inactive, exit now as something
# may attempt to start it again later
- if service_inactive "${SVCNAME}" ; then
+ if [[ ${retval} == "0" ]] && service_inactive "${SVCNAME}" ; then
svcinactive=0
return 0
fi
@@ -255,7 +258,7 @@ svc_stop() {
if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then
mark_service_stopped "${SVCNAME}"
else
- if [[ ${svcinactive} == 0 ]] ; then
+ if [[ ${svcinactive} == "0" ]] ; then
mark_service_inactive "${SVCNAME}"
else
mark_service_started "${SVCNAME}"
@@ -309,82 +312,88 @@ svc_start() {
service_message "Service ${SVCNAME} starting"
+ if broken "${SVCNAME}" ; then
+ eerror "ERROR: Some services needed are missing. Run"
+ eerror " './${SVCNAME} broken' for a list of those"
+ eerror " services. ${SVCNAME} was not started."
+ retval=1
+ fi
+
# Save the IN_BACKGROUND var as we need to clear it for starting depends
local ib_save="${IN_BACKGROUND}"
unset IN_BACKGROUND
- local startupservices="$(ineed "${SVCNAME}") $(valid_iuse "${SVCNAME}")"
- local netservices=
- for x in $(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
- $(dolisting "/etc/runlevels/${mylevel}/net.*") ; do
- netservices="${netservices} ${x##*/}"
- done
-
- # Start dependencies, if any.
- if ! is_runlevel_start ; then
- for x in ${startupservices} ; do
- if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] && ! is_net_up ; then
- for y in ${netservices} ; do
- service_stopped "${y}" && start_service "${y}"
- done
- elif [[ ${x} != "net" ]] ; then
- if service_stopped "${x}" ; then
- start_service "${x}"
- fi
- fi
+ if [[ ${retval} == "0" && ${RC_NO_DEPS} != "yes" ]] ; then
+ local startupservices="$(ineed "${SVCNAME}") $(valid_iuse "${SVCNAME}")"
+ local netservices=
+ for x in $(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
+ $(dolisting "/etc/runlevels/${mylevel}/net.*") ; do
+ netservices="${netservices} ${x##*/}"
done
- fi
- # We also wait for any services we're after to finish incase they
- # have a "before" dep but we don't dep on them.
- if is_runlevel_start ; then
- startupservices="${startupservices} $(valid_iafter "${SVCNAME}")"
- fi
+ # Start dependencies, if any.
+ if ! is_runlevel_start ; then
+ for x in ${startupservices} ; do
+ if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] && ! is_net_up ; then
+ for y in ${netservices} ; do
+ service_stopped "${y}" && start_service "${y}"
+ done
+ elif [[ ${x} != "net" ]] ; then
+ if service_stopped "${x}" ; then
+ start_service "${x}"
+ fi
+ fi
+ done
+ fi
- if [[ " ${startupservices} " == *" net "* ]] ; then
- startupservices=" ${startupservices} "
- startupservices="${startupservices/ net / ${netservices} }"
- startupservices="${startupservices// net /}"
- fi
+ # We also wait for any services we're after to finish incase they
+ # have a "before" dep but we don't dep on them.
+ if is_runlevel_start ; then
+ startupservices="${startupservices} $(valid_iafter "${SVCNAME}")"
+ fi
- # Wait for dependencies to finish.
- for x in ${startupservices} ; do
- service_started "${x}" && continue
- wait_service "${x}"
- if ! service_started "${x}" ; then
- # A 'need' dependency is critical for startup
- if ineed -t "${SVCNAME}" "${x}" >/dev/null \
- || net_service "${x}" && ineed -t "${SVCNAME}" net \
- && ! is_net_up ; then
- if service_inactive "${x}" || service_wasinactive "${x}" || \
- [[ -n $(ls "${svcdir}"/scheduled/*/"${x}" 2>/dev/null) ]] ; then
- svc_schedule_start "${x}" "${SVCNAME}"
- [[ -n ${startinactive} ]] && startinactive="${startinactive}, "
- startinactive="${startinactive}${x}"
- else
- startfail="${x}"
- break
+ if [[ " ${startupservices} " == *" net "* ]] ; then
+ startupservices=" ${startupservices} "
+ startupservices="${startupservices/ net / ${netservices} }"
+ startupservices="${startupservices// net /}"
+ fi
+
+ # Wait for dependencies to finish.
+ for x in ${startupservices} ; do
+ service_started "${x}" && continue
+ wait_service "${x}"
+ if ! service_started "${x}" ; then
+ # A 'need' dependency is critical for startup
+ if ineed -t "${SVCNAME}" "${x}" >/dev/null \
+ || net_service "${x}" && ineed -t "${SVCNAME}" net \
+ && ! is_net_up ; then
+ if service_inactive "${x}" || service_wasinactive "${x}" || \
+ [[ -n $(ls "${svcdir}"/scheduled/*/"${x}" 2>/dev/null) ]] ; then
+ svc_schedule_start "${x}" "${SVCNAME}"
+ [[ -n ${startinactive} ]] && startinactive="${startinactive}, "
+ startinactive="${startinactive}${x}"
+ else
+ startfail="${x}"
+ break
+ fi
fi
fi
+ done
+
+ if [[ -n ${startfail} ]] ; then
+ eerror "ERROR: Problem starting needed service ${startfail}"
+ eerror " ${SVCNAME} was not started."
+ retval=1
+ elif [[ -n ${startinactive} ]] ; then
+ # Change the last , to or for correct grammar.
+ x="${startinactive##*, }"
+ startinactive="${startinactive/%, ${x}/ or ${x}}"
+ ewarn "WARNING: ${SVCNAME} is scheduled to start when ${startinactive} has started."
+ retval=1
fi
- done
-
- if [[ -n ${startfail} ]] ; then
- eerror "ERROR: Problem starting needed service ${startfail}"
- eerror " ${SVCNAME} was not started."
- retval=1
- elif [[ -n ${startinactive} ]] ; then
- # Change the last , to or for correct grammar.
- x="${startinactive##*, }"
- startinactive="${startinactive/%, ${x}/ or ${x}}"
- ewarn "WARNING: ${SVCNAME} is scheduled to start when ${startinactive} has started."
- retval=1
- elif broken "${SVCNAME}" ; then
- eerror "ERROR: Some services needed are missing. Run"
- eerror " './${SVCNAME} broken' for a list of those"
- eerror " services. ${SVCNAME} was not started."
- retval=1
- else
+ fi
+
+ if [[ ${retval} == "0" ]] ; then
IN_BACKGROUND="${ib_save}"
(
exit() {
@@ -407,15 +416,15 @@ svc_start() {
# If a service has been marked inactive, exit now as something
# may attempt to start it again later
- if service_inactive "${SVCNAME}" ; then
+ if [[ ${retval} == "0" ]] && service_inactive "${SVCNAME}" ; then
svcinactive=0
service_message "ewarn" "WARNING: ${SVCNAME} has started but is inactive"
return 1
fi
fi
- if [[ ${retval} != 0 ]] ; then
- if [[ ${svcinactive} == 0 ]] ; then
+ if [[ ${retval} != "0" ]] ; then
+ if [[ ${svcinactive} == "0" ]] ; then
mark_service_inactive "${SVCNAME}"
else
mark_service_stopped "${SVCNAME}"
@@ -531,12 +540,16 @@ fi
for arg in $* ; do
case "${arg}" in
--quiet)
+ RC_QUIET="yes"
RC_QUIET_STDOUT="yes"
;;
# We check this in functions.sh ...
# --nocolor)
# RC_NOCOLOR="yes"
# ;;
+ --nodeps)
+ RC_NO_DEPS="yes"
+ ;;
--verbose)
RC_VERBOSE="yes"
;;
@@ -652,7 +665,7 @@ for arg in $* ; do
retval="$?"
svcpause="no"
;;
- --quiet|--nocolor)
+ --quiet|--nocolor|--nodeps)
;;
help)
exec "${svclib}"/sh/rc-help.sh "${myscript}" help