diff --git a/cmd/respawn/respawn.go b/cmd/respawn/respawn.go index 620a4912..66271e2d 100644 --- a/cmd/respawn/respawn.go +++ b/cmd/respawn/respawn.go @@ -1,6 +1,7 @@ package respawn import ( + "io" "io/ioutil" "os" "os/exec" @@ -9,10 +10,38 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/codegangsta/cli" ) func Main() { - input, err := ioutil.ReadAll(os.Stdin) + app := cli.NewApp() + + app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "file, f", + Usage: "Optional config file to load", + }, + } + app.Action = run + + app.Run(os.Args) + +} + +func run(c *cli.Context) { + var stream io.Reader = os.Stdin + var err error + + inputFileName := c.String("file") + + if inputFileName != "" { + stream, err = os.Open(inputFileName) + if err != nil { + log.Fatal(err) + } + } + + input, err := ioutil.ReadAll(stream) if err != nil { panic(err) } diff --git a/cmd/sysinit/sysinit.go b/cmd/sysinit/sysinit.go index 9071d033..64af141f 100644 --- a/cmd/sysinit/sysinit.go +++ b/cmd/sysinit/sysinit.go @@ -163,19 +163,6 @@ func launchConsole(cfg *config.Config) error { 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 { @@ -188,7 +175,6 @@ func sysInit() error { loadImages, runContainers, func(cfg *config.Config) error { - //TODO: not totally sure why we need this. syscall.Sync() return nil }, diff --git a/config/config.go b/config/config.go index 3825180c..040ef376 100644 --- a/config/config.go +++ b/config/config.go @@ -46,14 +46,14 @@ type Config struct { RescueContainer *ContainerConfig `yaml:"rescue_container,omitempty"` State ConfigState `yaml:"state,omitempty"` Userdocker UserDockerInfo `yaml:"userdocker,omitempty"` - CloudConfig []string `yaml:"cloud_config,omitempty"` SystemContainers []ContainerConfig `yaml:"system_containers,omitempty"` SystemDockerArgs []string `yaml:"system_docker_args,flow,omitempty"` Modules []string `yaml:"modules,omitempty"` + CloudInit CloudInit `yaml:"cloud_init"` } type UserDockerInfo struct { - UseTLS bool `yaml:"use_tls,omitempty"` + UseTLS bool `yaml:"use_tls"` TLSServerCert string `yaml:"tls_server_cert"` TLSServerKey string `yaml:"tls_server_key"` TLSCACert string `yaml:"tls_ca_cert"` @@ -65,6 +65,10 @@ type ConfigState struct { Required bool `yaml:"required"` } +type CloudInit struct { + Datasources []string `yaml:"datasources"` +} + func (c *Config) Merge(newConfig Config) (bool, error) { //Efficient? Nope, but computers are fast newConfig.ClearReadOnly() @@ -73,6 +77,8 @@ func (c *Config) Merge(newConfig Config) (bool, error) { return false, err } + log.Debugf("Input \n%s", string(content)) + err = yaml.Unmarshal([]byte(content), c) return true, err } @@ -116,7 +122,18 @@ func LoadConfig() (*Config, error) { func (c *Config) readArgs() error { log.Debug("Reading config args") - cmdLine := strings.Join(os.Args[1:], " ") + parts := make([]string, len(os.Args)) + + for _, arg := range os.Args[1:] { + if strings.HasPrefix(arg, "--") { + arg = arg[2:] + } + + arg = strings.Replace(arg, "-", ".", -1) + parts = append(parts, arg) + } + + cmdLine := strings.Join(parts, " ") if len(cmdLine) == 0 { return nil } diff --git a/config/default.go b/config/default.go index db00ba49..6bdb90f9 100644 --- a/config/default.go +++ b/config/default.go @@ -17,7 +17,6 @@ func NewConfig() *Config { Userdocker: UserDockerInfo{ UseTLS: true, }, - CloudConfig: []string{}, SystemContainers: []ContainerConfig{ { Cmd: "--name=system-volumes " + @@ -29,19 +28,25 @@ func NewConfig() *Config { "state", }, { - Cmd: "--name=console-volumes " + + Cmd: "--name=command-volumes " + "--net=none " + "--read-only " + "-v=/init:/sbin/halt:ro " + "-v=/init:/sbin/poweroff:ro " + "-v=/init:/sbin/reboot:ro " + - "-v=/init:/sbin/tlsconf:ro " + + "-v=/init:/usr/bin/cloud-init:ro " + "-v=/init:/usr/bin/tlsconf:ro " + "-v=/init:/usr/bin/rancherctl:ro " + "-v=/init:/usr/bin/respawn:ro " + "-v=/init:/usr/bin/system-docker:ro " + "-v=/lib/modules:/lib/modules:ro " + "-v=/usr/bin/docker:/usr/bin/docker:ro " + + "state", + }, + { + Cmd: "--name=user-volumes " + + "--net=none " + + "--read-only " + "-v=/var/lib/rancher/state/home:/home " + "-v=/var/lib/rancher/state/opt:/opt " + "state", @@ -56,11 +61,11 @@ func NewConfig() *Config { "udev", }, { - Cmd: "--name=cloudconfig " + + Cmd: "--name=cloud-init " + + "--rm " + "--net=host " + - "-v=/init:/usr/bin/rancherctl:ro " + - "-v=/init:/usr/bin/cloudinit:ro " + - "cloudconfig", + "--volumes-from=command-volumes " + + "cloudinit", }, { Cmd: "--name=network " + @@ -77,6 +82,14 @@ func NewConfig() *Config { "--net=host " + "ntp", }, + { + Cmd: "--name=syslog " + + "-d " + + "--rm " + + "--privileged " + + "--net=host " + + "syslog", + }, { Cmd: "--name=userdocker " + "-d " + @@ -86,11 +99,9 @@ func NewConfig() *Config { "--pid=host " + "--net=host " + "--privileged " + - "--volumes-from=console-volumes " + + "--volumes-from=command-volumes " + + "--volumes-from=user-volumes " + "--volumes-from=system-volumes " + - "-v=/usr/bin/docker:/usr/bin/docker:ro " + - "-v=/init:/usr/bin/tlsconf:ro " + - "-v=/init:/usr/sbin/rancherctl:ro " + "-v=/var/lib/rancher/state/docker:/var/lib/docker " + "userdocker", }, @@ -99,20 +110,14 @@ func NewConfig() *Config { "-d " + "--rm " + "--privileged " + - "--volumes-from=console-volumes " + + "--volumes-from=command-volumes " + + "--volumes-from=user-volumes " + "--volumes-from=system-volumes " + "--ipc=host " + "--net=host " + "--pid=host " + "console", }, - { - Cmd: "--name=syslog " + - "-d " + - "--privileged " + - "--net=host " + - "syslog", - }, }, RescueContainer: &ContainerConfig{ Cmd: "--name=rescue " + diff --git a/main.go b/main.go index 5d7f1178..24495a3a 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,7 @@ func main() { registerCmd("/usr/bin/respawn", respawn.Main) registerCmd("/usr/sbin/rancherctl", control.Main) registerCmd("/usr/bin/tlsconf", tlsconf.Main) - registerCmd("/usr/bin/cloudinit", cloudinit.Main) + registerCmd("/usr/bin/cloud-init", cloudinit.Main) if !reexec.Init() { log.Fatalf("Failed to find an entry point for %s", os.Args[0]) diff --git a/scripts/dockerimages/08-ntp b/scripts/dockerimages/08-ntp index b0d65f88..f13d0083 100644 --- a/scripts/dockerimages/08-ntp +++ b/scripts/dockerimages/08-ntp @@ -1,3 +1,3 @@ -FROM console +FROM base COPY scripts/dockerimages/scripts/ntp.sh / CMD ["/ntp.sh"] diff --git a/scripts/dockerimages/09-syslog b/scripts/dockerimages/09-syslog index 04052bcb..e0d41abb 100644 --- a/scripts/dockerimages/09-syslog +++ b/scripts/dockerimages/09-syslog @@ -1,3 +1,3 @@ -FROM console +FROM base COPY scripts/dockerimages/scripts/syslog.sh / CMD ["/syslog.sh"] diff --git a/scripts/dockerimages/scripts/cloud-init.sh b/scripts/dockerimages/scripts/cloud-init.sh index 021c74a9..ce43f1e7 100755 --- a/scripts/dockerimages/scripts/cloud-init.sh +++ b/scripts/dockerimages/scripts/cloud-init.sh @@ -4,4 +4,4 @@ set -x -e CLOUD_CONFIG_FLAGS=$(rancherctl config get cloud_config) -cloudinit --preinit "$CLOUD_CONFIG_FLAGS" +cloud-init --preinit "$CLOUD_CONFIG_FLAGS" diff --git a/scripts/dockerimages/scripts/console.sh b/scripts/dockerimages/scripts/console.sh index 8ac0366e..48d7861f 100755 --- a/scripts/dockerimages/scripts/console.sh +++ b/scripts/dockerimages/scripts/console.sh @@ -1,15 +1,12 @@ #!/bin/sh -#if [ -t 1 ]; then - #exec /bin/sh -#else - CLOUD_CONFIG_FILE=/var/lib/rancher/cloud-config if [ -s $CLOUD_CONFIG_FILE ]; then - cloudinit --from-file $CLOUD_CONFIG_FILE + cloud-init --from-file $CLOUD_CONFIG_FILE fi - exec respawn << EOF + +cat > /etc/respawn.conf << EOF /sbin/getty 115200 tty1 /sbin/getty 115200 tty2 /sbin/getty 115200 tty3 @@ -17,4 +14,5 @@ fi /sbin/getty 115200 tty5 /sbin/getty 115200 tty6 EOF -#fi + +exec respawn -f /etc/respawn.conf