cmd/buildlet: halt the machine for Sierra VMs on MacStadium

macOS Sierra's network stack gets wedged after a few runs of all.bash.
Instead, halt the machine after a build is complete. cmd/makemac will make
a new one for the next build.

Change-Id: Icb1b21c045376cff9958a0d3b4cfaf784c9948d0
Reviewed-on: https://go-review.googlesource.com/37465
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/cmd/buildlet/buildlet.go b/cmd/buildlet/buildlet.go
index 1cfd065..2448b35 100644
--- a/cmd/buildlet/buildlet.go
+++ b/cmd/buildlet/buildlet.go
@@ -1004,6 +1004,13 @@
 		err = exec.Command("/bin/halt", "-n", "-f", "-p").Run()
 	case "plan9":
 		err = exec.Command("fshalt").Run()
+	case "darwin":
+		if os.Getenv("GO_BUILDER_ENV") == "macstadium_vm" {
+			// Fast, sloppy, unsafe, because we're never reusing this VM again.
+			err = exec.Command("/sbin/halt", "-n", "-q", "-l").Run()
+		} else {
+			err = errors.New("not respecting -halt flag on macOS in unknown environment")
+		}
 	default:
 		err = errors.New("No system-specific halt command run; will just end buildlet process.")
 	}
@@ -1258,7 +1265,14 @@
 	if m == nil {
 		log.Fatalf("unsupported sw_vers version %q", version)
 	}
-	*reverse = "darwin-amd64-" + m[1] + "_" + m[2]
+	major, minor := m[1], m[2] // "10", "12"
+	if minor == "12" {
+		// macOS Sierra wedges its network stack if it runs
+		// all.bash a few times in a row. Reboot between each
+		// build.
+		*haltEntireOS = true
+	}
+	*reverse = "darwin-amd64-" + major + "_" + minor
 	*coordinator = "farmer.golang.org:443"
 	*hostname = vmwareGetInfo("guestinfo.name")
 }