Author: eelco Date: 2010-07-06 09:17:46 +0000 (Tue, 06 Jul 2010) New Revision: 22490
You can view the changes in this commit at: https://svn.nixos.org/viewvc/nix?rev=22490&view=rev Added: nixos/trunk/modules/config/swap.nix nixos/trunk/tests/nfs.nix Removed: nixos/trunk/modules/tasks/swap.nix Modified: nixos/trunk/ nixos/trunk/lib/make-iso9660-image.sh nixos/trunk/lib/test-driver/Machine.pm nixos/trunk/lib/test-driver/test-driver.pl nixos/trunk/modules/config/system-path.nix nixos/trunk/modules/installer/grub/grub-menu-builder.sh nixos/trunk/modules/installer/grub/grub.nix nixos/trunk/modules/module-list.nix nixos/trunk/modules/services/databases/mysql.nix nixos/trunk/modules/services/databases/postgresql.nix nixos/trunk/modules/services/hardware/udev.nix nixos/trunk/modules/services/network-filesystems/nfs-kernel.nix nixos/trunk/modules/services/networking/portmap.nix nixos/trunk/modules/services/ttys/mingetty.nix nixos/trunk/modules/services/x11/display-managers/kdm.nix nixos/trunk/modules/services/x11/xserver.nix nixos/trunk/modules/system/activation/activation-script.nix nixos/trunk/modules/system/boot/stage-2-init.sh nixos/trunk/modules/system/upstart-events/runlevel.nix nixos/trunk/modules/system/upstart-events/shutdown.nix nixos/trunk/modules/tasks/filesystems.nix nixos/trunk/modules/testing/test-instrumentation.nix nixos/trunk/modules/virtualisation/qemu-vm.nix nixos/trunk/release.nix nixos/trunk/tests/default.nix nixos/trunk/tests/installer.nix Log: * Merge the boot-order branch. The main improvement is that it uses mountall to mount filesystems and starts certain jobs (e.g., X11, console logins, databases) only after all filesystems have been mounted. If any filesystem fails to mount, an emergency shell is started to allow the user to fix the problem. Changes (first 1000 lines of the diffs): Property changes on: nixos/trunk ___________________________________________________________________ Modified: svn:mergeinfo - /nixos/branches/fix-style:13689-13861,14192-14408,14450-14826 /nixos/branches/upstart-0.6:18180-18619 /nixos/trunk:13326-15006,15032,15058,15061-15062,15074,15086,15145,15192,15204,15208,15211,15274,15312,15326,15340,15344-15346,15348,15368-15370,15391,15396-15397,15407-15408,15413,15424,15427-15428,15430,15464,15468-15469,15480,15505,15508-15509,15519,15548,15577,15580,15609,15620,15633,15656,15660-15661,15669,15695-15696,15704-15705,15779,15811,15822-15824,15831,15899,16050,16196,16200 + /nixos/branches/boot-order:22147-22489 /nixos/branches/fix-style:13689-13861,14192-14408,14450-14826 /nixos/branches/upstart-0.6:18180-18619 /nixos/trunk:13326-15006,15032,15058,15061-15062,15074,15086,15145,15192,15204,15208,15211,15274,15312,15326,15340,15344-15346,15348,15368-15370,15391,15396-15397,15407-15408,15413,15424,15427-15428,15430,15464,15468-15469,15480,15505,15508-15509,15519,15548,15577,15580,15609,15620,15633,15656,15660-15661,15669,15695-15696,15704-15705,15779,15811,15822-15824,15831,15899,16050,16196,16200 Modified: nixos/trunk/lib/make-iso9660-image.sh =================================================================== --- nixos/trunk/lib/make-iso9660-image.sh 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/lib/make-iso9660-image.sh 2010-07-06 09:17:46 UTC (rev 22490) @@ -54,7 +54,7 @@ # Also include a manifest of the closures in a format suitable for # nix-store --load-db. -if [ -n "$object"; ]; then +if [ -n "$object" ]; then printRegistration=1 perl $pathsFromGraph closure-* > nix-path-registration echo "nix-path-registration=nix-path-registration" >> pathlist fi Modified: nixos/trunk/lib/test-driver/Machine.pm =================================================================== --- nixos/trunk/lib/test-driver/Machine.pm 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/lib/test-driver/Machine.pm 2010-07-06 09:17:46 UTC (rev 22490) @@ -2,7 +2,6 @@ use strict; use threads; -use Thread::Queue; use Socket; use IO::Handle; use POSIX qw(dup2); @@ -28,8 +27,8 @@ if (!$startCommand) { # !!! merge with qemu-vm.nix. $startCommand = - "qemu-system-x86_64 -m 384 -no-kvm-irqchip " . - "-net nic,model=virtio -net user \$QEMU_OPTS "; + "qemu-system-x86_64 -m 384 " . + "-net nic,model=virtio -net user,\$QEMU_NET_OPTS \$QEMU_OPTS "; $startCommand .= "-drive file=" . Cwd::abs_path($args->{hda}) . ",if=virtio,boot=on,werror=report " if defined $args->{hda}; $startCommand .= "-cdrom $args->{cdrom} " @@ -51,7 +50,6 @@ booted => 0, pid => 0, connected => 0, - connectedQueue => Thread::Queue->new(), socket => undef, stateDir => "$tmpDir/$name", monitor => undef, @@ -101,6 +99,14 @@ bind($monitorS, sockaddr_un($monitorPath)) or die "cannot bind monitor socket: $!"; listen($monitorS, 1) or die; + # Create a Unix domain socket to which the root shell in the guest will connect. + my $shellPath = $self->{stateDir} . "/shell"; + unlink $shellPath; + my $shellS; + socket($shellS, PF_UNIX, SOCK_STREAM, 0) or die; + bind($shellS, sockaddr_un($shellPath)) or die "cannot bind shell socket: $!"; + listen($shellS, 1) or die; + # Start the VM. my $pid = fork(); die if $pid == -1; @@ -108,22 +114,21 @@ if ($pid == 0) { close $serialP; close $monitorS; + close $shellS; open NUL, "</dev/null" or die; dup2(fileno(NUL), fileno(STDIN)); dup2(fileno($serialC), fileno(STDOUT)); dup2(fileno($serialC), fileno(STDERR)); $ENV{TMPDIR} = $self->{stateDir}; - $ENV{QEMU_OPTS} = "-nographic -no-reboot -redir tcp:65535::514 -monitor unix:./monitor"; + $ENV{USE_TMPDIR} = 1; + $ENV{QEMU_OPTS} = "-nographic -no-reboot -monitor unix:./monitor -chardev socket,id=shell,path=./shell"; + $ENV{QEMU_NET_OPTS} = "guestfwd=tcp:10.0.2.6:23-chardev:shell"; $ENV{QEMU_KERNEL_PARAMS} = "hostTmpDir=$ENV{TMPDIR}"; chdir $self->{stateDir} or die; exec $self->{startCommand}; die; } - # Wait until QEMU connects to the monitor. - accept($self->{monitor}, $monitorS) or die; - $self->waitForMonitorPrompt; - # Process serial line output. close $serialC; @@ -131,17 +136,31 @@ sub processSerialOutput { my ($self, $serialP) = @_; - $/ = "\r\n"; while (<$serialP>) { chomp; + s/\r$//; print STDERR $self->name, "# $_\n"; - $self->{connectedQueue}->enqueue(1) if $_ eq "===UP==="; } - # If the child dies, wake up connect(). - $self->{connectedQueue}->enqueue(1); } - $self->log("vm running as pid $pid"); + eval { + local $SIG{CHLD} = sub { die "QEMU died prematurely\n"; }; + + # Wait until QEMU connects to the monitor. + accept($self->{monitor}, $monitorS) or die; + + # Wait until QEMU connects to the root shell socket. QEMU + # does so immediately; this doesn't mean that the root shell + # has connected yet inside the guest. + accept($self->{socket}, $shellS) or die; + $self->{socket}->autoflush(1); + }; + die "$@" if $@; + + $self->waitForMonitorPrompt; + + $self->log("QEMU running (pid $pid)"); + $self->{pid} = $pid; $self->{booted} = 1; } @@ -190,27 +209,12 @@ $self->start; - # Wait until the processQemuOutput thread signals that the machine - # is up. - retry sub { - return 1 if $self->{connectedQueue}->dequeue_nb(); - }; - - retry sub { - $self->log("trying to connect"); - my $socket = new IO::Handle; - $self->{socket} = $socket; - socket($socket, PF_UNIX, SOCK_STREAM, 0) or die; - connect($socket, sockaddr_un($self->{stateDir} . "/65535.socket")) or die; - $socket->autoflush(1); - print $socket "echo hello\n" or next; - flush $socket; - my $line = readline($socket); - chomp $line; - return 1 if $line eq "hello"; - }; - - $self->log("connected"); + local $SIG{ALRM} = sub { die "timed out waiting for the guest to connect\n"; }; + alarm 300; + readline $self->{socket} or die; + alarm 0; + + $self->log("connected to guest root shell"); $self->{connected} = 1; } @@ -294,7 +298,7 @@ } -sub mustFail { +sub fail { my ($self, $command) = @_; my ($status, $out) = $self->execute($command); die "command `$command' unexpectedly succeeded" @@ -302,6 +306,11 @@ } +sub mustFail { + fail @_; +} + + # Wait for an Upstart job to reach the "running" state. sub waitForJob { my ($self, $jobName) = @_; @@ -360,6 +369,16 @@ } +sub crash { + my ($self) = @_; + return unless $self->{booted}; + + $self->sendMonitorCommand("quit"); + + $self->waitForShutdown; +} + + # Make the machine unreachable by shutting down eth1 (the multicast # interface used to talk to the other VMs). We keep eth0 up so that # the test driver can continue to talk to the machine. Modified: nixos/trunk/lib/test-driver/test-driver.pl =================================================================== --- nixos/trunk/lib/test-driver/test-driver.pl 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/lib/test-driver/test-driver.pl 2010-07-06 09:17:46 UTC (rev 22490) @@ -74,6 +74,3 @@ runTests; - - -print STDERR "DONE\n"; Copied: nixos/trunk/modules/config/swap.nix (from rev 22489, nixos/branches/boot-order/modules/config/swap.nix) =================================================================== --- nixos/trunk/modules/config/swap.nix (rev 0) +++ nixos/trunk/modules/config/swap.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -0,0 +1,74 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +{ + + ###### interface + + options = { + + swapDevices = mkOption { + default = []; + example = [ + { device = "/dev/hda7"; } + { device = "/var/swapfile"; } + { label = "bigswap"; } + ]; + description = '' + The swap devices and swap files. These must have been + initialised using <command>mkswap</command>. Each element + should be an attribute set specifying either the path of the + swap device or file (<literal>device</literal>) or the label + of the swap device (<literal>label</literal>, see + <command>mkswap -L</command>). Using a label is + recommended. + ''; + + type = types.list types.optionSet; + + options = {config, options, ...}: { + + options = { + + device = mkOption { + example = "/dev/sda3"; + type = types.string; + description = "Path of the device."; + }; + + label = mkOption { + example = "swap"; + type = types.string; + description = '' + Label of the device. Can be used instead of <varname>device</varname>. + ''; + }; + + cipher = mkOption { + default = false; + example = true; + type = types.bool; + description = '' + Encrypt the swap device to protect swapped data. This option + does not work with labels. + ''; + }; + + }; + + config = { + device = + if options.label.isDefined then + "/dev/disk/by-label/${config.label}" + else + mkNotdef; + }; + + }; + + }; + + }; + +} Modified: nixos/trunk/modules/config/system-path.nix =================================================================== --- nixos/trunk/modules/config/system-path.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/config/system-path.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -22,7 +22,6 @@ pkgs.cpio pkgs.curl pkgs.diffutils - pkgs.e2fsprogs pkgs.eject # HAL depends on it anyway pkgs.findutils pkgs.gawk @@ -44,7 +43,6 @@ pkgs.pciutils pkgs.perl pkgs.procps - pkgs.reiserfsprogs pkgs.rsync pkgs.seccure pkgs.strace Modified: nixos/trunk/modules/installer/grub/grub-menu-builder.sh =================================================================== --- nixos/trunk/modules/installer/grub/grub-menu-builder.sh 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/installer/grub/grub-menu-builder.sh 2010-07-06 09:17:46 UTC (rev 22490) @@ -216,6 +216,10 @@ EOF` +cat >> $tmp <<EOF +...@extraconfig@ +EOF + if test -n "@extraEntriesBeforeNixOS@"; then echo "$extraEntries" >> $tmp fi Modified: nixos/trunk/modules/installer/grub/grub.nix =================================================================== --- nixos/trunk/modules/installer/grub/grub.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/installer/grub/grub.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -12,7 +12,8 @@ inherit grub; inherit (pkgs) bash; path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; - inherit (config.boot.loader.grub) copyKernels extraEntries extraEntriesBeforeNixOS + inherit (config.boot.loader.grub) copyKernels + extraConfig extraEntries extraEntriesBeforeNixOS splashImage configurationLimit version default timeout; }; @@ -67,6 +68,15 @@ ''; }; + extraConfig = mkOption { + default = ""; + example = "serial; terminal_output.serial"; + description = '' + Additional GRUB commands inserted in the configuration file + just before the menu entries. + ''; + }; + extraEntries = mkOption { default = ""; example = '' Modified: nixos/trunk/modules/module-list.nix =================================================================== --- nixos/trunk/modules/module-list.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/module-list.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -7,6 +7,7 @@ ./config/no-x-libs.nix ./config/nsswitch.nix ./config/power-management.nix + ./config/swap.nix ./config/system-path.nix ./config/timezone.nix ./config/unix-odbc-drivers.nix @@ -152,7 +153,6 @@ ./tasks/kbd.nix ./tasks/lvm.nix ./tasks/network-interfaces.nix - ./tasks/swap.nix ./tasks/swraid.nix ./tasks/tty-backgrounds.nix ] Modified: nixos/trunk/modules/services/databases/mysql.nix =================================================================== --- nixos/trunk/modules/services/databases/mysql.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/services/databases/mysql.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -100,7 +100,7 @@ jobs.mysql = { description = "MySQL server"; - startOn = "started network-interfaces"; + startOn = "filesystem"; preStart = '' Modified: nixos/trunk/modules/services/databases/postgresql.nix =================================================================== --- nixos/trunk/modules/services/databases/postgresql.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/services/databases/postgresql.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -28,9 +28,6 @@ postgresql = postgresqlAndPlugins pkgs.postgresql; - startDependency = if config.services.gw6c.enable then - "gw6c" else "network-interfaces"; - run = "${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} postgres"; flags = optional cfg.enableTCPIP "-i"; @@ -120,10 +117,10 @@ default = []; example = "pkgs.postgis"; # of course don't use a string here! description = '' - When this list contains elemnts a new store path is created. - Postgresql and the elments are symlinked into it. Then pg_config, + When this list contains elements a new store path is created. + PostgreSQL and the elments are symlinked into it. Then pg_config, postgres and pc_ctl are copied to make them use the new - $out/lib directory as pkglibdir. This make it possible to use postgis + $out/lib directory as pkglibdir. This makes it possible to use postgis without patching the .sql files which reference $libdir/postgis-1.5. ''; # Note: the duplication of executables is about 4MB size. @@ -160,7 +157,7 @@ jobs.postgresql = { description = "PostgreSQL server"; - startOn = "started ${startDependency}"; + startOn = "filesystem"; environment = { TZ = config.time.timeZone; Modified: nixos/trunk/modules/services/hardware/udev.nix =================================================================== --- nixos/trunk/modules/services/hardware/udev.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/services/hardware/udev.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -185,8 +185,14 @@ daemonType = "fork"; exec = "${udev}/sbin/udevd --daemon"; + }; - postStart = + jobs.udevtrigger = + { startOn = "started udev"; + + task = true; + + script = '' # Let udev create device nodes for all modules that have already # been loaded into the kernel (or for which support is built into @@ -200,9 +206,8 @@ initctl emit -n new-devices ''; - }; - + }; } Modified: nixos/trunk/modules/services/network-filesystems/nfs-kernel.nix =================================================================== --- nixos/trunk/modules/services/network-filesystems/nfs-kernel.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/services/network-filesystems/nfs-kernel.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -8,6 +8,8 @@ cfg = config.services.nfsKernel; + exports = pkgs.writeText "exports" cfg.server.exports; + in { @@ -19,7 +21,7 @@ services.nfsKernel = { client.enable = mkOption { - default = false; + default = any (fs: fs.fsType == "nfs" || fs.fsType == "nfs4") config.fileSystems; description = '' Whether to enable the kernel's NFS client daemons. ''; @@ -82,7 +84,7 @@ }); environment.etc = mkIf cfg.server.enable (singleton - { source = pkgs.writeText "exports" cfg.server.exports; + { source = exports; target = "exports"; }); @@ -100,19 +102,23 @@ '' export PATH=${pkgs.nfsUtils}/sbin:$PATH mkdir -p /var/lib/nfs + ${config.system.sbin.modprobe}/sbin/modprobe nfsd || true + ${pkgs.sysvtools}/bin/mountpoint -q /proc/fs/nfsd \ + || ${config.system.sbin.mount}/bin/mount -t nfsd none /proc/fs/nfsd + ${optionalString cfg.server.createMountPoints '' # create export directories: # skip comments, take first col which may either be a quoted # "foo bar" or just foo (-> man export) - sed '/^#.*/d;s/^"\([^"]*\)".*/\1/;t;s/[ ].*//' ${cfg.server.exports} \ + sed '/^#.*/d;s/^"\([^"]*\)".*/\1/;t;s/[ ].*//' ${exports} \ | xargs -d '\n' mkdir -p '' } - # exports file is ${cfg.server.exports} + # exports file is ${exports} # keep this comment so that this job is restarted whenever exports changes! exportfs -ra ''; @@ -128,7 +134,9 @@ startOn = "started nfs-kernel-exports and started portmap"; stopOn = "stopping nfs-kernel-exports"; - exec = "${pkgs.nfsUtils}/sbin/rpc.nfsd ${if cfg.server.hostName != null then "-H ${cfg.server.hostName}" else ""} ${builtins.toString cfg.server.nproc}"; + preStart = "${pkgs.nfsUtils}/sbin/rpc.nfsd ${if cfg.server.hostName != null then "-H ${cfg.server.hostName}" else ""} ${builtins.toString cfg.server.nproc}"; + + postStop = "${pkgs.nfsUtils}/sbin/rpc.nfsd 0"; }; } @@ -138,10 +146,12 @@ description = "Kernel NFS server - mount daemon"; - startOn = "started nfs-kernel-nfsd and started portmap"; - stopOn = "stopping nfs-kernel-exports"; + startOn = "starting nfs-kernel-nfsd and started portmap"; + stopOn = "stopped nfs-kernel-nfsd"; - exec = "${pkgs.nfsUtils}/sbin/rpc.mountd -F -f /etc/exports"; + daemonType = "fork"; + + exec = "${pkgs.nfsUtils}/sbin/rpc.mountd -f /etc/exports"; }; } @@ -151,16 +161,35 @@ description = "Kernel NFS server - Network Status Monitor"; - startOn = "${if cfg.server.enable then "started nfs-kernel-nfsd and " else ""} started portmap"; - stopOn = "stopping nfs-kernel-exports"; + startOn = "${if cfg.server.enable then "starting nfs-kernel-nfsd and " else ""} started portmap"; + stopOn = "never"; preStart = '' mkdir -p /var/lib/nfs + mkdir -p /var/lib/nfs/sm + mkdir -p /var/lib/nfs/sm.bak ''; - exec = "${pkgs.nfsUtils}/sbin/rpc.statd -F"; + daemonType = "fork"; + + exec = "${pkgs.nfsUtils}/sbin/rpc.statd --no-notify"; }; + } + + // optionalAttrs (cfg.client.enable || cfg.server.enable) + { nfs_kernel_sm_notify = + { name = "nfs-kernel-sm-notify"; + + description = "Kernel NFS server - Reboot notification"; + + startOn = "started nfs-kernel-statd" + + (if cfg.client.enable then " and starting mountall" else ""); + + task = true; + + exec = "${pkgs.nfsUtils}/sbin/sm-notify -d"; + }; }; }; Modified: nixos/trunk/modules/services/networking/portmap.nix =================================================================== --- nixos/trunk/modules/services/networking/portmap.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/services/networking/portmap.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -54,7 +54,7 @@ users.extraUsers = singleton { name = "portmap"; inherit uid; - description = "portmap daemon user"; + description = "Portmap daemon user"; home = "/var/empty"; }; @@ -66,14 +66,16 @@ jobs.portmap = { description = "ONC RPC portmap"; - startOn = "ip-up"; + startOn = "started network-interfaces"; + stopOn = "never"; + daemonType = "fork"; + exec = '' - ${portmap}/sbin/portmap -f \ - ${if config.services.portmap.chroot == "" - then "" - else "-t \"${config.services.portmap.chroot}\""} \ + ${portmap}/sbin/portmap \ + ${optionalString (config.services.portmap.chroot != "") + "-t '${config.services.portmap.chroot}'"} \ ${if config.services.portmap.verbose then "-v" else ""} ''; }; Modified: nixos/trunk/modules/services/ttys/mingetty.nix =================================================================== --- nixos/trunk/modules/services/ttys/mingetty.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/services/ttys/mingetty.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -55,7 +55,7 @@ # Generate a separate job for each tty. jobs = listToAttrs (map (tty: nameValuePair tty { - startOn = "started udev"; + startOn = "started udev and filesystem"; exec = "${pkgs.mingetty}/sbin/mingetty --loginprog=${pkgs.shadow}/bin/login --noclear ${tty}"; Modified: nixos/trunk/modules/services/x11/display-managers/kdm.nix =================================================================== --- nixos/trunk/modules/services/x11/display-managers/kdm.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/services/x11/display-managers/kdm.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -94,7 +94,9 @@ config = mkIf cfg.enable { services.xserver.displayManager.job = - { execCmd = "PATH=${pkgs.grub}/sbin:$PATH exec ${kdebase_workspace}/bin/kdm -config ${kdmrc} -nodaemon"; + { execCmd = + (optionalString (config.system.boot.loader.id == "grub") "PATH=${config.system.build.grub}/sbin:$PATH ") + + "exec ${kdebase_workspace}/bin/kdm -config ${kdmrc} -nodaemon"; logsXsession = true; }; Modified: nixos/trunk/modules/services/x11/xserver.nix =================================================================== --- nixos/trunk/modules/services/x11/xserver.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/services/x11/xserver.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -408,7 +408,7 @@ optional (elem "virtualbox" driverNames) kernelPackages.virtualboxGuestAdditions; jobs.xserver = - { startOn = if cfg.autorun then "started udev and started hal" else ""; + { startOn = if cfg.autorun then "filesystem and stopped udevtrigger and started hal" else ""; environment = { FONTCONFIG_FILE = "/etc/fonts/fonts.conf"; # !!! cleanup Modified: nixos/trunk/modules/system/activation/activation-script.nix =================================================================== --- nixos/trunk/modules/system/activation/activation-script.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/system/activation/activation-script.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -75,7 +75,6 @@ var = fullDepEntry '' # Various log/runtime directories. - mkdir -m 0755 -p /var/run touch /var/run/utmp # must exist chgrp ${toString config.ids.gids.utmp} /var/run/utmp @@ -84,16 +83,6 @@ mkdir -m 0755 -p /var/run/nix/current-load # for distributed builds mkdir -m 0700 -p /var/run/nix/remote-stores - # Use a tmpfs for /var/run/nscd to ensure that / or /var can be - # unmounted or at least remounted read-only during shutdown. - # (Upstart 0.6 apparently uses nscd to do some name lookups, - # resulting in it holding some mmap mapping to deleted files in - # /var/run/nscd.) - if [ ! -e /var/run/nscd ]; then - mkdir -p /var/run/nscd - ${pkgs.utillinux}/bin/mount -t tmpfs -o "mode=755" none /var/run/nscd - fi - mkdir -m 0755 -p /var/log mkdir -m 0755 -p /var/log/upstart Modified: nixos/trunk/modules/system/boot/stage-2-init.sh =================================================================== --- nixos/trunk/modules/system/boot/stage-2-init.sh 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/system/boot/stage-2-init.sh 2010-07-06 09:17:46 UTC (rev 22490) @@ -109,6 +109,16 @@ rm -rf /nix/var/nix/chroots # recreated in activate-configuration.sh +# Use a tmpfs for /var/run to ensure that / or /var can be unmounted +# or at least remounted read-only during shutdown. (Upstart 0.6 +# apparently uses nscd to do some name lookups, resulting in it +# holding some mmap mapping to deleted files in /var/run/nscd. +# Similarly, portmap and statd have open files in /var/run and are +# needed during shutdown to unmount NFS volumes.) +mkdir -m 0755 -p /var/run +mount -t tmpfs -o "mode=755" none /var/run + + # Clear the resume device. if test -n "$resumeDevice"; then mkswap "$resumeDevice" || echo 'Failed to clear saved image.' @@ -140,9 +150,11 @@ # Run any user-specified commands. @shell@ @postBootCommands@ + # For debugging Upstart. #...@shell@ --login < /dev/console > /dev/console 2>&1 & + # Start Upstart's init. echo "starting Upstart..." PATH=/var/run/current-system/upstart/sbin exec init Modified: nixos/trunk/modules/system/upstart-events/runlevel.nix =================================================================== --- nixos/trunk/modules/system/upstart-events/runlevel.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/system/upstart-events/runlevel.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -4,6 +4,15 @@ { + # After booting, go to runlevel 2. (NixOS doesn't really use + # runlevels, but this keeps wtmp happy.) + jobs.boot = + { name = "boot"; + startOn = "startup"; + task = true; + script = "telinit 2"; + }; + jobs.runlevel = { name = "runlevel"; Modified: nixos/trunk/modules/system/upstart-events/shutdown.nix =================================================================== --- nixos/trunk/modules/system/upstart-events/shutdown.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/system/upstart-events/shutdown.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -37,14 +37,19 @@ sync - # Kill all remaining processes except init and this one. + # Kill all remaining processes except init, this one and any + # Upstart jobs that don't stop on the "starting shutdown" + # event, as these are necessary to complete the shutdown. + omittedPids=$(initctl list | sed -e 's/.*process \([0-9]\+\)/-o \1/;t;d') + #echo "saved PIDs: $omittedPids" + echo "sending the TERM signal to all processes..." - kill -TERM -1 + ${pkgs.sysvtools}/bin/killall5 -15 $job $omittedPids sleep 1 # wait briefly echo "sending the KILL signal to all processes..." - kill -KILL -1 + ${pkgs.sysvtools}/bin/killall5 -9 $job $omittedPids # If maintenance mode is requested, start a root shell, and @@ -58,38 +63,37 @@ initctl emit -n startup exit 0 fi - - + + + # Write a shutdown record to wtmp while /var/log is still writable. + reboot --wtmp-only + + # Set the hardware clock to the system time. echo "setting the hardware clock..." hwclock --systohc --utc - - - # Unmount helper functions. - getMountPoints() { - cat /proc/mounts \ - | grep -v '^rootfs' \ - | sed 's|^[^ ]\+ \+\([^ ]\+\).*|\1|' \ - | grep -v '/proc\|/sys\|/dev' - } - - getDevice() { - local mountPoint=$1 - cat /proc/mounts \ - | grep -v '^rootfs' \ - | grep "^[^ ]\+ \+$mountPoint \+" \ - | sed 's|^\([^ ]\+\).*|\1|' - } - + + + # Stop all swap devices. + swapoff -a + + # Unmount file systems. We repeat this until no more file systems # can be unmounted. This is to handle loopback devices, file # systems mounted on other file systems and so on. tryAgain=1 while test -n "$tryAgain"; do tryAgain= - - for mp in $(getMountPoints); do - device=$(getDevice $mp) + failed= # list of mount points that couldn't be unmounted/remounted + + cp /proc/mounts /dev/.mounts # don't read /proc/mounts while it's changing + exec 4< /dev/.mounts + while read -u 4 device mp fstype options rest; do + # Skip various special filesystems. Non-existent + # mount points are typically tmpfs/aufs mounts from + # the initrd. + if [ "$mp" = /proc -o "$mp" = /sys -o "$mp" = /dev -o "$device" = "rootfs" -o "$mp" = /var/run -o ! -e "$mp" ]; then continue; fi + echo "unmounting $mp..." # We need to remount,ro before attempting any @@ -99,27 +103,31 @@ # `-i' is to workaround a bug in mount.cifs (it # doesn't recognise the `remount' option, and # instead mounts the FS again). - mount -n -i -o remount,ro "$mp" + success= + if mount -t "$fstype" -n -i -o remount,ro "device" "$mp"; then success=1; fi # Note: don't use `umount -f'; it's very buggy. # (For instance, when applied to a bind-mount it # unmounts the target of the bind-mount.) !!! But # we should use `-f' for NFS. - if umount -n "$mp"; then - if test "$mp" != /; then tryAgain=1; fi + if [ "$mp" != / -a "$mp" != /nix/store ]; then + if umount -n "$mp"; then success=1; tryAgain=1; fi fi - - # Hack: work around a bug in mount (mount -o remount on a - # loop device forgets the loop=/dev/loopN entry in - # /etc/mtab). - if echo "$device" | grep -q '/dev/loop'; then - echo "removing loop device $device..." - losetup -d "$device" - fi + + if [ -z "$success" ]; then failed="$failed $mp"; fi done done - - + + + # Warn about filesystems that could not be unmounted or + # remounted read-only. + if [ -n "$failed" ]; then + echo "[1;31mwarning:[0m the following filesystems could not be unmounted:" + for mp in $failed; do echo " $mp"; done + sleep 5 + fi + + # Final sync. sync Modified: nixos/trunk/modules/tasks/filesystems.nix =================================================================== --- nixos/trunk/modules/tasks/filesystems.nix 2010-07-06 09:01:15 UTC (rev 22489) +++ nixos/trunk/modules/tasks/filesystems.nix 2010-07-06 09:17:46 UTC (rev 22490) @@ -4,104 +4,9 @@ let - fileSystems = config.fileSystems; - mount = config.system.sbin.mount; + # Packages that provide fsck backends. + fsPackages = [ pkgs.e2fsprogs pkgs.reiserfsprogs ]; - task = - '' - PATH=${pkgs.e2fsprogs}/sbin:${pkgs.utillinuxng}/sbin:$PATH - - newDevices=1 - - # If we mount any file system, we repeat this loop, because new - # mount opportunities may have become available (such as images - # for loopback mounts). - - while test -n "$newDevices"; do - newDevices= - - ${flip concatMapStrings fileSystems (fs: '' - for dummy in x; do # make `continue' work - mountPoint='${fs.mountPoint}' - device='${if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}"}' - fsType='${fs.fsType}' - - # A device is a pseudo-device (i.e. not an actual device - # node) if it's not an absolute path (e.g. an NFS server - # such as machine:/path), if it starts with // (a CIFS FS), - # a known pseudo filesystem (such as tmpfs), or the device - # is a directory (e.g. a bind mount). - isPseudo= - test "''${device:0:1}" != / -o "''${device:0:2}" = // -o "$fsType" = "tmpfs" \ - -o -d "$device" && isPseudo=1 - - if ! test -n "$isPseudo" -o -e "$device"; then - echo "skipping $device, doesn't exist (yet)" - continue - fi - - # !!! quick hack: if the mount point is already mounted, try - # a remount to change the options but nothing else. - if cat /proc/mounts | grep -F -q " $mountPoint "; then - if test "''${device:0:2}" != //; then - echo "remounting $device on $mountPoint" - ${mount}/bin/mount -t "$fsType" \ - -o remount,"${fs.options}" \ - "$device" "$mountPoint" || true - fi - continue - fi - - # If $device is already mounted somewhere else, unmount it first. - # !!! Note: we use /etc/mtab, not /proc/mounts, because mtab - # contains more accurate info when using loop devices. - - if test -z "$isPseudo"; then - - device=$(readlink -f "$device") - - prevMountPoint=$( - cat /etc/mtab \ - | grep "^$device " \ - | sed 's|^[^ ]\+ \+\([^ ]\+\).*|\1|' \ - ) - - if test "$prevMountPoint" = "$mountPoint"; then - echo "remounting $device on $mountPoint" - ${mount}/bin/mount -t "$fsType" \ - -o remount,"${fs.options}" \ - "$device" "$mountPoint" || true - continue - fi - - if test -n "$prevMountPoint"; then - echo "unmount $device from $prevMountPoint" - ${mount}/bin/umount "$prevMountPoint" || true - fi - - fi - - echo "mounting $device on $mountPoint" - - # !!! should do something with the result; also prevent repeated fscks. - if test -z "$isPseudo"; then - fsck -a "$device" || true - fi - - ${optionalString fs.autocreate - '' - mkdir -p "$mountPoint" - '' - } - - if ${mount}/bin/mount -t "$fsType" -o "${fs.options}" "$device" "$mountPoint"; then - newDevices=1 - fi (599 diff lines omitted) _______________________________________________ nix-commits mailing list [email protected] http://mail.cs.uu.nl/mailman/listinfo/nix-commits
