Author: sandervanderburg
Date: Mon Oct 18 19:47:46 2010
New Revision: 24352
URL: https://svn.nixos.org/websvn/nix/?rev=24352&sc=1
Log:
Modified the nixos-deploy-network script to use a 2PC-like approach illustrated
in the Disnix HotSWUp paper for system configurations
Modified:
nixos/trunk/modules/installer/tools/nixos-deploy-network/deploy.nix
nixos/trunk/modules/installer/tools/nixos-deploy-network/nixos-deploy-network.sh
Modified: nixos/trunk/modules/installer/tools/nixos-deploy-network/deploy.nix
==============================================================================
--- nixos/trunk/modules/installer/tools/nixos-deploy-network/deploy.nix Mon Oct
18 18:47:05 2010 (r24351)
+++ nixos/trunk/modules/installer/tools/nixos-deploy-network/deploy.nix Mon Oct
18 19:47:46 2010 (r24352)
@@ -2,33 +2,71 @@
, nixpkgs ? /etc/nixos/nixpkgs
, networkExpr
, infrastructureExpr
+, targetProperty ? "hostname"
}:
let
pkgs = import nixpkgs {};
- inherit (builtins) attrNames getAttr listToAttrs concatMapStrings;
+ inherit (builtins) attrNames getAttr listToAttrs;
+ inherit (pkgs.lib) concatMapStrings;
network = import networkExpr;
infrastructure = import infrastructureExpr;
-
- generateScript = network: infrastructure: configs:
+
+ generateRollbackSucceededPhase = network: infrastructure: configs:
concatMapStrings (configurationName:
let
infrastructureElement = getAttr configurationName infrastructure;
config = getAttr configurationName configs;
in
''
- echo "=== upgrading ${infrastructureElement.hostName} ==="
- nix-copy-closure --to ${infrastructureElement.hostName}
${config.system.build.toplevel} \
- && ssh $NIX_SSHOPTS ${infrastructureElement.hostName} nix-env -p
/nix/var/nix/profiles/system --set ${config.system.build.toplevel} \
- && ssh $NIX_SSHOPTS ${infrastructureElement.hostName}
${config.system.build.toplevel}/bin/switch-to-configuration switch \
- && { succeeded=$((succeeded + 1)); } \
- || { failed=$((failed + 1)); echo 'WARNING: upgrade of
${infrastructureElement.hostName} failed!'; }
+ if [ "$rollback" != "$succeeded" ]
+ then
+ ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement}
nix-env -p /nix/var/nix/profiles/system --rollback
+ ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement}
/nix/var/nix/profiles/bin/switch-to-configuration switch
+
+ rollback=$((rollback + 1))
+ fi
+ ''
+ ) (attrNames network)
+ ;
+
+ generateDistributionPhase = network: infrastructure: configs:
+ concatMapStrings (configurationName:
+ let
+ infrastructureElement = getAttr configurationName infrastructure;
+ config = getAttr configurationName configs;
+ in
+ ''
+ echo "=== copy system closure to ${getAttr targetProperty
infrastructureElement} ==="
+ nix-copy-closure --to ${getAttr targetProperty infrastructureElement}
${config.system.build.toplevel}
''
) (attrNames network)
;
-
+
+ generateActivationPhase = network: infrastructure: configs:
+ concatMapStrings (configurationName:
+ let
+ infrastructureElement = getAttr configurationName infrastructure;
+ config = getAttr configurationName configs;
+ in
+ ''
+ echo "=== activating system configuration on ${getAttr targetProperty
infrastructureElement} ==="
+ ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement}
nix-env -p /nix/var/nix/profiles/system --set ${config.system.build.toplevel}
||
+ (ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement}
nix-env -p /nix/var/nix/profiles/system --rollback; rollbackSucceeded)
+
+ ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement}
/nix/var/nix/profiles/bin/switch-to-configuration switch ||
+ ( ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement}
nix-env -p /nix/var/nix/profiles/system --rollback
+ ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement}
/nix/var/nix/profiles/bin/switch-to-configuration switch
+ rollbackSucceeded
+ )
+
+ succeeded=$((succeeded + 1))
+ ''
+ ) (attrNames network)
+ ;
+
evaluateMachines = network: infrastructure:
listToAttrs (map (configurationName:
let
@@ -48,13 +86,27 @@
in
pkgs.stdenv.mkDerivation {
name = "deploy-script";
- buildCommand = ''
+ buildCommand =
+ ''
ensureDir $out/bin
cat > $out/bin/deploy-systems << "EOF"
#! ${pkgs.stdenv.shell} -e
- failed=0; succeeded=0
- ${generateScript network infrastructure configs}
- echo "Upgrade of $failed machines failed, $succeeded machines succeeded.";
+
+ rollbackSucceeded()
+ {
+ rollback=0
+ ${generateRollbackSucceededPhase network infrastructure configs}
+ }
+
+ # Distribution phase
+
+ ${generateDistributionPhase network infrastructure configs}
+
+ # Activation phase
+
+ succeeded=0
+
+ ${generateActivationPhase network infrastructure configs}
EOF
chmod +x $out/bin/deploy-systems
'';
Modified:
nixos/trunk/modules/installer/tools/nixos-deploy-network/nixos-deploy-network.sh
==============================================================================
---
nixos/trunk/modules/installer/tools/nixos-deploy-network/nixos-deploy-network.sh
Mon Oct 18 18:47:05 2010 (r24351)
+++
nixos/trunk/modules/installer/tools/nixos-deploy-network/nixos-deploy-network.sh
Mon Oct 18 19:47:46 2010 (r24352)
@@ -68,6 +68,6 @@
# Deploy the network
-nix-build $NIXOS/deploy.nix --argstr networkExpr $networkExpr --argstr
infrastructureExpr $infrastructureExpr $showTraceArg
+nix-build $NIXOS/modules/installer/tools/nixos-deploy-network/deploy.nix
--argstr networkExpr $networkExpr --argstr infrastructureExpr
$infrastructureExpr $showTraceArg
./result/bin/deploy-systems
rm -f result
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits