• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang garden.Process类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudfoundry-incubator/garden.Process的典型用法代码示例。如果您正苦于以下问题:Golang Process类的具体用法?Golang Process怎么用?Golang Process使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Process类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: flushProcess

func flushProcess(conn net.Conn, process garden.Process, stdout <-chan []byte, stderr <-chan []byte) {
	stdoutSource := transport.Stdout
	stderrSource := transport.Stderr

	for {
		select {
		case data := <-stdout:
			d := string(data)
			transport.WriteMessage(conn, &transport.ProcessPayload{
				ProcessID: process.ID(),
				Source:    &stdoutSource,
				Data:      &d,
			})

		case data := <-stderr:
			d := string(data)
			transport.WriteMessage(conn, &transport.ProcessPayload{
				ProcessID: process.ID(),
				Source:    &stderrSource,
				Data:      &d,
			})

		default:
			return
		}
	}
}
开发者ID:vito,项目名称:gaol,代码行数:27,代码来源:request_handling.go


示例2: wait

func (c *checker) wait(logger lager.Logger, proc garden.Process) (int, error) {
	logger = logger.Session("wait")
	logger.Debug("starting")
	defer logger.Debug("finished")

	var exitCode int
	err := retryOnFail(c.retryInterval, func(attempt uint) (waitErr error) {
		exitCode, waitErr = proc.Wait()
		if waitErr != nil {
			logger.Error("failed", waitErr, lager.Data{"attempt": attempt})
			return waitErr
		}

		logger.Debug("succeeded", lager.Data{"attempt": attempt})
		return nil
	})

	return exitCode, err
}
开发者ID:snowsnail,项目名称:executor,代码行数:19,代码来源:checker.go


示例3: Run

func (conn RetryableConnection) Run(handle string, processSpec garden.ProcessSpec, processIO garden.ProcessIO) (garden.Process, error) {
	var innerProcess garden.Process

	err := conn.retry(func() error {
		var err error
		innerProcess, err = conn.Connection.Run(handle, processSpec, processIO)
		return err
	})
	if err != nil {
		return nil, err
	}

	return &retryableProcess{
		Process: innerProcess,

		rehydrate: func() (garden.Process, error) {
			return conn.Attach(handle, innerProcess.ID(), processIO)
		},
	}, nil
}
开发者ID:utako,项目名称:atc,代码行数:20,代码来源:retryable_garden_connection.go


示例4: streamInput

func (s *GardenServer) streamInput(decoder *json.Decoder, in *io.PipeWriter, process garden.Process, connCloseCh chan struct{}) {
	for {
		var payload transport.ProcessPayload
		err := decoder.Decode(&payload)
		if err != nil {
			close(connCloseCh)
			in.CloseWithError(errors.New("Connection closed"))
			return
		}

		switch {
		case payload.TTY != nil:
			process.SetTTY(*payload.TTY)

		case payload.Source != nil:
			if payload.Data == nil {
				in.Close()
				return
			} else {
				_, err := in.Write([]byte(*payload.Data))
				if err != nil {
					return
				}
			}

		case payload.Signal != nil:
			s.logger.Info("stream-input-process-signal", lager.Data{"payload": payload})

			switch *payload.Signal {
			case garden.SignalKill:
				err = process.Signal(garden.SignalKill)
				if err != nil {
					s.logger.Error("stream-input-process-signal-kill-failed", err, lager.Data{"payload": payload})
				}
			case garden.SignalTerminate:
				err = process.Signal(garden.SignalTerminate)
				if err != nil {
					s.logger.Error("stream-input-process-signal-terminate-failed", err, lager.Data{"payload": payload})
				}
			default:
				s.logger.Error("stream-input-unknown-process-payload-signal", nil, lager.Data{"payload": payload})
				in.Close()
				return
			}

		default:
			s.logger.Error("stream-input-unknown-process-payload", nil, lager.Data{"payload": payload})
			in.Close()
			return
		}
	}
}
开发者ID:nagyistoce,项目名称:garden,代码行数:52,代码来源:request_handling.go


示例5: streamProcess

func (s *GardenServer) streamProcess(logger lager.Logger, conn net.Conn, process garden.Process, stdinPipe *io.PipeWriter) {
	statusCh := make(chan int, 1)
	errCh := make(chan error, 1)

	go func() {
		status, err := process.Wait()
		if err != nil {
			logger.Error("wait-failed", err, lager.Data{
				"id": process.ID(),
			})

			errCh <- err
		} else {
			logger.Info("exited", lager.Data{
				"status": status,
				"id":     process.ID(),
			})

			statusCh <- status
		}
	}()

	for {
		select {

		case status := <-statusCh:
			transport.WriteMessage(conn, &transport.ProcessPayload{
				ProcessID:  process.ID(),
				ExitStatus: &status,
			})

			stdinPipe.Close()
			return

		case err := <-errCh:
			e := err.Error()
			transport.WriteMessage(conn, &transport.ProcessPayload{
				ProcessID: process.ID(),
				Error:     &e,
			})

			stdinPipe.Close()
			return

		case <-s.stopping:
			logger.Debug("detaching", lager.Data{
				"id": process.ID(),
			})

			return
		}
	}
}
开发者ID:tangfeixiong,项目名称:garden,代码行数:53,代码来源:request_handling.go


示例6:

	Describe("Running processes", func() {
		It("runs the process and returns its exit code", func() {
			cmd := exec.Command("bash", "-c", "exit 42")

			process, err := processTracker.Run(555, cmd, garden.ProcessIO{}, nil, signaller)
			Expect(err).NotTo(HaveOccurred())

			status, err := process.Wait()
			Expect(err).ToNot(HaveOccurred())
			Expect(status).To(Equal(42))
		})

		Describe("signalling a running process", func() {
			var (
				process garden.Process
				stdout  *gbytes.Buffer
				cmd     *exec.Cmd
			)

			JustBeforeEach(func() {
				var err error
				cmd = exec.Command(testPrintBin)

				stdout = gbytes.NewBuffer()
				process, err = processTracker.Run(
					2, cmd,
					garden.ProcessIO{
						Stdout: io.MultiWriter(stdout, GinkgoWriter),
						Stderr: GinkgoWriter,
					}, nil, signaller)
				Expect(err).NotTo(HaveOccurred())
开发者ID:guanglinlv,项目名称:garden-linux,代码行数:31,代码来源:process_tracker_test.go


示例7: runScript

func (resource *resource) runScript(
	path string,
	args []string,
	input interface{},
	output interface{},
	logDest io.Writer,
	inputSource ArtifactSource,
	inputDestination ArtifactDestination,
	recoverable bool,
) ifrit.Runner {
	return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
		request, err := json.Marshal(input)
		if err != nil {
			return err
		}

		if recoverable {
			result, err := resource.container.Property(resourceResultPropertyName)
			if err == nil {
				return json.Unmarshal([]byte(result), &output)
			}
		}

		stdout := new(bytes.Buffer)
		stderr := new(bytes.Buffer)

		processIO := garden.ProcessIO{
			Stdin:  bytes.NewBuffer(request),
			Stdout: stdout,
		}

		if logDest != nil {
			processIO.Stderr = logDest
		} else {
			processIO.Stderr = stderr
		}

		var process garden.Process

		var processIDProp string
		if recoverable {
			processIDProp, err = resource.container.Property(resourceProcessIDPropertyName)
			if err != nil {
				processIDProp = ""
			}
		}

		if processIDProp != "" {
			var processID uint32
			_, err = fmt.Sscanf(processIDProp, "%d", &processID)
			if err != nil {
				return err
			}

			process, err = resource.container.Attach(processID, processIO)
			if err != nil {
				return err
			}
		} else {
			if inputSource != nil {
				err := inputSource.StreamTo(inputDestination)
				if err != nil {
					return err
				}
			}

			process, err = resource.container.Run(garden.ProcessSpec{
				Path: path,
				Args: args,
				User: "root",
			}, processIO)
			if err != nil {
				return err
			}

			if recoverable {
				processIDValue := fmt.Sprintf("%d", process.ID())

				err := resource.container.SetProperty(resourceProcessIDPropertyName, processIDValue)
				if err != nil {
					return err
				}
			}
		}

		close(ready)

		statusCh := make(chan int, 1)
		errCh := make(chan error, 1)

		go func() {
			status, err := process.Wait()
			if err != nil {
				errCh <- err
			} else {
				statusCh <- status
			}
		}()

		select {
//.........这里部分代码省略.........
开发者ID:utako,项目名称:atc,代码行数:101,代码来源:run_script.go


示例8:

			Expect(err).NotTo(HaveOccurred())

			cmd := exec.Command("bash", "-c", "pwd")
			cmd.Dir = tmpDir

			stdout := gbytes.NewBuffer()
			_, err = processTracker.Run("556", cmd, garden.ProcessIO{Stdout: stdout}, nil)
			Expect(err).NotTo(HaveOccurred())

			Eventually(stdout).Should(gbytes.Say(tmpDir))
		})

		Describe("signalling a running process", func() {
			var (
				process garden.Process
				stdout  *gbytes.Buffer
				cmd     *exec.Cmd
			)

			JustBeforeEach(func() {
				var err error
				cmd = exec.Command("sh", "-c", `
					trap "echo 'terminated'; exit 42" TERM
					echo "trapping"

					sleep 100 &
					wait
				`)

				stdout = gbytes.NewBuffer()
				process, err = processTracker.Run(
开发者ID:digideskio,项目名称:guardian,代码行数:31,代码来源:process_tracker_test.go


示例9:

				calledHandle, calledSpec := innerConnection.StreamOutArgsForCall(0)
				Ω(calledHandle).Should(Equal(handle))
				Ω(calledSpec.Path).Should(Equal("/etc/passwd"))
				Ω(calledSpec.User).Should(Equal("admin"))
			})

			It("returns the reader", func() {
				Ω(gotReader).Should(Equal(gbytes.NewBuffer()))
			})
		})
	})

	Describe("Attach", func() {
		var (
			fakeProcess *gfakes.FakeProcess
			process     garden.Process
		)

		processIO := garden.ProcessIO{
			Stdout: gbytes.NewBuffer(),
		}

		BeforeEach(func() {
			fakeProcess = new(gfakes.FakeProcess)
			fakeProcess.IDReturns(6)
		})

		itRetries(func() error {
			var err error
			process, err = conn.Attach("la-contineur", 6, processIO)
			return err
开发者ID:utako,项目名称:atc,代码行数:31,代码来源:retryable_garden_connection_test.go


示例10:

				calledHandle, calledSpec := innerConnection.StreamOutArgsForCall(0)
				Expect(calledHandle).To(Equal(handle))
				Expect(calledSpec.Path).To(Equal("/etc/passwd"))
				Expect(calledSpec.User).To(Equal("admin"))
			})

			It("returns the reader", func() {
				Expect(gotReader).To(Equal(gbytes.NewBuffer()))
			})
		})
	})

	Describe("Attach", func() {
		var (
			fakeProcess *gfakes.FakeProcess
			process     garden.Process
		)

		processIO := garden.ProcessIO{
			Stdout: gbytes.NewBuffer(),
		}

		BeforeEach(func() {
			fakeProcess = new(gfakes.FakeProcess)
			fakeProcess.IDReturns("process-id")
		})

		itRetries(func() error {
			var err error
			process, err = conn.Attach("la-contineur", "process-id", processIO)
			return err
开发者ID:pcfdev-forks,项目名称:atc,代码行数:31,代码来源:retryable_garden_connection_test.go



注:本文中的github.com/cloudfoundry-incubator/garden.Process类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang linux_container.LinuxContainer类代码示例发布时间:2022-05-23
下一篇:
Golang garden.ContainerSpec类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap