當前位置: 首頁>>代碼示例>>Golang>>正文


Golang systemd.UseSystemd函數代碼示例

本文整理匯總了Golang中github.com/docker/libcontainer/cgroups/systemd.UseSystemd函數的典型用法代碼示例。如果您正苦於以下問題:Golang UseSystemd函數的具體用法?Golang UseSystemd怎麽用?Golang UseSystemd使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了UseSystemd函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewDriver

func NewDriver(root, initPath string) (*driver, error) {
	meminfo, err := sysinfo.ReadMemInfo()
	if err != nil {
		return nil, err
	}

	if err := os.MkdirAll(root, 0700); err != nil {
		return nil, err
	}
	// native driver root is at docker_root/execdriver/native. Put apparmor at docker_root
	if err := apparmor.InstallDefaultProfile(); err != nil {
		return nil, err
	}
	cgm := libcontainer.Cgroupfs
	if systemd.UseSystemd() {
		cgm = libcontainer.SystemdCgroups
	}

	f, err := libcontainer.New(
		root,
		cgm,
		libcontainer.InitPath(reexec.Self(), DriverName),
	)
	if err != nil {
		return nil, err
	}

	return &driver{
		root:             root,
		initPath:         initPath,
		activeContainers: make(map[string]libcontainer.Container),
		machineMemory:    meminfo.MemTotal,
		factory:          f,
	}, nil
}
開發者ID:yingmsky,項目名稱:docker,代碼行數:35,代碼來源:driver.go

示例2: TestMain

func TestMain(m *testing.M) {
	var (
		err error
		ret int = 0
	)

	log.SetOutput(os.Stderr)
	log.SetLevel(log.InfoLevel)

	factory, err = libcontainer.New(".", libcontainer.Cgroupfs)
	if err != nil {
		log.Error(err)
		os.Exit(1)
	}
	if systemd.UseSystemd() {
		systemdFactory, err = libcontainer.New(".", libcontainer.SystemdCgroups)
		if err != nil {
			log.Error(err)
			os.Exit(1)
		}
	}

	ret = m.Run()
	os.Exit(ret)
}
開發者ID:st3v3nle,項目名稱:cadvisor,代碼行數:25,代碼來源:init_test.go

示例3: Register

// Register root container before running this function!
func Register(factory info.MachineInfoFactory) error {
	client, err := docker.NewClient(*ArgDockerEndpoint)
	if err != nil {
		return fmt.Errorf("unable to communicate with docker daemon: %v", err)
	}
	if version, err := client.Version(); err != nil {
		return fmt.Errorf("unable to communicate with docker daemon: %v", err)
	} else {
		expected_version := []int{0, 11, 1}
		version_string := version.Get("Version")
		version, err := parseDockerVersion(version_string)
		if err != nil {
			return fmt.Errorf("Couldn't parse docker version: %v", err)
		}
		for index, number := range version {
			if number > expected_version[index] {
				break
			} else if number < expected_version[index] {
				return fmt.Errorf("cAdvisor requires docker version above %v but we have found version %v reported as \"%v\"", expected_version, version, version_string)
			}
		}
	}
	f := &dockerFactory{
		machineInfoFactory: factory,
		useSystemd:         systemd.UseSystemd(),
		client:             client,
	}
	if f.useSystemd {
		log.Printf("System is using systemd")
	}
	log.Printf("Registering Docker factory")
	container.RegisterContainerHandlerFactory(f)
	return nil
}
開發者ID:rossbachp,項目名稱:cadvisor,代碼行數:35,代碼來源:factory.go

示例4: killAllPids

// killAllPids itterates over all of the container's processes
// sending a SIGKILL to each process.
func killAllPids(container *libcontainer.Config) error {
	var (
		procs   []*os.Process
		freeze  = fs.Freeze
		getPids = fs.GetPids
	)
	if systemd.UseSystemd() {
		freeze = systemd.Freeze
		getPids = systemd.GetPids
	}
	freeze(container.Cgroups, cgroups.Frozen)
	pids, err := getPids(container.Cgroups)
	if err != nil {
		return err
	}
	for _, pid := range pids {
		// TODO: log err without aborting if we are unable to find
		// a single PID
		if p, err := os.FindProcess(pid); err == nil {
			procs = append(procs, p)
			p.Kill()
		}
	}
	freeze(container.Cgroups, cgroups.Thawed)
	for _, p := range procs {
		p.Wait()
	}
	return err
}
開發者ID:hgschmie,項目名稱:docker,代碼行數:31,代碼來源:exec.go

示例5: GetStats

func (self *dockerContainerHandler) GetStats() (stats *info.ContainerStats, err error) {
	if !self.isDockerContainer() {
		// Return empty stats for root containers.
		stats = new(info.ContainerStats)
		stats.Timestamp = time.Now()
		return
	}
	mi, err := self.machineInfoFactory.GetMachineInfo()
	if err != nil {
		return
	}
	parent, id, err := self.splitName()
	if err != nil {
		return
	}
	cg := &cgroups.Cgroup{
		Parent: parent,
		Name:   id,
	}

	// TODO(vmarmol): Use libcontainer's Stats() in the new API when that is ready.
	// Use systemd paths if systemd is being used.
	var s *cgroups.Stats
	if systemd.UseSystemd() {
		s, err = systemd.GetStats(cg)
	} else {
		s, err = fs.GetStats(cg)
	}
	if err != nil {
		return
	}
	stats = libcontainerToContainerStats(s, mi)
	return
}
開發者ID:RubanDeventhiran,項目名稱:kubernetes,代碼行數:34,代碼來源:handler.go

示例6: SetupCgroups

// SetupCgroups applies the cgroup restrictions to the process running in the container based
// on the container's configuration
func SetupCgroups(container *libcontainer.Config, nspid int) (map[string]string, error) {
	if container.Cgroups != nil {
		c := container.Cgroups
		if systemd.UseSystemd() {
			return systemd.Apply(c, nspid)
		}
		return fs.Apply(c, nspid)
	}
	return map[string]string{}, nil
}
開發者ID:hgschmie,項目名稱:docker,代碼行數:12,代碼來源:exec.go

示例7: SetupCgroups

// SetupCgroups applies the cgroup restrictions to the process running in the container based
// on the container's configuration
func SetupCgroups(container *libcontainer.Config, nspid int) (cgroups.ActiveCgroup, error) {
	if container.Cgroups != nil {
		c := container.Cgroups
		if systemd.UseSystemd() {
			return systemd.Apply(c, nspid)
		}
		return fs.Apply(c, nspid)
	}
	return nil, nil
}
開發者ID:hwpaas,項目名稱:docker,代碼行數:12,代碼來源:exec.go

示例8: loadFactory

func loadFactory(context *cli.Context) (libcontainer.Factory, error) {
	cgm := libcontainer.Cgroupfs
	if context.Bool("systemd") {
		if systemd.UseSystemd() {
			cgm = libcontainer.SystemdCgroups
		} else {
			logrus.Warn("systemd cgroup flag passed, but systemd support for managing cgroups is not available.")
		}
	}
	return libcontainer.New(context.GlobalString("root"), cgm)
}
開發者ID:colebrumley,項目名稱:docker,代碼行數:11,代碼來源:utils.go

示例9: Unpause

func (d *driver) Unpause(c *execdriver.Command) error {
	active := d.activeContainers[c.ID]
	if active == nil {
		return fmt.Errorf("active container for %s does not exist", c.ID)
	}
	active.container.Cgroups.Freezer = "THAWED"
	if systemd.UseSystemd() {
		return systemd.Freeze(active.container.Cgroups, active.container.Cgroups.Freezer)
	}
	return fs.Freeze(active.container.Cgroups, active.container.Cgroups.Freezer)
}
開發者ID:Gandi,項目名稱:docker,代碼行數:11,代碼來源:driver.go

示例10: init

func init() {
	useSystemd = systemd.UseSystemd()
	if !useSystemd {
		// Second attempt at checking for systemd, check for a "name=systemd" cgroup.
		mnt, err := cgroups.FindCgroupMountpoint("cpu")
		if err == nil {
			// systemd presence does not mean systemd controls cgroups.
			// If system.slice cgroup exists, then systemd is taking control.
			// This breaks if user creates system.slice manually :)
			useSystemd = utils.FileExists(mnt + "/system.slice")
		}
	}
}
開發者ID:vrosnet,項目名稱:kubernetes,代碼行數:13,代碼來源:factory.go

示例11: Register

// Register root container before running this function!
func Register(factory info.MachineInfoFactory) error {
	client, err := docker.NewClient(*ArgDockerEndpoint)
	if err != nil {
		return fmt.Errorf("unable to communicate with docker daemon: %v", err)
	}
	if version, err := client.Version(); err != nil {
		return fmt.Errorf("unable to communicate with docker daemon: %v", err)
	} else {
		expected_version := []int{0, 11, 1}
		version_string := version.Get("Version")
		version, err := parseDockerVersion(version_string)
		if err != nil {
			return fmt.Errorf("Couldn't parse docker version: %v", err)
		}
		for index, number := range version {
			if number > expected_version[index] {
				break
			} else if number < expected_version[index] {
				return fmt.Errorf("cAdvisor requires docker version above %v but we have found version %v reported as \"%v\"", expected_version, version, version_string)
			}
		}
	}

	// Check that the libcontainer execdriver is used.
	information, err := client.Info()
	if err != nil {
		return fmt.Errorf("failed to detect Docker info: %v", err)
	}
	usesNativeDriver := false
	for _, val := range *information {
		if strings.Contains(val, "ExecutionDriver=") && strings.Contains(val, "native") {
			usesNativeDriver = true
			break
		}
	}
	if !usesNativeDriver {
		return fmt.Errorf("Docker found, but not using native exec driver")
	}

	f := &dockerFactory{
		machineInfoFactory: factory,
		useSystemd:         systemd.UseSystemd(),
		client:             client,
	}
	if f.useSystemd {
		glog.Infof("System is using systemd")
	}
	glog.Infof("Registering Docker factory")
	container.RegisterContainerHandlerFactory(f)
	return nil
}
開發者ID:cnf,項目名稱:cadvisor,代碼行數:52,代碼來源:factory.go

示例12: toggle

func toggle(state cgroups.FreezerState) error {
	container, err := loadConfig()
	if err != nil {
		return err
	}

	if systemd.UseSystemd() {
		err = systemd.Freeze(container.Cgroups, state)
	} else {
		err = fs.Freeze(container.Cgroups, state)
	}

	return err
}
開發者ID:Gandi,項目名稱:docker,代碼行數:14,代碼來源:pause.go

示例13: destroyAction

func destroyAction(context *cli.Context) {
	config, err := getConfig(context)
	if err != nil {
		log.Fatal(err)
	}

	killAll(config)
	// Systemd will clean up cgroup state for empty container.
	if !systemd.UseSystemd() {
		err := fs.Cleanup(config)
		if err != nil {
			log.Fatal(err)
		}
	}
}
開發者ID:BreezeWu,項目名稱:docker,代碼行數:15,代碼來源:cgutil.go

示例14: setFreezerState

func setFreezerState(context *cli.Context, state cgroups.FreezerState) {
	config, err := getConfig(context)
	if err != nil {
		log.Fatal(err)
	}

	if systemd.UseSystemd() {
		err = systemd.Freeze(config, state)
	} else {
		err = fs.Freeze(config, state)
	}
	if err != nil {
		log.Fatal(err)
	}
}
開發者ID:BreezeWu,項目名稱:docker,代碼行數:15,代碼來源:cgutil.go

示例15: GetPidsForContainer

func (d *driver) GetPidsForContainer(id string) ([]int, error) {
	d.Lock()
	active := d.activeContainers[id]
	d.Unlock()

	if active == nil {
		return nil, fmt.Errorf("active container for %s does not exist", id)
	}
	c := active.container.Cgroups

	if systemd.UseSystemd() {
		return systemd.GetPids(c)
	}
	return fs.GetPids(c)
}
開發者ID:Gandi,項目名稱:docker,代碼行數:15,代碼來源:driver.go


注:本文中的github.com/docker/libcontainer/cgroups/systemd.UseSystemd函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。