diff --git a/modules/system/activation/switch-to-configuration.sh b/modules/system/activation/switch-to-configuration.sh index 8b8ea718666..781972882fd 100644 --- a/modules/system/activation/switch-to-configuration.sh +++ b/modules/system/activation/switch-to-configuration.sh @@ -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 diff --git a/modules/system/upstart/upstart.nix b/modules/system/upstart/upstart.nix index 175c64bb88f..fa2e4fc22b7 100644 --- a/modules/system/upstart/upstart.nix +++ b/modules/system/upstart/upstart.nix @@ -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 } '';