summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorChristian Heim <phreak@gentoo.org>2006-05-25 10:09:00 +0000
committerChristian Heim <phreak@gentoo.org>2006-05-25 10:09:00 +0000
commit641e205510a26ca3ae4ed9d3f7e27221e2656bb7 (patch)
tree86e317c5d043dfbde91cb981229623ca4a189c52 /sbin
parentMerging baselayout r2022 for branches/rc-scripts_1_6, branches/baselayout-1_1... (diff)
downloadbaselayout-vserver-641e205510a26ca3ae4ed9d3f7e27221e2656bb7.tar.gz
baselayout-vserver-641e205510a26ca3ae4ed9d3f7e27221e2656bb7.tar.bz2
baselayout-vserver-641e205510a26ca3ae4ed9d3f7e27221e2656bb7.zip
Merging r2046
svn path=/baselayout-vserver/trunk/; revision=365
Diffstat (limited to 'sbin')
-rwxr-xr-xsbin/depscan.sh2
-rwxr-xr-xsbin/functions.sh16
-rwxr-xr-xsbin/rc55
-rwxr-xr-xsbin/rc-services.sh29
-rwxr-xr-xsbin/runscript.sh54
5 files changed, 97 insertions, 59 deletions
diff --git a/sbin/depscan.sh b/sbin/depscan.sh
index e9454a1..d0cff4a 100755
--- a/sbin/depscan.sh
+++ b/sbin/depscan.sh
@@ -68,7 +68,7 @@ fi
for x in softscripts snapshot options daemons \
started starting inactive wasinactive stopping failed \
- exclusive exitcodes scheduled ; do
+ exclusive exitcodes scheduled coldplugged ; do
if [[ ! -d "${mysvcdir}/${x}" ]] ; then
if ! mkdir -p -m 0755 "${mysvcdir}/${x}" 2>/dev/null ; then
eerror "Could not create needed directory '${mysvcdir}/${x}'!"
diff --git a/sbin/functions.sh b/sbin/functions.sh
index 423ada6..96f74ba 100755
--- a/sbin/functions.sh
+++ b/sbin/functions.sh
@@ -6,9 +6,6 @@ RC_GOT_FUNCTIONS="yes"
# Override defaults with user settings ...
[[ -f /etc/conf.d/rc ]] && source /etc/conf.d/rc
-# daemontools dir
-SVCDIR="/var/lib/supervise"
-
# Check /etc/conf.d/rc for a description of these ...
declare -r svclib="/lib/rcscripts"
declare -r svcdir="${svcdir:-/var/lib/init.d}"
@@ -340,7 +337,7 @@ veend() {
[[ ${RC_VERBOSE} == "yes" ]] && { eend "$@"; return $?; }
return ${1:-0}
}
-veend() {
+vewend() {
[[ ${RC_VERBOSE} == "yes" ]] && { ewend "$@"; return $?; }
return ${1:-0}
}
@@ -510,6 +507,17 @@ is_net_fs() {
return $?
}
+# bool is_net_fs(path)
+#
+# return 0 if path is under unionfs control
+#
+# EXAMPLE: if is_union_fs / ; then ...
+#
+is_union_fs() {
+ [[ ! -x /sbin/unionctl ]] && return 1
+ unionctl "$1" --list &>/dev/null
+}
+
# bool is_uml_sys()
#
# return 0 if the currently running system is User Mode Linux
diff --git a/sbin/rc b/sbin/rc
index 48b63f0..368deeb 100755
--- a/sbin/rc
+++ b/sbin/rc
@@ -123,8 +123,16 @@ else
# As we're in the bootlevel, add any services that failed due
# to /dev/.rcsysinit existing to the list
if [[ -d /dev/.rcboot ]] ; then
+ COLDPLUG_SERVICES=
for x in $(dolisting /dev/.rcboot/) ; do
- [[ -L ${x} ]] && myscripts="${myscripts} ${x##*/}"
+ [[ -L ${x} ]] && COLDPLUG_SERVICES="${COLDPLUG_SERVICES} ${x##*/}"
+ done
+ for x in ${COLDPLUG_SERVICES} ; do
+ if [[ ! -e /etc/runlevels/"${BOOTLEVEL}"/"${x}" \
+ && ! -e /etc/runlevels/"${DEFAULTLEVEL}"/"${x}" ]] ; then
+ myscripts="${myscripts} ${x}"
+ mark_service_coldplugged "${x}"
+ fi
done
einfo "Device initiated services:${HILITE}${myscripts}${NORMAL}"
rm -rf /dev/.rcboot
@@ -171,23 +179,15 @@ dep_stop() {
service_stopped "${myservice}" && return 0
- # Candidate for zapping ?
- [[ ! -L "${svcdir}/softscripts.new/${myservice}" ]] || \
- return 0
-
- # If this is a 'net' service, we do not want to stop it if it was
- # not in the previous runlevel, and we are not shutting down,
- # rebooting or going to single runlevel. This is because the user
- # (or hotplut) might have started it (net.ppp?) ...
- if net_service "${myservice}" && \
- [[ ${SOFTLEVEL} != "reboot" && \
- ${SOFTLEVEL} != "shutdown" ]] ; then
- if [[ -z ${OLDSOFTLEVEL} ]] || \
- ! in_runlevel "${myservice}" "${OLDSOFTLEVEL}" ; then
- # This service is not in the previous runlevel, so
- # do not stop it ...
- return 0
- fi
+ [[ -L ${svcdir}/softscripts.new/${service} ]] \
+ && return 0
+
+ if [[ ${SOFTLEVEL} != "reboot" \
+ && ${SOFTLEVEL} != "shutdown" ]] ; then
+ service_coldplugged "${service}" && return 0
+ [[ -z ${OLDSOFTLEVEL} ]] \
+ || ! in_runlevel "${service}" "${OLDSOFTLEVEL}" \
+ && return 0
fi
# Should not work for 'use'
@@ -254,24 +254,15 @@ fi
echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then
- source /sbin/functions.sh
-
# Clear $svcdir from stale entries, but leave the caches around, as it
# should help speed things up a bit
rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \
grep -ve '\(depcache\|deptree\|envcache\)')
-
- # Need try(), etc
- source "${svclib}"/sh/init-functions.sh
- source /etc/init.d/halt.sh
-
- if [[ ${SOFTLEVEL} == "reboot" ]] ; then
- source /etc/init.d/reboot.sh
- else
- source /etc/init.d/shutdown.sh
- fi
-
+ # Call halt.sh with LC_ALL=C so that bash doesn't load any locales
+ # which could interfere with unmounting /usr
+ LC_ALL=C exec /etc/init.d/halt.sh "${SOFTLEVEL}"
+
# Should never get here
exit 0
fi
@@ -292,7 +283,7 @@ get_start_services() {
-L "${svcdir}/softscripts/${LOGGER_SERVICE}" ]] && \
list="${list} ${LOGGER_SERVICE}"
- for x in $(dolisting "${svcdir}/softscripts/") ; do
+ for x in $(dolisting "${svcdir}/softscripts/") ; do
list="${list} ${x##*/}"
done
diff --git a/sbin/rc-services.sh b/sbin/rc-services.sh
index 25e1805..301669d 100755
--- a/sbin/rc-services.sh
+++ b/sbin/rc-services.sh
@@ -405,12 +405,14 @@ start_service() {
# if we can not start the services in parallel
# then just start it and return the exit status
( "/etc/init.d/${service}" start )
+ service_started "${service}" || service_inactive "${service}"
retval=$?
return "${retval}"
else
# if parallel startup is allowed, start it in background
(
- "/etc/init.d/${service}" start
+ "/etc/init.d/${service}" start
+ service_started "${service}" || service_inactive "${service}"
retval=$?
) &
return 0
@@ -448,18 +450,31 @@ stop_service() {
# if we can not start the services in parallel
# then just start it and return the exit status
( "/etc/init.d/${service}" stop )
+ service_stopped "${service}"
retval=$?
return "${retval}"
else
# if parallel startup is allowed, start it in background
(
( "/etc/init.d/${service}" stop )
+ service_stopped "${service}"
retval=$?
) &
return 0
fi
}
+# bool mark_service_coldplugged(service)
+#
+# Mark 'service' as coldplugged.
+#
+mark_service_coldplugged() {
+ [[ -z $1 ]] && return 1
+
+ ln -snf "/etc/init.d/$1" "${svcdir}/coldplugged/$1"
+ return 0
+}
+
# bool mark_service_starting(service)
#
# Mark 'service' as starting.
@@ -536,7 +551,8 @@ mark_service_stopped() {
rm -Rf "${svcdir}/daemons/$1" "${svcdir}/starting/$1" \
"${svcdir}/started/$1" "${svcdir}/inactive/$1" \
"${svcdir}/wasinactive/$1" "${svcdir}/stopping/$1" \
- "${svcdir}/scheduled/$1" "${svcdir}/options/$1"
+ "${svcdir}/scheduled/$1" "${svcdir}/options/$1" \
+ "${svcdir}/coldplugged/$1"
end_service "$1" 0
@@ -559,6 +575,14 @@ test_service_state() {
return 1
}
+# bool service_coldplugged(service)
+#
+# Returns true if 'service' is coldplugged
+#
+service_coldplugged() {
+ test_service_state "$1" "coldplugged"
+}
+
# bool service_starting(service)
#
# Returns true if 'service' is starting
@@ -718,7 +742,6 @@ valid_i() {
${x} == "net" ]] \
&& echo "${x}"
done
-
return 0
}
diff --git a/sbin/runscript.sh b/sbin/runscript.sh
index a54ff67..867878b 100755
--- a/sbin/runscript.sh
+++ b/sbin/runscript.sh
@@ -23,19 +23,24 @@ export SVCNAME
# Support deprecated myservice variable
myservice="${SVCNAME}"
+svc_trap() {
+ trap 'eerror "ERROR: ${SVCNAME} caught an interrupt"; exit 1' \
+ INT QUIT TSTP
+}
+
+# Setup a default trap
+svc_trap
+
# coldplug events can trigger init scripts, but we don't want to run them
# until after rc sysinit has completed so we punt them to the boot runlevel
if [[ -e /dev/.rcsysinit ]] ; then
eerror "ERROR: cannot run ${SVCNAME} until sysinit completes"
- [[ "${RC_COLDPLUG} " == "!* "* ]] && exit 1
- if [[ "${RC_COLDPLUG} " != "* "* ]] ; then
- for x in ${RC_COLDPLUG} ; do
- # We don't quote ${x} so we can do globbing
- [[ ${SVCNAME} == ${x} ]] && break
- [[ "!${SVCNAME}" == ${x} ]] && exit 1
- done
- [[ ${SVCNAME} == ${x} ]] || exit 1
- fi
+ [[ ${RC_COLDPLUG:-yes} != "yes" ]] && exit 1
+ set -f
+ for x in ${RC_PLUG_SERVICES} ; do
+ [[ ${SVCNAME} == ${x} ]] && break
+ [[ "!${SVCNAME}" == ${x} ]] && exit 1
+ done
eerror "${SVCNAME} will be started in the ${BOOTLEVEL} runlevel"
if [[ ! -L /dev/.rcboot/"${SVCNAME}" ]] ; then
[[ ! -d /dev/.rcboot ]] && mkdir /dev/.rcboot
@@ -44,13 +49,23 @@ if [[ -e /dev/.rcsysinit ]] ; then
exit 1
fi
-svc_trap() {
- trap 'eerror "ERROR: ${SVCNAME} caught an interrupt"; exit 1' \
- INT QUIT TSTP
-}
-
-# Setup a default trap
-svc_trap
+# Only hotplug if we're allowed to
+if [[ ${IN_HOTPLUG} == "1" ]] ; then
+ if [[ ${RC_HOTPLUG:-yes} != "yes" ]] ; then
+ eerror "${SVCNAME} is not allowed to be hotplugged"
+ exit 1
+ fi
+
+ set -f
+ for x in ${RC_PLUG_SERVICES} ; do
+ [[ ${SVCNAME} == ${x} ]] && break
+ if [[ "!${SVCNAME}" == ${x} ]] ; then
+ eerror "${SVCNAME} is not allowed to be hotplugged"
+ exit 1
+ fi
+ done
+ set +f
+fi
# State variables
svcpause="no"
@@ -381,9 +396,10 @@ svc_start() {
&& ! 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}"
+ if svc_schedule_start "${x}" "${SVCNAME}" ; then
+ [[ -n ${startinactive} ]] && startinactive="${startinactive}, "
+ startinactive="${startinactive}${x}"
+ fi
else
startfail="${x}"
break