#! @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 <&2 fi fi if test "$action" = "switch" -o "$action" = "test"; then oldEvents=$(readlink -f /etc/event.d || true) newEvents=$(readlink -f @out@/etc/event.d) echo "old: $oldEvents" echo "new: $newEvents" stopJob() { local job=$1 initctl stop "$job" while ! initctl list 2>&1 | grep -q "initctl: $job (stop)"; do echo "waiting for $job..." sleep 1 done } # Stop all services that are not in the new Upstart # configuration. for event in $(cd $oldEvents && ls); do if ! test -e "$newEvents/$event"; then echo "stopping $event..." stopJob $event fi done # Activate the new configuration (i.e., update /etc, make # accounts, and so on). echo "Activating the configuration..." @out@/activate # Make Upstart reload its events. !!! Should wait until it has # finished processing its stop events. kill -TERM 1 # Start all new services and restart all changed services. for event in $(cd $newEvents && ls); do # Hack: skip the sys-* events. if echo "$event" | grep -q "^sys-"; then continue; fi if ! test -e "$oldEvents/$event"; then echo "starting $event..." initctl start "$event" elif test "$(readlink "$oldEvents/$event")" != "$(readlink "$newEvents/$event")"; then echo "restarting $event..." stopJob $event initctl start "$event" else echo "unchanged $event" fi done fi sync