From 37c17d760129be116cca67661acc947ce43be522 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 18 Dec 2006 16:27:56 +0000 Subject: [PATCH] * When runtime switching to a new configuration, stop/start/restart Upstart jobs as appropriate. I.e., if a job exists in the old but not the new configuration, stop it; if it exists in the new but not the old, start it; and most interesting, if it exists in both but its store paths differ, restart it. So the purely functional model combined cryptographic hashing allows us to precisely identify how two configurations differ from each other svn path=/nixos/trunk/; revision=7385 --- configuration/switch-to-configuration.sh | 39 ++++++++++++++++++++++-- configuration/system.nix | 9 +++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/configuration/switch-to-configuration.sh b/configuration/switch-to-configuration.sh index faf592834d9..11a5ccb5367 100644 --- a/configuration/switch-to-configuration.sh +++ b/configuration/switch-to-configuration.sh @@ -2,7 +2,7 @@ set -e export PATH=/empty -for i in @path@; do PATH=$PATH:$i/bin; done +for i in @path@; do PATH=$PATH:$i/bin:$i/sbin; done action="$1" if ! test -e /etc/NIXOS; then @@ -34,9 +34,44 @@ if test "$action" = "switch" -o "$action" = "boot"; then 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" + + # 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..." + initctl stop "$event" + fi + done + + # Activate the new configuration (i.e., update /etc, make + # accounts, and so on). echo "Activating the configuration..." @out@/activate - kill -TERM 1 # make Upstart reload its events + + # 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 + if ! test -e "$oldEvents/$event"; then + echo "starting $event..." + initctl start "$event" + elif test "$(readlink "$oldEvents/$event")" != "$(readlink "$newEvents/$event")"; then + echo "restarting $event..." + initctl stop "$event" + initctl start "$event" + else + echo "unchanged $event" + fi + done fi sync diff --git a/configuration/system.nix b/configuration/system.nix index a78708e8e4a..5a91c38e95b 100644 --- a/configuration/system.nix +++ b/configuration/system.nix @@ -242,7 +242,14 @@ rec { kernel = pkgs.kernel + "/vmlinuz"; initrd = initialRamdisk + "/initrd"; # Most of these are needed by grub-install. - path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.findutils pkgs.diffutils]; + path = [ + pkgs.coreutils + pkgs.gnused + pkgs.gnugrep + pkgs.findutils + pkgs.diffutils + pkgs.upstart # for initctl + ]; };