1
0
mirror of https://github.com/rancher/os.git synced 2025-09-04 16:21:07 +00:00

Further cleanup and refactoring

This commit is contained in:
Darren Shepherd
2015-02-19 20:05:43 -07:00
parent e211279636
commit f84aa02276
9 changed files with 83 additions and 48 deletions

View File

@@ -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)
}

View File

@@ -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
},

View File

@@ -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
}

View File

@@ -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 " +

View File

@@ -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])

View File

@@ -1,3 +1,3 @@
FROM console
FROM base
COPY scripts/dockerimages/scripts/ntp.sh /
CMD ["/ntp.sh"]

View File

@@ -1,3 +1,3 @@
FROM console
FROM base
COPY scripts/dockerimages/scripts/syslog.sh /
CMD ["/syslog.sh"]

View File

@@ -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"

View File

@@ -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