summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorChristian Heim <phreak@gentoo.org>2006-01-19 17:13:13 +0000
committerChristian Heim <phreak@gentoo.org>2006-01-19 17:13:13 +0000
commit2fc04a041525a0215e9eb3ca54e4617c1be7b4f7 (patch)
tree2d0c6f0239789614db2400bdd742d6aa96c1c201 /sbin
parentMerging r1828 (diff)
downloadbaselayout-vserver-2fc04a041525a0215e9eb3ca54e4617c1be7b4f7.tar.gz
baselayout-vserver-2fc04a041525a0215e9eb3ca54e4617c1be7b4f7.tar.bz2
baselayout-vserver-2fc04a041525a0215e9eb3ca54e4617c1be7b4f7.zip
Merging r1832
svn path=/baselayout-vserver/trunk/; revision=212
Diffstat (limited to 'sbin')
-rwxr-xr-xsbin/depscan.sh6
-rwxr-xr-xsbin/rc-services.sh47
-rwxr-xr-xsbin/runscript.sh203
3 files changed, 116 insertions, 140 deletions
diff --git a/sbin/depscan.sh b/sbin/depscan.sh
index 20669d2..a67b8d7 100755
--- a/sbin/depscan.sh
+++ b/sbin/depscan.sh
@@ -16,7 +16,7 @@ if [[ ! -d ${svcdir} ]] ; then
fi
for x in softscripts snapshot options daemons \
- started starting inactive stopping failed \
+ started starting inactive wasinactive stopping failed \
exclusive exitcodes scheduled ; do
if [[ ! -d "${svcdir}/${x}" ]] ; then
if ! mkdir -p -m 0755 "${svcdir}/${x}" 2>/dev/null ; then
@@ -35,7 +35,7 @@ if [[ $1 == "-u" ]] ; then
# If its not there, we have to update, and make sure its present
# for next mtime testing
- if [[ ! -e ${svcdir}/depcache ]] ; then
+ if [[ ! -e "${svcdir}/depcache" ]] ; then
update=1
touch "${svcdir}/depcache"
fi
@@ -56,7 +56,7 @@ if [[ $1 == "-u" ]] ; then
shift
fi
-[[ ${update} == 0 ]] && exit 0
+[[ ${update} == 0 && -e "${svcdir}/deptree" ]] && exit 0
ebegin "Caching service dependencies"
diff --git a/sbin/rc-services.sh b/sbin/rc-services.sh
index 98bbcd9..1b68506 100755
--- a/sbin/rc-services.sh
+++ b/sbin/rc-services.sh
@@ -378,14 +378,12 @@ start_service() {
# then just start it and return the exit status
( "/etc/init.d/${service}" start )
retval=$?
- end_service "${service}" "${retval}"
return "${retval}"
else
# if parallel startup is allowed, start it in background
(
"/etc/init.d/${service}" start
retval=$?
- end_service "${service}" "${retval}"
) &
return 0
fi
@@ -423,14 +421,12 @@ stop_service() {
# then just start it and return the exit status
( "/etc/init.d/${service}" stop )
retval=$?
- end_service "${service}" "${retval}"
return "${retval}"
else
# if parallel startup is allowed, start it in background
(
( "/etc/init.d/${service}" stop )
retval=$?
- end_service "${service}" "${retval}"
) &
return 0
fi
@@ -445,8 +441,9 @@ mark_service_starting() {
ln -sn "/etc/init.d/$1" "${svcdir}/starting/$1" 2>/dev/null || return 1
- [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
[[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1"
+ [[ -f "${svcdir}/inactive/$1" ]] \
+ && mv "${svcdir}/inactive/$1" "${svcdir}/wasinactive/$1"
return 0
}
@@ -459,10 +456,12 @@ mark_service_started() {
ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
- [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1"
- [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
- [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1"
+ rm -f "${svcdir}/starting/$1" "${svcdir}/inactive/$1" \
+ "${svcdir}/wasinactive/$1" "${svcdir}/stopping/$1" \
+ "${svcdir}"/scheduled/*/"$1"
+ end_service "$1" 0
+
return 0
}
@@ -475,9 +474,10 @@ mark_service_inactive() {
ln -snf "/etc/init.d/$1" "${svcdir}/inactive/$1"
- [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1"
- [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1"
- [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1"
+ rm -f "${svcdir}/started/$1" "${svcdir}/wasinactive/$1" \
+ "${svcdir}/starting/$1" "${svcdir}/stopping/$1"
+
+ end_service "$1" 0
return 0
}
@@ -491,8 +491,10 @@ mark_service_stopping() {
ln -sn "/etc/init.d/$1" "${svcdir}/stopping/$1" 2>/dev/null || return 1
- [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
- [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1"
+ rm -f "${svcdir}/started/$1"
+ [[ -f "${svcdir}/inactive/$1" ]] \
+ && mv "${svcdir}/inactive/$1" "${svcdir}/wasinactive/$1"
+
return 0
}
@@ -503,11 +505,12 @@ mark_service_stopping() {
mark_service_stopped() {
[[ -z $1 ]] && return 1
- [[ -f "${svcdir}/daemons/$1" ]] && rm -f "${svcdir}/daemons/$1"
- [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1"
- [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1"
- [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
- [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1"
+ rm -Rf "${svcdir}/daemons/$1" "${svcdir}/starting/$1" \
+ "${svcdir}/started/$1" "${svcdir}/inactive/$1" \
+ "${svcdir}/wasinactive/$1" "${svcdir}/stopping/$1" \
+ "${svcdir}/scheduled/$1"
+
+ end_service "$1" 0
return 0
}
@@ -552,6 +555,14 @@ service_inactive() {
test_service_state "$1" "inactive"
}
+# bool service_wasinactive(service)
+#
+# Returns true if 'service' is inactive
+#
+service_wasinactive() {
+ test_service_state "$1" "wasinactive"
+}
+
# bool service_stopping(service)
#
# Returns true if 'service' is stopping
diff --git a/sbin/runscript.sh b/sbin/runscript.sh
index 19adc43..7fdd89e 100755
--- a/sbin/runscript.sh
+++ b/sbin/runscript.sh
@@ -11,10 +11,6 @@ if [[ ${EUID} != 0 ]] && ! [[ $2 == "status" && $# -eq 2 ]] ; then
exit 1
fi
-# State variables
-svcpause="no"
-svcrestart="no"
-
myscript="$1"
if [[ -L $1 && ! -L "/etc/init.d/${1##*/}" ]] ; then
myservice="$(readlink "$1")"
@@ -27,13 +23,17 @@ export SVCNAME="${myservice}"
mylevel="$(< "${svcdir}/softlevel")"
svc_trap() {
- trap 'eerror "ERROR: \"${myservice}\" caught an interrupt"; exit 1' \
+ trap 'eerror "ERROR: ${myservice} caught an interrupt"; exit 1' \
INT QUIT TSTP
}
# Setup a default trap
svc_trap
+# State variables
+svcpause="no"
+svcrestart="no"
+
# Functions to handle dependencies and services
[[ ${RC_GOT_SERVICES} != "yes" ]] && source "${svclib}/sh/rc-services.sh"
# Functions to control daemons
@@ -76,7 +76,6 @@ service_inactive "${myservice}"
svcinactive="$?"
svc_quit() {
eerror "ERROR: ${myservice} caught an interrupt"
- end_service "${myservice}"
if service_inactive "${myservice}" || [[ ${svcinactive} == 0 ]] ; then
mark_service_inactive "${myservice}"
elif [[ ${svcstarted} == 0 ]] ; then
@@ -132,7 +131,7 @@ svc_start_scheduled() {
services="${services} ${x##*/}"
done
- for x in $(trace_dependencies "${services}") ; do
+ for x in ${services} ; do
service_stopped "${x}" && start_service "${x}"
rm -f "${svcdir}/scheduled/${myservice}/${x}"
done
@@ -143,29 +142,23 @@ svc_start_scheduled() {
svc_stop() {
local x= mydep= mydeps= retval=0
local -a servicelist=()
-
- # Do not try to stop if it had already failed to do so on runlevel change
+
+ # Do not try to stop if it had already failed to do so
if is_runlevel_stop && service_failed "${myservice}" ; then
return 1
- fi
-
- if service_stopped "${myservice}" ; then
+ elif service_stopped "${myservice}" ; then
ewarn "WARNING: ${myservice} has not yet been started."
return 0
fi
-
if ! mark_service_stopping "${myservice}" ; then
- ewarn "WARNING: ${myservice} is already stopping."
- return 0
+ eerror "ERROR: ${myservice} is already stopping."
+ return 1
fi
- # Lock service starting too ...
- mark_service_starting "${myservice}"
-
+
# Ensure that we clean up if we abort for any reason
trap "svc_quit" INT QUIT TSTP
-
- begin_service "${myservice}"
-
+
+ mark_service_starting "${myservice}"
service_message "Stopping service ${myservice}"
if in_runlevel "${myservice}" "${BOOTLEVEL}" && \
@@ -202,8 +195,6 @@ svc_stop() {
done
done
- [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait
-
for x in "${service_list[@]}" ; do
# We need to test if the service has been marked stopped
# as the fifo may still be around if called by custom code
@@ -242,7 +233,6 @@ svc_stop() {
# may attempt to start it again later
if service_inactive "${myservice}" ; then
svcinactive=0
- end_service "${myservice}" 0
return 0
fi
fi
@@ -253,7 +243,9 @@ svc_stop() {
is_runlevel_stop && mark_service_failed "${myservice}"
# If we are halting the system, do it as cleanly as possible
- if [[ ${SOFTLEVEL} != "reboot" && ${SOFTLEVEL} != "shutdown" ]] ; then
+ if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then
+ mark_service_stopped "${myservice}"
+ else
if [[ ${svcinactive} == 0 ]] ; then
mark_service_inactive "${myservice}"
else
@@ -263,8 +255,6 @@ svc_stop() {
service_message "eerror" "ERROR: ${myservice} failed to stop"
else
- # If we're stopped from a daemon that sets ${IN_BACKGROUND} such as
- # wpa_monitor when we mark as inactive instead of taking the down
svcstarted=1
if service_inactive "${myservice}" ; then
svcinactive=0
@@ -274,8 +264,6 @@ svc_stop() {
service_message "Stopped service ${myservice}"
fi
- end_service "${myservice}" "${retval}"
-
# Reset the trap
svc_trap
@@ -288,14 +276,9 @@ svc_start() {
# Do not try to start if i have done so already on runlevel change
if is_runlevel_start && service_failed "${myservice}" ; then
return 1
- fi
-
- if service_started "${myservice}" ; then
+ elif service_started "${myservice}" ; then
ewarn "WARNING: ${myservice} has already been started."
return 0
- elif service_stopping "${myservice}" ; then
- eerror "ERROR: please wait for ${myservice} to stop first."
- return 1
elif service_inactive "${myservice}" ; then
if [[ ${IN_BACKGROUND} != "true" ]] ; then
ewarn "WARNING: ${myservice} has already been started."
@@ -304,42 +287,44 @@ svc_start() {
fi
if ! mark_service_starting "${myservice}" ; then
- ewarn "WARNING: ${myservice} is already starting."
- return 0
+ if service_stopping "${myservice}" ; then
+ eerror "ERROR: ${myservice} is already stopping."
+ else
+ eerror "ERROR: ${myservice} is already starting."
+ fi
+ return 1
fi
# Ensure that we clean up if we abort for any reason
trap "svc_quit" INT QUIT TSTP
-
- begin_service "${myservice}"
+
service_message "Starting service ${myservice}"
# Save the IN_BACKGROUND var as we need to clear it for starting depends
local ib_save="${IN_BACKGROUND}"
unset IN_BACKGROUND
-
- local startupservices="$(trace_dependencies $(ineed "${myservice}") \
- $(valid_iuse "${myservice}"))"
- local netservices="$(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
- $(dolisting "/etc/runlevels/${mylevel}/net.*")"
- local startupnetservices=
- # Start dependencies, if any.
- # We don't handle "after" deps here as it's the job of rc to start them.
- for x in ${startupservices} ; do
- if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] && ! is_net_up ; then
- for y in ${netservices} ; do
- y="${y##*/}"
- service_stopped "${y}" && start_service "${y}"
- done
- elif [[ ${x} != "net" ]] ; then
- if service_stopped "${x}" ; then
- start_service "${x}"
- fi
- fi
+ local startupservices="$(ineed "${myservice}") $(valid_iuse "${myservice}")"
+ local netservices=
+ for x in $(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
+ $(dolisting "/etc/runlevels/${mylevel}/net.*") ; do
+ netservices="${netservices} ${x##*/}"
done
- [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait
+ # 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
# We also wait for any services we're after to finish incase they
# have a "before" dep but we don't dep on them.
@@ -347,50 +332,35 @@ svc_start() {
startupservices="${startupservices} $(valid_iafter "${myservice}")"
fi
+ if [[ " ${startupservices} " == *" net "* ]] ; then
+ startupservices=" ${startupservices} "
+ startupservices="${startupservices/ net / ${netservices} }"
+ startupservices="${startupservices// net /}"
+ fi
+
# Wait for dependencies to finish.
for x in ${startupservices} ; do
- if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] ; then
- for y in ${netservices} ; do
- y="${y##*/}"
- # Don't wait if it's already been started
- service_started "${y}" && continue
- wait_service "${y}"
- if ! service_started "${y}" ; then
- # A 'need' dependency is critical for startup
- if ineed -t "${myservice}" "${x}" >/dev/null ; then
- if ! is_net_up ; then
- if service_inactive "${y}" ; then
- svc_schedule_start "${y}" "${myservice}"
- startinactive="${y}"
- else
- startfail="${y}"
- fi
- break
- fi
- fi
- fi
- done
- elif [[ ${x} != "net" ]] ; then
- # Don't wait if it's already been started
- service_started "${x}" && continue
- wait_service "${x}"
- if ! service_started "${x}" ; then
- # A 'need' dependacy is critical for startup
- if ineed -t "${myservice}" "${x}" >/dev/null ; then
- if service_inactive "${x}" ; then
- svc_schedule_start "${x}"
- startinactive="${x}"
- else
- startfail="${x}"
- fi
- break
+ service_started "${x}" && continue
+ wait_service "${x}"
+ if ! service_started "${x}" ; then
+ # A 'need' dependency is critical for startup
+ if ineed -t "${myservice}" "${x}" >/dev/null \
+ || net_service "${x}" && ineed -t "${myservice}" 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}" "${myservice}"
+ startinactive="${x}"
+ else
+ startfail="${x}"
fi
+ break
fi
fi
done
- if [[ ${startfail} == "yes" ]] ; then
- eerror "ERROR: Problem starting needed service ${startfail}."
+ if [[ -n ${startfail} ]] ; then
+ eerror "ERROR: Problem starting needed service ${startfail}"
eerror " ${myservice} was not started."
retval=1
elif [[ -n ${startinactive} ]] ; then
@@ -422,21 +392,15 @@ svc_start() {
if service_inactive "${myservice}" ; then
svcinactive=0
service_message "ewarn" "WARNING: ${myservice} has started but is inactive"
- end_service "${myservice}" 1
return 1
fi
fi
if [[ ${retval} != 0 ]] ; then
- # Remove link if service didn't start; but only if we're not booting
- # If we're booting, we need to continue and do our best to get the
- # system up.
- if [[ ${SOFTLEVEL} != "${BOOTLEVEL}" ]] ; then
- if [[ ${svcinactive} == 0 ]] ; then
- mark_service_inactive "${myservice}"
- else
- mark_service_stopped "${myservice}"
- fi
+ if [[ ${svcinactive} == 0 ]] ; then
+ mark_service_inactive "${myservice}"
+ else
+ mark_service_stopped "${myservice}"
fi
if [[ -z ${startinactive} ]] ; then
@@ -449,7 +413,6 @@ svc_start() {
service_message "Service ${myservice} started"
fi
- end_service "${myservice}" "${retval}"
# Reset the trap
svc_trap
@@ -561,6 +524,8 @@ for arg in $* ; do
;;
esac
done
+
+retval=0
for arg in $* ; do
case "${arg}" in
stop)
@@ -585,31 +550,26 @@ for arg in $* ; do
svc_schedule_start "${myservice}" "${x##*/}"
fi
done
+ else
+ rm -f "${svcdir}"/scheduled/*/"${myservice}"
fi
-
- exit "${retval}"
+
;;
start)
svc_start
- retval=$?
+ retval="$?"
service_started "${myservice}" && svc_start_scheduled
- exit "${retval}"
;;
needsme|ineed|usesme|iuse|broken)
trace_dependencies "-${arg}"
;;
status)
svc_status
+ retval="$?"
;;
zap)
- if [[ -e "${svcdir}/scheduled/${myservice}" ]] ; then
- rm -Rf "${svcdir}/scheduled/${myservice}"
- fi
- if ! service_stopped "${myservice}" ; then
- einfo "Manually resetting ${myservice} to stopped state."
- mark_service_stopped "${myservice}"
- fi
- end_service "${myservice}"
+ einfo "Manually resetting ${myservice} to stopped state."
+ mark_service_stopped "${myservice}"
;;
restart)
svcrestart="yes"
@@ -640,6 +600,7 @@ for arg in $* ; do
else
restart
fi
+ retval="$?"
[[ -e "${svcdir}/scheduled/${myservice}" ]] \
&& rm -Rf "${svcdir}/scheduled/${myservice}"
@@ -661,6 +622,7 @@ for arg in $* ; do
pause)
svcpause="yes"
svc_stop
+ retval="$?"
svcpause="no"
;;
--quiet|--nocolor)
@@ -671,8 +633,11 @@ for arg in $* ; do
*)
# Allow for homegrown functions
svc_homegrown ${arg}
+ retval="$?"
;;
esac
done
+exit "${retval}"
+
# vim:ts=4