* Make the script to start Samba available to the VM stuff in NixOS.

* Use socat's "exec" and "nofork" options to reduce the number of
  processes.  Also, if smbd exits abnormally, exit from the smbd
  restart loop.

svn path=/nixpkgs/trunk/; revision=22279
This commit is contained in:
Eelco Dolstra 2010-06-15 16:13:10 +00:00
parent 9991b4f4c6
commit 1626db66f5

View File

@ -211,9 +211,11 @@ rec {
qemuCommandLinux = '' qemuCommandLinux = ''
qemu-system-x86_64 \ ${kvm}/bin/qemu-system-x86_64 \
-nographic -no-reboot \ -nographic -no-reboot \
-net nic,model=virtio -chardev socket,id=samba,path=./samba -net user,guestfwd=tcp:10.0.2.4:139-chardev:samba \ -net nic,model=virtio \
-chardev socket,id=samba,path=./samba \
-net user,guestfwd=tcp:10.0.2.4:139-chardev:samba \
-drive file=$diskImage,if=virtio,boot=on,cache=writeback,werror=report \ -drive file=$diskImage,if=virtio,boot=on,cache=writeback,werror=report \
-kernel ${kernel}/bzImage \ -kernel ${kernel}/bzImage \
-initrd ${initrd}/initrd \ -initrd ${initrd}/initrd \
@ -222,16 +224,10 @@ rec {
''; '';
vmRunCommand = qemuCommand: writeText "vm-run" '' startSamba =
export > saved-env let sambaScript = writeScript "run-smbd" "while ${samba}/sbin/smbd -s $TMPDIR/smb.conf; do true; done"; in
''
PATH=${coreutils}/bin:${kvm}/bin cat > $TMPDIR/smb.conf <<SMB
diskImage=''${diskImage:-/dev/null}
eval "$preVM"
cat > smb.conf <<EOF
[global] [global]
private dir = $TMPDIR private dir = $TMPDIR
smb ports = 0 smb ports = 0
@ -245,7 +241,21 @@ rec {
path = / path = /
read only = no read only = no
guest ok = yes guest ok = yes
EOF SMB
${socat}/bin/socat unix-listen:./samba exec:'/bin/sh -c ${sambaScript}',nofork > /dev/null 2>&1 &
while [ ! -e ./samba ]; do sleep 0.1; done # ugly
'';
vmRunCommand = qemuCommand: writeText "vm-run" ''
export > saved-env
PATH=${coreutils}/bin
diskImage=''${diskImage:-/dev/null}
eval "$preVM"
# Write the command to start the VM to a file so that the user can # Write the command to start the VM to a file so that the user can
# debug inside the VM if the build fails (when Nix is called with # debug inside the VM if the build fails (when Nix is called with
@ -255,8 +265,7 @@ rec {
diskImage=$diskImage diskImage=$diskImage
TMPDIR=$TMPDIR TMPDIR=$TMPDIR
cd $TMPDIR cd $TMPDIR
${socat}/bin/socat unix-listen:./samba system:'while true; do ${samba}/sbin/smbd -s $TMPDIR/smb.conf; done' > /dev/null 2>&1 & ${startSamba}
while [ ! -e ./samba ]; do sleep 0.1; done # ugly
${qemuCommand} ${qemuCommand}
EOF EOF
@ -330,7 +339,7 @@ rec {
qemuCommandGeneric = '' qemuCommandGeneric = ''
qemu-system-x86_64 \ ${kvm}/bin/qemu-system-x86_64 \
-nographic -no-reboot \ -nographic -no-reboot \
-smb $(pwd) -hda $diskImage \ -smb $(pwd) -hda $diskImage \
$QEMU_OPTS $QEMU_OPTS