1
0
mirror of https://github.com/rancher/os.git synced 2025-06-30 16:51:47 +00:00

Add ability to tail console on startup

This commit is contained in:
Darren Shepherd 2015-03-14 22:21:22 -07:00
parent a94fa20b42
commit c770598a53
2 changed files with 38 additions and 12 deletions

View File

@ -170,19 +170,39 @@ func runContainers(cfg *config.Config) error {
return runContainersFrom("", cfg, containerConfigs)
}
func launchConsole(cfg *config.Config) error {
if !util.IsRunningInTty() {
func tailConsole(cfg *config.Config) error {
if !cfg.Console.Tail {
return nil
}
log.Debugf("Attaching to console")
cmd := exec.Command("docker", "attach", "console")
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Start()
client, err := docker.NewSystemClient()
if err != nil {
return err
}
return cmd.Wait()
for _, container := range cfg.SystemContainers {
if container.Id != config.CONSOLE_CONTAINER {
continue
}
c := docker.NewContainer(config.DOCKER_SYSTEM_HOST, &container).Lookup()
if c.Err != nil {
continue
}
log.Infof("Tailing console : %s", c.Name)
return client.Logs(dockerClient.LogsOptions{
Container: c.Name,
Stdout: true,
Stderr: true,
Follow: true,
OutputStream: os.Stdout,
ErrorStream: os.Stderr,
})
}
log.Error("Console not found")
return nil
}
func sysInit() error {
@ -198,7 +218,7 @@ func sysInit() error {
syscall.Sync()
return nil
},
//launchConsole,
tailConsole,
}
return config.RunInitFuncs(cfg, initFuncs)

View File

@ -32,21 +32,27 @@ type Config struct {
Dns []string `yaml:"dns,flow,omitempty"`
//Rescue bool `yaml:"rescue,omitempty"`
//RescueContainer *ContainerConfig `yaml:"rescue_container,omitempty"`
Console ConsoleConfig `yaml:"console,omitempty"`
State ConfigState `yaml:"state,omitempty"`
Userdocker UserDockerConfig `yaml:"userdocker,omitempty"`
UpgradeConfig UpgradeConfig `yaml:"upgrade,omitempty"`
Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
BootstrapContainers []ContainerConfig `yaml:"bootstrap_containers,omitempty"`
SystemContainers []ContainerConfig `yaml:"system_containers,omitempty"`
UserContainers []ContainerConfig `yaml:"user_containers,omitempty"`
SystemDockerArgs []string `yaml:"system_docker_args,flow,omitempty"`
Modules []string `yaml:"modules,omitempty"`
CloudInit CloudInit `yaml:"cloud_init,omitempty"`
SshConfig SshConfig `yaml:"ssh,omitempty"`
Ssh SshConfig `yaml:"ssh,omitempty"`
EnabledAddons []string `yaml:"enabled_addons,omitempty"`
Addons map[string]Config `yaml:"addons,omitempty"`
Network NetworkConfig `yaml:"network,omitempty"`
}
type ConsoleConfig struct {
Tail bool `yaml:"tail,omitempty"`
Ephemeral bool `yaml:"ephemeral,omitempty"`
}
type UpgradeConfig struct {
Url string `yaml:"url,omitempty"`
}