mirror of
https://github.com/rancher/os.git
synced 2025-09-03 07:44:21 +00:00
Further cleanup and refactoring
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package respawn
|
package respawn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -9,10 +10,38 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Main() {
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@@ -163,19 +163,6 @@ func launchConsole(cfg *config.Config) error {
|
|||||||
cmd.Start()
|
cmd.Start()
|
||||||
|
|
||||||
return cmd.Wait()
|
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 {
|
||||||
@@ -188,7 +175,6 @@ func sysInit() error {
|
|||||||
loadImages,
|
loadImages,
|
||||||
runContainers,
|
runContainers,
|
||||||
func(cfg *config.Config) error {
|
func(cfg *config.Config) error {
|
||||||
//TODO: not totally sure why we need this.
|
|
||||||
syscall.Sync()
|
syscall.Sync()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@@ -46,14 +46,14 @@ type Config struct {
|
|||||||
RescueContainer *ContainerConfig `yaml:"rescue_container,omitempty"`
|
RescueContainer *ContainerConfig `yaml:"rescue_container,omitempty"`
|
||||||
State ConfigState `yaml:"state,omitempty"`
|
State ConfigState `yaml:"state,omitempty"`
|
||||||
Userdocker UserDockerInfo `yaml:"userdocker,omitempty"`
|
Userdocker UserDockerInfo `yaml:"userdocker,omitempty"`
|
||||||
CloudConfig []string `yaml:"cloud_config,omitempty"`
|
|
||||||
SystemContainers []ContainerConfig `yaml:"system_containers,omitempty"`
|
SystemContainers []ContainerConfig `yaml:"system_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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserDockerInfo struct {
|
type UserDockerInfo struct {
|
||||||
UseTLS bool `yaml:"use_tls,omitempty"`
|
UseTLS bool `yaml:"use_tls"`
|
||||||
TLSServerCert string `yaml:"tls_server_cert"`
|
TLSServerCert string `yaml:"tls_server_cert"`
|
||||||
TLSServerKey string `yaml:"tls_server_key"`
|
TLSServerKey string `yaml:"tls_server_key"`
|
||||||
TLSCACert string `yaml:"tls_ca_cert"`
|
TLSCACert string `yaml:"tls_ca_cert"`
|
||||||
@@ -65,6 +65,10 @@ type ConfigState struct {
|
|||||||
Required bool `yaml:"required"`
|
Required bool `yaml:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CloudInit struct {
|
||||||
|
Datasources []string `yaml:"datasources"`
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) Merge(newConfig Config) (bool, error) {
|
func (c *Config) Merge(newConfig Config) (bool, error) {
|
||||||
//Efficient? Nope, but computers are fast
|
//Efficient? Nope, but computers are fast
|
||||||
newConfig.ClearReadOnly()
|
newConfig.ClearReadOnly()
|
||||||
@@ -73,6 +77,8 @@ func (c *Config) Merge(newConfig Config) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("Input \n%s", string(content))
|
||||||
|
|
||||||
err = yaml.Unmarshal([]byte(content), c)
|
err = yaml.Unmarshal([]byte(content), c)
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
@@ -116,7 +122,18 @@ func LoadConfig() (*Config, error) {
|
|||||||
|
|
||||||
func (c *Config) readArgs() error {
|
func (c *Config) readArgs() error {
|
||||||
log.Debug("Reading config args")
|
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 {
|
if len(cmdLine) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,6 @@ func NewConfig() *Config {
|
|||||||
Userdocker: UserDockerInfo{
|
Userdocker: UserDockerInfo{
|
||||||
UseTLS: true,
|
UseTLS: true,
|
||||||
},
|
},
|
||||||
CloudConfig: []string{},
|
|
||||||
SystemContainers: []ContainerConfig{
|
SystemContainers: []ContainerConfig{
|
||||||
{
|
{
|
||||||
Cmd: "--name=system-volumes " +
|
Cmd: "--name=system-volumes " +
|
||||||
@@ -29,19 +28,25 @@ func NewConfig() *Config {
|
|||||||
"state",
|
"state",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Cmd: "--name=console-volumes " +
|
Cmd: "--name=command-volumes " +
|
||||||
"--net=none " +
|
"--net=none " +
|
||||||
"--read-only " +
|
"--read-only " +
|
||||||
"-v=/init:/sbin/halt:ro " +
|
"-v=/init:/sbin/halt:ro " +
|
||||||
"-v=/init:/sbin/poweroff:ro " +
|
"-v=/init:/sbin/poweroff:ro " +
|
||||||
"-v=/init:/sbin/reboot: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/tlsconf:ro " +
|
||||||
"-v=/init:/usr/bin/rancherctl:ro " +
|
"-v=/init:/usr/bin/rancherctl:ro " +
|
||||||
"-v=/init:/usr/bin/respawn:ro " +
|
"-v=/init:/usr/bin/respawn:ro " +
|
||||||
"-v=/init:/usr/bin/system-docker:ro " +
|
"-v=/init:/usr/bin/system-docker:ro " +
|
||||||
"-v=/lib/modules:/lib/modules:ro " +
|
"-v=/lib/modules:/lib/modules:ro " +
|
||||||
"-v=/usr/bin/docker:/usr/bin/docker: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/home:/home " +
|
||||||
"-v=/var/lib/rancher/state/opt:/opt " +
|
"-v=/var/lib/rancher/state/opt:/opt " +
|
||||||
"state",
|
"state",
|
||||||
@@ -56,11 +61,11 @@ func NewConfig() *Config {
|
|||||||
"udev",
|
"udev",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Cmd: "--name=cloudconfig " +
|
Cmd: "--name=cloud-init " +
|
||||||
|
"--rm " +
|
||||||
"--net=host " +
|
"--net=host " +
|
||||||
"-v=/init:/usr/bin/rancherctl:ro " +
|
"--volumes-from=command-volumes " +
|
||||||
"-v=/init:/usr/bin/cloudinit:ro " +
|
"cloudinit",
|
||||||
"cloudconfig",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Cmd: "--name=network " +
|
Cmd: "--name=network " +
|
||||||
@@ -77,6 +82,14 @@ func NewConfig() *Config {
|
|||||||
"--net=host " +
|
"--net=host " +
|
||||||
"ntp",
|
"ntp",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Cmd: "--name=syslog " +
|
||||||
|
"-d " +
|
||||||
|
"--rm " +
|
||||||
|
"--privileged " +
|
||||||
|
"--net=host " +
|
||||||
|
"syslog",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Cmd: "--name=userdocker " +
|
Cmd: "--name=userdocker " +
|
||||||
"-d " +
|
"-d " +
|
||||||
@@ -86,11 +99,9 @@ func NewConfig() *Config {
|
|||||||
"--pid=host " +
|
"--pid=host " +
|
||||||
"--net=host " +
|
"--net=host " +
|
||||||
"--privileged " +
|
"--privileged " +
|
||||||
"--volumes-from=console-volumes " +
|
"--volumes-from=command-volumes " +
|
||||||
|
"--volumes-from=user-volumes " +
|
||||||
"--volumes-from=system-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 " +
|
"-v=/var/lib/rancher/state/docker:/var/lib/docker " +
|
||||||
"userdocker",
|
"userdocker",
|
||||||
},
|
},
|
||||||
@@ -99,20 +110,14 @@ func NewConfig() *Config {
|
|||||||
"-d " +
|
"-d " +
|
||||||
"--rm " +
|
"--rm " +
|
||||||
"--privileged " +
|
"--privileged " +
|
||||||
"--volumes-from=console-volumes " +
|
"--volumes-from=command-volumes " +
|
||||||
|
"--volumes-from=user-volumes " +
|
||||||
"--volumes-from=system-volumes " +
|
"--volumes-from=system-volumes " +
|
||||||
"--ipc=host " +
|
"--ipc=host " +
|
||||||
"--net=host " +
|
"--net=host " +
|
||||||
"--pid=host " +
|
"--pid=host " +
|
||||||
"console",
|
"console",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Cmd: "--name=syslog " +
|
|
||||||
"-d " +
|
|
||||||
"--privileged " +
|
|
||||||
"--net=host " +
|
|
||||||
"syslog",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
RescueContainer: &ContainerConfig{
|
RescueContainer: &ContainerConfig{
|
||||||
Cmd: "--name=rescue " +
|
Cmd: "--name=rescue " +
|
||||||
|
2
main.go
2
main.go
@@ -44,7 +44,7 @@ func main() {
|
|||||||
registerCmd("/usr/bin/respawn", respawn.Main)
|
registerCmd("/usr/bin/respawn", respawn.Main)
|
||||||
registerCmd("/usr/sbin/rancherctl", control.Main)
|
registerCmd("/usr/sbin/rancherctl", control.Main)
|
||||||
registerCmd("/usr/bin/tlsconf", tlsconf.Main)
|
registerCmd("/usr/bin/tlsconf", tlsconf.Main)
|
||||||
registerCmd("/usr/bin/cloudinit", cloudinit.Main)
|
registerCmd("/usr/bin/cloud-init", cloudinit.Main)
|
||||||
|
|
||||||
if !reexec.Init() {
|
if !reexec.Init() {
|
||||||
log.Fatalf("Failed to find an entry point for %s", os.Args[0])
|
log.Fatalf("Failed to find an entry point for %s", os.Args[0])
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
FROM console
|
FROM base
|
||||||
COPY scripts/dockerimages/scripts/ntp.sh /
|
COPY scripts/dockerimages/scripts/ntp.sh /
|
||||||
CMD ["/ntp.sh"]
|
CMD ["/ntp.sh"]
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
FROM console
|
FROM base
|
||||||
COPY scripts/dockerimages/scripts/syslog.sh /
|
COPY scripts/dockerimages/scripts/syslog.sh /
|
||||||
CMD ["/syslog.sh"]
|
CMD ["/syslog.sh"]
|
||||||
|
@@ -4,4 +4,4 @@ set -x -e
|
|||||||
|
|
||||||
CLOUD_CONFIG_FLAGS=$(rancherctl config get cloud_config)
|
CLOUD_CONFIG_FLAGS=$(rancherctl config get cloud_config)
|
||||||
|
|
||||||
cloudinit --preinit "$CLOUD_CONFIG_FLAGS"
|
cloud-init --preinit "$CLOUD_CONFIG_FLAGS"
|
||||||
|
@@ -1,15 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#if [ -t 1 ]; then
|
|
||||||
#exec /bin/sh
|
|
||||||
#else
|
|
||||||
|
|
||||||
CLOUD_CONFIG_FILE=/var/lib/rancher/cloud-config
|
CLOUD_CONFIG_FILE=/var/lib/rancher/cloud-config
|
||||||
|
|
||||||
if [ -s $CLOUD_CONFIG_FILE ]; then
|
if [ -s $CLOUD_CONFIG_FILE ]; then
|
||||||
cloudinit --from-file $CLOUD_CONFIG_FILE
|
cloud-init --from-file $CLOUD_CONFIG_FILE
|
||||||
fi
|
fi
|
||||||
exec respawn << EOF
|
|
||||||
|
cat > /etc/respawn.conf << EOF
|
||||||
/sbin/getty 115200 tty1
|
/sbin/getty 115200 tty1
|
||||||
/sbin/getty 115200 tty2
|
/sbin/getty 115200 tty2
|
||||||
/sbin/getty 115200 tty3
|
/sbin/getty 115200 tty3
|
||||||
@@ -17,4 +14,5 @@ fi
|
|||||||
/sbin/getty 115200 tty5
|
/sbin/getty 115200 tty5
|
||||||
/sbin/getty 115200 tty6
|
/sbin/getty 115200 tty6
|
||||||
EOF
|
EOF
|
||||||
#fi
|
|
||||||
|
exec respawn -f /etc/respawn.conf
|
||||||
|
Reference in New Issue
Block a user