summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-17 13:14:42 -0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-17 13:14:42 -0400
commita44e57519627df094657f73c9e475aead2761919 (patch)
treeaf24ede5e9006b9e72dc71581e006368d48ed627
parent7d958dcdd109f7b9bf1fd0eb335ac2ab3b116fb0 (diff)
downloadnixlib-a44e57519627df094657f73c9e475aead2761919.tar
nixlib-a44e57519627df094657f73c9e475aead2761919.tar.gz
nixlib-a44e57519627df094657f73c9e475aead2761919.tar.bz2
nixlib-a44e57519627df094657f73c9e475aead2761919.tar.lz
nixlib-a44e57519627df094657f73c9e475aead2761919.tar.xz
nixlib-a44e57519627df094657f73c9e475aead2761919.tar.zst
nixlib-a44e57519627df094657f73c9e475aead2761919.zip
switch-to-configuration: Respect the ‘restartIfChanged’ attribute
-rw-r--r--modules/services/x11/xserver.nix2
-rw-r--r--modules/system/activation/switch-to-configuration.pl31
-rw-r--r--modules/system/boot/systemd-unit-options.nix9
-rw-r--r--modules/system/boot/systemd.nix1
-rw-r--r--modules/system/upstart/upstart.nix13
5 files changed, 37 insertions, 19 deletions
diff --git a/modules/services/x11/xserver.nix b/modules/services/x11/xserver.nix
index 5d795e5d57dc..5b9cb74169e0 100644
--- a/modules/services/x11/xserver.nix
+++ b/modules/services/x11/xserver.nix
@@ -383,7 +383,7 @@ in
       { wantedBy = [ "graphical.target" ];
         after = [ "systemd-udev-settle.service" ];
 
-        #restartIfChanged = false;
+        restartIfChanged = false;
 
         environment =
           { FONTCONFIG_FILE = "/etc/fonts/fonts.conf"; # !!! cleanup
diff --git a/modules/system/activation/switch-to-configuration.pl b/modules/system/activation/switch-to-configuration.pl
index df4c440b97a9..a4ca287b420f 100644
--- a/modules/system/activation/switch-to-configuration.pl
+++ b/modules/system/activation/switch-to-configuration.pl
@@ -75,12 +75,23 @@ sub parseFstab {
     return %res;
 }
 
+sub parseUnit {
+    my ($filename) = @_;
+    my $info = {};
+    foreach my $line (read_file($filename)) {
+        # FIXME: not quite correct.
+        $line =~ /^([^=]+)=(.*)$/ or next;
+        $info->{$1} = $2;
+    }
+    return $info;
+}
+
 # Forget about previously failed services.
 system("@systemd@/bin/systemctl", "reset-failed");
 
 # Stop all services that no longer exist or have changed in the new
 # configuration.
-my @unitsToStop;
+my (@unitsToStop, @unitsToSkip);
 my $activePrev = getActiveUnits;
 while (my ($unit, $state) = each %{$activePrev}) {
     my $baseUnit = $unit;
@@ -102,11 +113,16 @@ while (my ($unit, $state) = each %{$activePrev}) {
             } elsif ($unit =~ /\.socket$/ || $unit =~ /\.path$/) {
                 # FIXME: do something?
             } else {
-                # Record that this unit needs to be started below.  We
-                # write this to a file to ensure that the service gets
-                # restarted if we're interrupted.
-                write_file($restartListFile, { append => 1 }, "$unit\n");
-                push @unitsToStop, $unit;
+                my $unitInfo = parseUnit($newUnitFile);
+                if ($unitInfo->{'X-RestartIfChanged'} eq "false") {
+                    push @unitsToSkip, $unit;
+                } else {
+                    # Record that this unit needs to be started below.  We
+                    # write this to a file to ensure that the service gets
+                    # restarted if we're interrupted.
+                    write_file($restartListFile, { append => 1 }, "$unit\n");
+                    push @unitsToStop, $unit;
+                }
             }
         }
     }
@@ -159,6 +175,9 @@ if (scalar @unitsToStop > 0) {
     system("@systemd@/bin/systemctl", "stop", "--", @unitsToStop); # FIXME: ignore errors?
 }
 
+print STDERR "NOT restarting the following units: ", join(", ", sort(@unitsToSkip)), "\n"
+    if scalar @unitsToSkip > 0;
+
 # Activate the new configuration (i.e., update /etc, make accounts,
 # and so on).
 my $res = 0;
diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix
index 9aa9b2b4f3ba..f56ee4fc0d34 100644
--- a/modules/system/boot/systemd-unit-options.nix
+++ b/modules/system/boot/systemd-unit-options.nix
@@ -115,6 +115,15 @@ with pkgs.lib;
       '';
     };
 
+    restartIfChanged = mkOption {
+      type = types.bool;
+      default = true;
+      description = ''
+        Whether the service should be restarted during a NixOS
+        configuration switch if its definition has changed.
+      '';
+    };
+
   };
 
 }
\ No newline at end of file
diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix
index 992981f0a36e..def5a8bc580d 100644
--- a/modules/system/boot/systemd.nix
+++ b/modules/system/boot/systemd.nix
@@ -199,6 +199,7 @@ let
           [Service]
           Environment=PATH=${def.path}
           ${concatMapStrings (n: "Environment=${n}=${getAttr n def.environment}\n") (attrNames def.environment)}
+          ${optionalString (!def.restartIfChanged) "X-RestartIfChanged=false"}
 
           ${optionalString (def.preStart != "") ''
             ExecStartPre=${makeJobScript "${name}-prestart.sh" ''
diff --git a/modules/system/upstart/upstart.nix b/modules/system/upstart/upstart.nix
index 577efe170659..7a498b85439c 100644
--- a/modules/system/upstart/upstart.nix
+++ b/modules/system/upstart/upstart.nix
@@ -54,7 +54,7 @@ let
         '';
     in {
 
-      inherit (job) description requires wants before partOf environment path;
+      inherit (job) description requires wants before partOf environment path restartIfChanged;
 
       after =
         (if job.startOn == "stopped udevtrigger" then [ "systemd-udev-settle.service" ] else
@@ -185,15 +185,6 @@ let
       '';
     };
 
-    restartIfChanged = mkOption {
-      type = types.bool;
-      default = true;
-      description = ''
-        Whether the job should be restarted if it has changed after a
-        NixOS configuration switch.
-      '';
-    };
-
     task = mkOption {
       type = types.bool;
       default = false;
@@ -302,8 +293,6 @@ in
 
   config = {
 
-    system.build.upstart = "/no-upstart";
-
     boot.systemd.services =
       flip mapAttrs' config.jobs (name: job:
         nameValuePair "${job.name}.service" job.unit);