* Handle jobs that fail while a post-start script is waiting for them.

svn path=/nixos/trunk/; revision=33269
This commit is contained in:
Eelco Dolstra 2012-03-19 18:07:05 +00:00
parent 31c93522d5
commit fcc2e985a2
2 changed files with 20 additions and 3 deletions

View file

@ -102,6 +102,17 @@ initctl emit config-changed
declare -A tasks=(@tasks@)
declare -A noRestartIfChanged=(@noRestartIfChanged@)
start_() {
local job="$1"
if start --quiet "$job"; then
# Handle services that cancel themselves.
if ! [ -n "${tasks[$job]}" ]; then
local status=$(status "$job")
[[ "$status" =~ start/running ]] || echo "job $job failed to start!"
fi
fi
}
# Restart all running jobs that have changed. (Here "running" means
# all jobs that don't have a "stop" goal.) We use the symlinks in
# /var/run/upstart-jobs (created by each job's pre-start script) to
@ -118,7 +129,7 @@ for job in @jobs@; do
# Note: can't use "restart" here, since that only restarts the
# job's main process.
stop --quiet "$job" || true
start --quiet "$job" || true
start_ "$job" || true
done
# Start all jobs that are not running but should be. The "should be"
@ -141,7 +152,7 @@ for job in @jobs@; do
else
if ! grep -q "^start on" "$jobsDir/$job.conf"; then continue; fi
echo "starting service $job..."
start --quiet "$job" || true
start_ "$job" || true
fi
done

View file

@ -175,10 +175,16 @@ let
# Check whether the current job has been stopped. Used in
# post-start jobs to determine if they should continue.
stop_check() {
if [[ "$(status)" =~ stop/ ]]; then
local status="$(status)"
if [[ "$status" =~ stop/ ]]; then
echo "job asked to stop!"
return 1
fi
if [[ "$status" =~ respawn/ ]]; then
echo "job respawning unexpectedly!"
stop
return 1
fi
return 0
}
'';