mirror of
https://github.com/rancher/os.git
synced 2025-07-01 17:21:50 +00:00
Add ability to tail console on startup
This commit is contained in:
parent
a94fa20b42
commit
c770598a53
@ -170,19 +170,39 @@ func runContainers(cfg *config.Config) error {
|
|||||||
return runContainersFrom("", cfg, containerConfigs)
|
return runContainersFrom("", cfg, containerConfigs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func launchConsole(cfg *config.Config) error {
|
func tailConsole(cfg *config.Config) error {
|
||||||
if !util.IsRunningInTty() {
|
if !cfg.Console.Tail {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Attaching to console")
|
client, err := docker.NewSystemClient()
|
||||||
cmd := exec.Command("docker", "attach", "console")
|
if err != nil {
|
||||||
cmd.Stdout = os.Stdout
|
return err
|
||||||
cmd.Stdin = os.Stdin
|
}
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
cmd.Start()
|
|
||||||
|
|
||||||
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 {
|
func sysInit() error {
|
||||||
@ -198,7 +218,7 @@ func sysInit() error {
|
|||||||
syscall.Sync()
|
syscall.Sync()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
//launchConsole,
|
tailConsole,
|
||||||
}
|
}
|
||||||
|
|
||||||
return config.RunInitFuncs(cfg, initFuncs)
|
return config.RunInitFuncs(cfg, initFuncs)
|
||||||
|
@ -32,21 +32,27 @@ type Config struct {
|
|||||||
Dns []string `yaml:"dns,flow,omitempty"`
|
Dns []string `yaml:"dns,flow,omitempty"`
|
||||||
//Rescue bool `yaml:"rescue,omitempty"`
|
//Rescue bool `yaml:"rescue,omitempty"`
|
||||||
//RescueContainer *ContainerConfig `yaml:"rescue_container,omitempty"`
|
//RescueContainer *ContainerConfig `yaml:"rescue_container,omitempty"`
|
||||||
|
Console ConsoleConfig `yaml:"console,omitempty"`
|
||||||
State ConfigState `yaml:"state,omitempty"`
|
State ConfigState `yaml:"state,omitempty"`
|
||||||
Userdocker UserDockerConfig `yaml:"userdocker,omitempty"`
|
Userdocker UserDockerConfig `yaml:"userdocker,omitempty"`
|
||||||
UpgradeConfig UpgradeConfig `yaml:"upgrade,omitempty"`
|
Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
|
||||||
BootstrapContainers []ContainerConfig `yaml:"bootstrap_containers,omitempty"`
|
BootstrapContainers []ContainerConfig `yaml:"bootstrap_containers,omitempty"`
|
||||||
SystemContainers []ContainerConfig `yaml:"system_containers,omitempty"`
|
SystemContainers []ContainerConfig `yaml:"system_containers,omitempty"`
|
||||||
UserContainers []ContainerConfig `yaml:"user_containers,omitempty"`
|
UserContainers []ContainerConfig `yaml:"user_containers,omitempty"`
|
||||||
SystemDockerArgs []string `yaml:"system_docker_args,flow,omitempty"`
|
SystemDockerArgs []string `yaml:"system_docker_args,flow,omitempty"`
|
||||||
Modules []string `yaml:"modules,omitempty"`
|
Modules []string `yaml:"modules,omitempty"`
|
||||||
CloudInit CloudInit `yaml:"cloud_init,omitempty"`
|
CloudInit CloudInit `yaml:"cloud_init,omitempty"`
|
||||||
SshConfig SshConfig `yaml:"ssh,omitempty"`
|
Ssh SshConfig `yaml:"ssh,omitempty"`
|
||||||
EnabledAddons []string `yaml:"enabled_addons,omitempty"`
|
EnabledAddons []string `yaml:"enabled_addons,omitempty"`
|
||||||
Addons map[string]Config `yaml:"addons,omitempty"`
|
Addons map[string]Config `yaml:"addons,omitempty"`
|
||||||
Network NetworkConfig `yaml:"network,omitempty"`
|
Network NetworkConfig `yaml:"network,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ConsoleConfig struct {
|
||||||
|
Tail bool `yaml:"tail,omitempty"`
|
||||||
|
Ephemeral bool `yaml:"ephemeral,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type UpgradeConfig struct {
|
type UpgradeConfig struct {
|
||||||
Url string `yaml:"url,omitempty"`
|
Url string `yaml:"url,omitempty"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user