1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 06:11:12 +00:00

Start initial support of running in Docker

This commit is contained in:
Darren Shepherd
2015-02-14 09:35:12 -07:00
parent d564e5ae7d
commit c997143d22
3 changed files with 94 additions and 16 deletions

View File

@@ -187,25 +187,29 @@ func loadModules(cfg *config.Config) error {
}
func sysInit(cfg *config.Config) error {
cmd := exec.Command("openvt", "-s", "/sbin/init-sys")
//cmd := exec.Command("/sbin/init-sys")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
args := append([]string{"/sbin/init-sys"}, os.Args[1:]...)
var cmd *exec.Cmd
if util.IsRunningInTty() {
cmd = exec.Command(args[0], args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
} else {
args = append([]string{"openvt", "-s"}, args...)
cmd = exec.Command(args[0], args[1:]...)
}
if err := cmd.Start(); err != nil {
return err
}
return nil
//log.Debug("Launching host console")
//return exec.Command("openvt", "/bin/sh").Run()
//log.Debug("Launching console")
//return exec.Command("/bin/openvt", "-s", "/bin/console-container.sh").Start()
return os.Stdin.Close()
}
func execDocker(cfg *config.Config) error {
log.Info("Launching Docker")
os.Stdin.Close()
return syscall.Exec(cfg.DockerBin, cfg.SystemDockerArgs, os.Environ())
}
@@ -237,11 +241,11 @@ func mountState(cfg *config.Config) error {
}
}
log.Debugf("Bind mounting %s to %s", path.Join(STATE, "docker"), DOCKER)
err = util.Mount(path.Join(STATE, "docker"), DOCKER, "", "bind")
if err != nil && cfg.StateRequired {
return err
}
//log.Debugf("Bind mounting %s to %s", path.Join(STATE, "docker"), DOCKER)
//err = util.Mount(path.Join(STATE, "docker"), DOCKER, "", "bind")
//if err != nil && cfg.StateRequired {
// return err
//}
return nil
}

14
util/term.go Normal file
View File

@@ -0,0 +1,14 @@
package util
import (
"github.com/kless/term"
log "github.com/Sirupsen/logrus"
)
func IsRunningInTty() bool {
log.Infof("Is a tty : %v", term.IsTerminal(0))
log.Infof("Is a tty : %v", term.IsTerminal(1))
log.Infof("Is a tty : %v", term.IsTerminal(2))
return term.IsTerminal(1)
}

View File

@@ -4,6 +4,7 @@ import (
"archive/tar"
"fmt"
"io"
"math/rand"
"os"
"path"
"syscall"
@@ -11,6 +12,10 @@ import (
"github.com/docker/docker/pkg/mount"
)
var (
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
)
func mountProc() error {
if _, err := os.Stat("/proc/self/mountinfo"); os.IsNotExist(err) {
if _, err := os.Stat("/proc"); os.IsNotExist(err) {
@@ -94,3 +99,58 @@ func ExtractTar(archive string, dest string) error {
return nil
}
func Contains(values []string, value string) bool {
if len(value) == 0 {
return false
}
for _, value := range values {
if value == value {
return true
}
}
return false
}
type ReturnsErr func() error
func ShortCircuit(funcs ...ReturnsErr) error {
for _, f := range funcs {
err := f()
if err != nil {
return err
}
}
return nil
}
type ErrWriter struct {
w io.Writer
Err error
}
func NewErrorWriter(w io.Writer) *ErrWriter {
return &ErrWriter{
w: w,
}
}
func (e *ErrWriter) Write(buf []byte) *ErrWriter {
if e.Err != nil {
return e
}
_, e.Err = e.w.Write(buf)
return e
}
func RandSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}