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

Golang lxc.KillLxc函数代码示例

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

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



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

示例1: register

// register makes a container object usable by the daemon as <container.ID>
func (daemon *Daemon) register(container *Container, updateSuffixarray bool) error {
	if container.daemon != nil || daemon.Exists(container.ID) {
		return fmt.Errorf("Container is already loaded")
	}
	if err := validateID(container.ID); err != nil {
		return err
	}
	if err := daemon.ensureName(container); err != nil {
		return err
	}

	container.daemon = daemon

	// Attach to stdout and stderr
	container.stderr = broadcastwriter.New()
	container.stdout = broadcastwriter.New()
	// Attach to stdin
	if container.Config.OpenStdin {
		container.stdin, container.stdinPipe = io.Pipe()
	} else {
		container.stdinPipe = ioutils.NopWriteCloser(ioutil.Discard) // Silently drop stdin
	}
	// done
	daemon.containers.Add(container.ID, container)

	// don't update the Suffixarray if we're starting up
	// we'll waste time if we update it for every container
	daemon.idIndex.Add(container.ID)

	// FIXME: if the container is supposed to be running but is not, auto restart it?
	//        if so, then we need to restart monitor and init a new lock
	// If the container is supposed to be running, make sure of it
	if container.IsRunning() {
		log.Debugf("killing old running container %s", container.ID)

		existingPid := container.Pid
		container.SetStopped(&execdriver.ExitStatus{ExitCode: 0})

		// We only have to handle this for lxc because the other drivers will ensure that
		// no processes are left when docker dies
		if container.ExecDriver == "" || strings.Contains(container.ExecDriver, "lxc") {
			lxc.KillLxc(container.ID, 9)
		} else {
			// use the current driver and ensure that the container is dead x.x
			cmd := &execdriver.Command{
				ID: container.ID,
			}
			var err error
			cmd.ProcessConfig.Process, err = os.FindProcess(existingPid)
			if err != nil {
				log.Debugf("cannot find existing process for %d", existingPid)
			}
			daemon.execDriver.Terminate(cmd)
		}

		if err := container.Unmount(); err != nil {
			log.Debugf("unmount error %s", err)
		}
		if err := container.ToDisk(); err != nil {
			log.Debugf("saving stopped state to disk %s", err)
		}

		info := daemon.execDriver.Info(container.ID)
		if !info.IsRunning() {
			log.Debugf("Container %s was supposed to be running but is not.", container.ID)

			log.Debugf("Marking as stopped")

			container.SetStopped(&execdriver.ExitStatus{ExitCode: -127})
			if err := container.ToDisk(); err != nil {
				return err
			}
		}
	}
	return nil
}
开发者ID:hantuo,项目名称:docker,代码行数:77,代码来源:daemon.go


示例2: register

// register makes a container object usable by the daemon as <container.ID>
func (daemon *Daemon) register(container *Container, updateSuffixarray bool) error {
	if container.daemon != nil || daemon.Exists(container.ID) {
		return fmt.Errorf("Container is already loaded")
	}
	if err := validateID(container.ID); err != nil {
		return err
	}
	if err := daemon.ensureName(container); err != nil {
		return err
	}

	container.daemon = daemon

	// Attach to stdout and stderr
	container.stderr = broadcastwriter.New()
	container.stdout = broadcastwriter.New()
	// Attach to stdin
	if container.Config.OpenStdin {
		container.stdin, container.stdinPipe = io.Pipe()
	} else {
		container.stdinPipe = ioutils.NopWriteCloser(ioutil.Discard) // Silently drop stdin
	}
	// done
	daemon.containers.Add(container.ID, container)

	// don't update the Suffixarray if we're starting up
	// we'll waste time if we update it for every container
	daemon.idIndex.Add(container.ID)

	// FIXME: if the container is supposed to be running but is not, auto restart it?
	//        if so, then we need to restart monitor and init a new lock
	// If the container is supposed to be running, make sure of it
	if container.IsRunning() {
		if container.MonitorDriver == MonitorBuiltin {
			log.Debugf("killing old running container %s", container.ID)

			existingPid := container.Pid
			container.SetStopped(0)

			// We only have to handle this for lxc because the other drivers will ensure that
			// no processes are left when docker dies
			if container.ExecDriver == "" || strings.Contains(container.ExecDriver, "lxc") {
				lxc.KillLxc(container.ID, 9)
			} else {
				// use the current driver and ensure that the container is dead x.x
				cmd := &execdriver.Command{
					ID: container.ID,
				}
				var err error
				cmd.ProcessConfig.Process, err = os.FindProcess(existingPid)
				if err != nil {
					log.Debugf("cannot find existing process for %d", existingPid)
				}
				daemon.execDriver.Terminate(cmd)
			}

			if err := container.Unmount(); err != nil {
				log.Debugf("unmount error %s", err)
			}
			if err := container.ToDisk(); err != nil {
				log.Debugf("saving stopped state to disk %s", err)
			}

			info := daemon.execDriver.Info(container.ID)
			if !info.IsRunning() {
				log.Debugf("Container %s was supposed to be running but is not.", container.ID)

				log.Debugf("Marking as stopped")

				container.SetStopped(-127)
				if err := container.ToDisk(); err != nil {
					return err
				}
			}
		} else {
			// restore external container
			log.Debugf("restore external container: %s", container.ID)
			_, err := container.daemon.callMonitorAPI(container, "GET", "_ping")
			if err != nil {
				log.Errorf("Call monitor _ping API failed: %v, mark container %s stopped", err, container.ID)

				// Think monitor is down, mark container is down
				container.SetStopped(-125)
				if err := container.ToDisk(); err != nil {
					return err
				}
			} else {
				obj, err := container.daemon.callMonitorAPI(container, "GET", "state")
				if err != nil {
					log.Errorf("Call monitor state API failed: %v", err)
					return err
				}

				m := make(map[string]*WatchState)
				if err = json.Unmarshal(obj, &m); err != nil {
					log.Errorf("Decode WatchState error: %v", err)
					return err
				}
				ws := m["WatchState"]
//.........这里部分代码省略.........
开发者ID:hustcat,项目名称:docker-1.3,代码行数:101,代码来源:daemon.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang template.New函数代码示例发布时间:2022-05-23
下一篇:
Golang execdrivers.NewDriver函数代码示例发布时间: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