mirror of
https://github.com/rancher/os.git
synced 2025-09-01 06:40:31 +00:00
Random changes
This commit is contained in:
@@ -4,13 +4,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
dockerClient "github.com/fsouza/go-dockerclient"
|
dockerClient "github.com/fsouza/go-dockerclient"
|
||||||
"github.com/rancherio/os/config"
|
"github.com/rancherio/os/config"
|
||||||
"github.com/rancherio/os/docker"
|
"github.com/rancherio/os/docker"
|
||||||
initPkg "github.com/rancherio/os/init"
|
initPkg "github.com/rancherio/os/init"
|
||||||
|
"github.com/rancherio/os/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SysInit() {
|
func SysInit() {
|
||||||
@@ -67,7 +67,6 @@ func findImages(cfg *config.Config) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, fileName := range files {
|
for _, fileName := range files {
|
||||||
log.Debugf("Checking %s", fileName)
|
|
||||||
if ok, _ := path.Match(cfg.ImagesPattern, fileName); ok {
|
if ok, _ := path.Match(cfg.ImagesPattern, fileName); ok {
|
||||||
log.Debugf("Found %s", fileName)
|
log.Debugf("Found %s", fileName)
|
||||||
result = append(result, fileName)
|
result = append(result, fileName)
|
||||||
@@ -115,35 +114,53 @@ func loadImages(cfg *config.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runContainers(cfg *config.Config) error {
|
func runContainers(cfg *config.Config) error {
|
||||||
containers := cfg.SystemContainers
|
containerConfigs := cfg.SystemContainers
|
||||||
if cfg.Rescue {
|
if cfg.Rescue {
|
||||||
log.Debug("Running rescue container")
|
log.Debug("Running rescue container")
|
||||||
containers = []config.ContainerConfig{cfg.RescueContainer}
|
containerConfigs = []config.ContainerConfig{cfg.RescueContainer}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, container := range containers {
|
for _, containerConfig := range containerConfigs {
|
||||||
args := append([]string{"run"}, container.Options...)
|
if util.Contains(cfg.Disable, containerConfig.Id) {
|
||||||
args = append(args, container.Image)
|
log.Debugf("%s is disabled", containerConfig.Id)
|
||||||
args = append(args, container.Args...)
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command(cfg.DockerBin, args...)
|
err := docker.StartAndWait(cfg, &containerConfig)
|
||||||
cmd.Stderr = os.Stderr
|
log.Debugf("Running %s", containerConfig.Id)
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
|
|
||||||
//log.Infof("Is a tty : %v", term.IsTerminal(0))
|
|
||||||
//log.Infof("Is a tty : %v", term.IsTerminal(1))
|
|
||||||
//log.Infof("Is a tty : %v", term.IsTerminal(2))
|
|
||||||
log.Debugf("Running %s", strings.Join(args, " "))
|
|
||||||
err := cmd.Run()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to run %v: %v", args, err)
|
log.Errorf("Failed to run %v: %v", containerConfig.Id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func launchConsole(cfg *config.Config) error {
|
||||||
|
|
||||||
|
cmd := exec.Command("docker", "attach", "console")
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Start()
|
||||||
|
|
||||||
|
return cmd.Wait()
|
||||||
|
//console := cfg.GetContainerById(cfg.ConsoleContainer)
|
||||||
|
//if console == nil {
|
||||||
|
// return nil
|
||||||
|
//}
|
||||||
|
|
||||||
|
//c, err := docker.ParseContainer(cfg, console)
|
||||||
|
//if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
|
||||||
|
//return c.Attach()
|
||||||
|
|
||||||
|
//return nil
|
||||||
|
}
|
||||||
|
|
||||||
func sysInit() error {
|
func sysInit() error {
|
||||||
cfg, err := config.LoadConfig()
|
cfg, err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -153,6 +170,7 @@ func sysInit() error {
|
|||||||
initFuncs := []config.InitFunc{
|
initFuncs := []config.InitFunc{
|
||||||
loadImages,
|
loadImages,
|
||||||
runContainers,
|
runContainers,
|
||||||
|
//launchConsole,
|
||||||
}
|
}
|
||||||
|
|
||||||
return config.RunInitFuncs(cfg, initFuncs)
|
return config.RunInitFuncs(cfg, initFuncs)
|
||||||
|
Reference in New Issue
Block a user