本文整理匯總了Golang中github.com/litl/galaxy/config.App.GetCPUShares方法的典型用法代碼示例。如果您正苦於以下問題:Golang App.GetCPUShares方法的具體用法?Golang App.GetCPUShares怎麽用?Golang App.GetCPUShares使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/litl/galaxy/config.App
的用法示例。
在下文中一共展示了App.GetCPUShares方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Start
func (s *ServiceRuntime) Start(env, pool string, appCfg config.App) (*docker.Container, error) {
img := appCfg.Version()
imgIdRef := appCfg.Version()
if appCfg.VersionID() != "" {
imgIdRef = appCfg.VersionID()
}
// see if we have the image locally
image, err := s.PullImage(img, imgIdRef)
if err != nil {
return nil, err
}
// setup env vars from etcd
var envVars []string
envVars = append(envVars, "ENV"+"="+env)
for key, value := range appCfg.Env() {
if key == "ENV" {
continue
}
envVars = append(envVars, strings.ToUpper(key)+"="+s.replaceVarEnv(value, s.hostIP))
}
instanceId, err := s.NextInstanceSlot(appCfg.Name(), strconv.FormatInt(appCfg.ID(), 10))
if err != nil {
return nil, err
}
envVars = append(envVars, fmt.Sprintf("HOST_IP=%s", s.hostIP))
envVars = append(envVars, fmt.Sprintf("GALAXY_APP=%s", appCfg.Name()))
envVars = append(envVars, fmt.Sprintf("GALAXY_VERSION=%s", strconv.FormatInt(appCfg.ID(), 10)))
envVars = append(envVars, fmt.Sprintf("GALAXY_INSTANCE=%s", strconv.FormatInt(int64(instanceId), 10)))
publicDns, err := EC2PublicHostname()
if err != nil {
log.Warnf("Unable to determine public hostname. Not on AWS? %s", err)
publicDns = "127.0.0.1"
}
envVars = append(envVars, fmt.Sprintf("PUBLIC_HOSTNAME=%s", publicDns))
containerName := appCfg.ContainerName() + "." + strconv.FormatInt(int64(instanceId), 10)
container, err := s.dockerClient.InspectContainer(containerName)
_, ok := err.(*docker.NoSuchContainer)
if err != nil && !ok {
return nil, err
}
// Existing container is running or stopped. If the image has changed, stop
// and re-create it.
if container != nil && container.Image != image.ID {
if container.State.Running || container.State.Restarting || container.State.Paused {
log.Printf("Stopping %s version %s running as %s", appCfg.Name(), appCfg.Version(), container.ID[0:12])
err := s.dockerClient.StopContainer(container.ID, 10)
if err != nil {
return nil, err
}
}
log.Printf("Removing %s version %s running as %s", appCfg.Name(), appCfg.Version(), container.ID[0:12])
err = s.dockerClient.RemoveContainer(docker.RemoveContainerOptions{
ID: container.ID,
})
if err != nil {
return nil, err
}
container = nil
}
if container == nil {
config := &docker.Config{
Image: img,
Env: envVars,
}
mem := appCfg.GetMemory(pool)
if mem != "" {
m, err := utils.ParseMemory(mem)
if err != nil {
return nil, err
}
config.Memory = m
}
cpu := appCfg.GetCPUShares(pool)
if cpu != "" {
if c, err := strconv.Atoi(cpu); err == nil {
config.CPUShares = int64(c)
}
}
log.Printf("Creating %s version %s", appCfg.Name(), appCfg.Version())
container, err = s.dockerClient.CreateContainer(docker.CreateContainerOptions{
Name: containerName,
Config: config,
})
if err != nil {
return nil, err
//.........這裏部分代碼省略.........
示例2: StartInteractive
func (s *ServiceRuntime) StartInteractive(env, pool string, appCfg config.App) error {
// see if we have the image locally
fmt.Fprintf(os.Stderr, "Pulling latest image for %s\n", appCfg.Version())
_, err := s.PullImage(appCfg.Version(), appCfg.VersionID())
if err != nil {
return err
}
args := []string{
"run", "--rm", "-i",
}
args = append(args, "-e")
args = append(args, "ENV"+"="+env)
for key, value := range appCfg.Env() {
if key == "ENV" {
continue
}
args = append(args, "-e")
args = append(args, strings.ToUpper(key)+"="+s.replaceVarEnv(value, s.hostIP))
}
args = append(args, "-e")
args = append(args, fmt.Sprintf("HOST_IP=%s", s.hostIP))
if s.dns != "" {
args = append(args, "--dns")
args = append(args, s.dns)
}
args = append(args, "-e")
args = append(args, fmt.Sprintf("GALAXY_APP=%s", appCfg.Name()))
args = append(args, "-e")
args = append(args, fmt.Sprintf("GALAXY_VERSION=%s", strconv.FormatInt(appCfg.ID(), 10)))
instanceId, err := s.NextInstanceSlot(appCfg.Name(), strconv.FormatInt(appCfg.ID(), 10))
if err != nil {
return err
}
args = append(args, "-e")
args = append(args, fmt.Sprintf("GALAXY_INSTANCE=%s", strconv.FormatInt(int64(instanceId), 10)))
publicDns, err := EC2PublicHostname()
if err != nil {
log.Warnf("Unable to determine public hostname. Not on AWS? %s", err)
publicDns = "127.0.0.1"
}
args = append(args, "-e")
args = append(args, fmt.Sprintf("PUBLIC_HOSTNAME=%s", publicDns))
mem := appCfg.GetMemory(pool)
if mem != "" {
args = append(args, "-m")
args = append(args, mem)
}
cpu := appCfg.GetCPUShares(pool)
if cpu != "" {
args = append(args, "-c")
args = append(args, cpu)
}
args = append(args, []string{"-t", appCfg.Version(), "/bin/bash"}...)
// shell out to docker run to get signal forwarded and terminal setup correctly
//cmd := exec.Command("docker", "run", "-rm", "-i", "-t", appCfg.Version(), "/bin/bash")
cmd := exec.Command("docker", args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Start()
if err != nil {
log.Fatal(err)
}
err = cmd.Wait()
if err != nil {
fmt.Fprintf(os.Stderr, "Command finished with error: %v\n", err)
}
return err
}