示例#1
0
func Main() {
	if len(os.Args) != 2 {
		log.Fatal("Must specify exactly one existing container")
	}
	newConsole := os.Args[1]

	cfg := config.LoadConfig()

	project, err := compose.GetProject(cfg, true, false)
	if err != nil {
		log.Fatal(err)
	}

	if newConsole != "default" {
		if err = compose.LoadService(project, cfg, true, newConsole); err != nil {
			log.Fatal(err)
		}
	}

	if err = config.Set("rancher.console", newConsole); err != nil {
		log.Errorf("Failed to update 'rancher.console': %v", err)
	}

	if err = project.Up(context.Background(), options.Up{
		Log: true,
	}, "console"); err != nil {
		log.Fatal(err)
	}

	if err = project.Restart(context.Background(), 10, "docker"); err != nil {
		log.Errorf("Failed to restart Docker: %v", err)
	}
}
示例#2
0
文件: service.go 项目: coderjoe/os
func (s *Service) shouldRebuild(ctx context.Context) (bool, error) {
	containers, err := s.Containers(ctx)
	if err != nil {
		return false, err
	}
	cfg := config.LoadConfig()
	for _, c := range containers {
		outOfSync, err := c.(*docker.Container).OutOfSync(ctx, s.Service.Config().Image)
		if err != nil {
			return false, err
		}

		_, containerInfo, err := s.getContainer(ctx)
		if err != nil {
			return false, err
		}
		name := containerInfo.Name[1:]

		origRebuildLabel := containerInfo.Config.Labels[config.REBUILD]
		newRebuildLabel := s.Config().Labels[config.REBUILD]
		rebuildLabelChanged := newRebuildLabel != origRebuildLabel
		logrus.WithFields(logrus.Fields{
			"origRebuildLabel":    origRebuildLabel,
			"newRebuildLabel":     newRebuildLabel,
			"rebuildLabelChanged": rebuildLabelChanged,
			"outOfSync":           outOfSync}).Debug("Rebuild values")

		if newRebuildLabel == "always" {
			return true, nil
		}
		if outOfSync {
			if s.Name() == "console" {
				if cfg.Rancher.ForceConsoleRebuild {
					if err := config.Set("rancher.force_console_rebuild", false); err != nil {
						return false, err
					}
					return true, nil
				}
				origConsoleLabel := containerInfo.Config.Labels[config.CONSOLE]
				newConsoleLabel := s.Config().Labels[config.CONSOLE]
				if newConsoleLabel != origConsoleLabel {
					return true, nil
				}
			} else if rebuildLabelChanged || origRebuildLabel != "false" {
				return true, nil
			} else {
				logrus.Warnf("%s needs rebuilding", name)
			}
		}
	}
	return false, nil
}
示例#3
0
文件: config.go 项目: coderjoe/os
func configSet(c *cli.Context) error {
	key := c.Args().Get(0)
	value := c.Args().Get(1)
	if key == "" {
		return nil
	}

	err := config.Set(key, value)
	if err != nil {
		log.Fatal(err)
	}

	return nil
}
示例#4
0
文件: console.go 项目: xingdl2007/os
func consoleEnable(c *cli.Context) error {
	if len(c.Args()) != 1 {
		log.Fatal("Must specify exactly one console to enable")
	}
	newConsole := c.Args()[0]

	cfg := config.LoadConfig()

	if newConsole != "default" {
		if err := compose.StageServices(cfg, newConsole); err != nil {
			return err
		}
	}

	if err := config.Set("rancher.console", newConsole); err != nil {
		log.Errorf("Failed to update 'rancher.console': %v", err)
	}

	return nil
}