예제 #1
0
func main() {
	flag.Parse()

	gclient := client.New(connection.New("tcp", "localhost:7777"))

	var container garden.Container
	containers, err := gclient.Containers(garden.Properties{})
	must(err)
	for _, c := range containers {
		if c.Handle() == *containerHandle {
			container = c
			break
		}
	}
	if container == nil {
		panic("Container not found!")
	}

	process, err := container.Attach(uint32(*processId), garden.ProcessIO{})
	must(err)

	switch *signalType {
	case "term":
		fmt.Println("Signalling term")
		must(process.Signal(garden.SignalTerminate))
		break

	case "kill":
		fmt.Println("Signalling kill")
		must(process.Signal(garden.SignalKill))
		break
	}
}
			process, err := container.Run(garden.ProcessSpec{
				User: "******",
				Path: "cat",
			}, garden.ProcessIO{})
			Expect(err).ToNot(HaveOccurred())

			processID = process.ID()
		})

		Measure("does not leak goroutines", func(b Benchmarker) {
			for i := 1; i <= iterations; i++ {
				stdoutR, stdoutW := io.Pipe()
				stdinR, stdinW := io.Pipe()

				_, err := container.Attach(processID, garden.ProcessIO{
					Stdin:  stdinR,
					Stdout: stdoutW,
				})
				Expect(err).ToNot(HaveOccurred())

				stdinData := fmt.Sprintf("hello %d", i)

				_, err = stdinW.Write([]byte(stdinData + "\n"))
				Expect(err).ToNot(HaveOccurred())

				var line []byte
				doneReading := make(chan struct{})
				go func() {
					line, _, err = bufio.NewReader(stdoutR).ReadLine()
					close(doneReading)
				}()
예제 #3
0
					_, err = fmt.Fprintf(io.Stderr, "stderr data")
					Ω(err).ShouldNot(HaveOccurred())
				}()

				return process, nil
			}

			stdout := gbytes.NewBuffer()
			stderr := gbytes.NewBuffer()

			processIO := garden.ProcessIO{
				Stdout: stdout,
				Stderr: stderr,
			}

			process, err := container.Attach(42, processIO)
			Ω(err).ShouldNot(HaveOccurred())

			attachedHandle, attachedID, attachedIO := fakeConnection.AttachArgsForCall(0)
			Ω(attachedHandle).Should(Equal("some-handle"))
			Ω(attachedID).Should(Equal(uint32(42)))
			Ω(attachedIO).Should(Equal(processIO))

			Ω(process.ID()).Should(Equal(uint32(42)))

			status, err := process.Wait()
			Ω(err).ShouldNot(HaveOccurred())
			Ω(status).Should(Equal(123))

			Eventually(stdout).Should(gbytes.Say("stdout data"))
			Eventually(stderr).Should(gbytes.Say("stderr data"))
예제 #4
0
					_, err = fmt.Fprintf(io.Stderr, "stderr data")
					Ω(err).ShouldNot(HaveOccurred())
				}()

				return process, nil
			}

			stdout := gbytes.NewBuffer()
			stderr := gbytes.NewBuffer()

			processIO := garden.ProcessIO{
				Stdout: stdout,
				Stderr: stderr,
			}

			process, err := container.Attach("process-handle", processIO)
			Ω(err).ShouldNot(HaveOccurred())

			attachedHandle, attachedID, attachedIO := fakeConnection.AttachArgsForCall(0)
			Ω(attachedHandle).Should(Equal("some-handle"))
			Ω(attachedID).Should(Equal("process-handle"))
			Ω(attachedIO).Should(Equal(processIO))

			Ω(process.ID()).Should(Equal("process-handle"))

			status, err := process.Wait()
			Ω(err).ShouldNot(HaveOccurred())
			Ω(status).Should(Equal(123))

			Eventually(stdout).Should(gbytes.Say("stdout data"))
			Eventually(stderr).Should(gbytes.Say("stderr data"))
예제 #5
0
						return process, nil
					}
				})

				It("responds with a ProcessPayload for every chunk", func() {
					stdout := gbytes.NewBuffer()
					stderr := gbytes.NewBuffer()

					processIO := garden.ProcessIO{
						Stdin:  bytes.NewBufferString("stdin data"),
						Stdout: stdout,
						Stderr: stderr,
					}

					process, err := container.Attach(42, processIO)
					Ω(err).ShouldNot(HaveOccurred())

					pid, _ := fakeContainer.AttachArgsForCall(0)
					Ω(pid).Should(Equal(uint32(42)))

					Eventually(stdout).Should(gbytes.Say("stdout data"))
					Eventually(stdout).Should(gbytes.Say("mirrored stdin data"))
					Eventually(stderr).Should(gbytes.Say("stderr data"))

					status, err := process.Wait()
					Ω(err).ShouldNot(HaveOccurred())
					Ω(status).Should(Equal(123))
				})

				itResetsGraceTimeWhenHandling(func() {
예제 #6
0
		It("continues to stream", func() {
			process, err := container.Run(garden.ProcessSpec{
				User: "******",
				Path: "sh",
				Args: []string{"-c", "while true; do echo hi; sleep 0.5; done"},
			}, garden.ProcessIO{})
			Expect(err).ToNot(HaveOccurred())

			restartGarden(gardenArgs...)

			_, err = process.Wait()
			Expect(err).To(HaveOccurred())

			stdout := gbytes.NewBuffer()
			_, err = container.Attach(process.ID(), garden.ProcessIO{
				Stdout: stdout,
			})
			Expect(err).ToNot(HaveOccurred())

			Eventually(stdout, 30.0).Should(gbytes.Say("hi\n"))
		})

		It("can still accept stdin", func() {
			r, w := io.Pipe()

			stdout := gbytes.NewBuffer()

			process, err := container.Run(garden.ProcessSpec{
				User: "******",
				Path: "sh",
				Args: []string{"-c", "cat <&0"},