#! @shell@ set -e export PATH=/empty for i in @path@; do PATH=$PATH:$i/bin:$i/sbin; done action="$1" if ! test -e /etc/NIXOS; then echo "This is not a NixOS installation (/etc/NIXOS) is missing!" exit 1 fi if test -z "$action"; then cat < /dev/null || echo 0) newVersion=$(cat @out@/upstart-interface-version 2> /dev/null || echo 0) if test "$oldVersion" -ne "$newVersion"; then cat <&2 || true } # 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 # determine if a job has changed. for job in @jobs@; do status=$(status "$job") if ! [[ "$status" =~ start/ ]]; then continue; fi if [ "$(readlink -f "$jobsDir/$job.conf")" = "$(readlink -f "/var/run/upstart-jobs/$job")" ]; then continue; fi if [ -n "${noRestartIfChanged[$job]}" ]; then log "not restarting changed service ‘$job’" continue fi log "restarting changed service ‘$job’..." # Note: can't use "restart" here, since that only restarts the # job's main process. stop --quiet "$job" || true start_ "$job" || true done # Start all jobs that are not running but should be. The "should be" # criterion is tricky: the intended semantics is that we end up with # the same jobs as after a reboot. If it's a task, start it if it # differs from the previous instance of the same task; if it wasn't # previously run, don't run it. If it's a service, only start it if # it has a "start on" condition. for job in @jobs@; do status=$(status "$job") if ! [[ "$status" =~ stop/ ]]; then continue; fi if [ -n "${tasks[$job]}" ]; then if [ ! -e "/var/run/upstart-jobs/$job" -o \ "$(readlink -f "$jobsDir/$job.conf")" = "$(readlink -f "/var/run/upstart-jobs/$job")" ]; then continue; fi if [ -n "${noRestartIfChanged[$job]}" ]; then continue; fi log "starting task ‘$job’..." start --quiet "$job" || true else if ! grep -q "^start on" "$jobsDir/$job.conf"; then continue; fi log "starting service ‘$job’..." start_ "$job" || true fi done # Signal dbus to reload its configuration. dbusPid=$(initctl status dbus 2> /dev/null | sed -e 's/.*process \([0-9]\+\)/\1/;t;d') [ -n "$dbusPid" ] && kill -HUP "$dbusPid"