1
0
mirror of https://github.com/rancher/os.git synced 2025-08-11 19:42:24 +00:00

General cleanup

This commit is contained in:
Darren Shepherd 2015-02-19 11:27:23 -07:00
parent 6e87ea3981
commit 045130a830
4 changed files with 73 additions and 58 deletions

View File

@ -12,14 +12,33 @@ func NewConfig() *Config {
Dev: "LABEL=RANCHER_STATE", Dev: "LABEL=RANCHER_STATE",
FsType: "auto", FsType: "auto",
}, },
SystemDockerArgs: []string{"docker", "-d", "-s", "overlay", "-b", "none", "--restart=false"}, SystemDockerArgs: []string{"docker", "-d", "-s", "overlay", "-b", "none", "--restart=false", "-H", DOCKER_SYSTEM_HOST},
Modules: []string{}, Modules: []string{},
SystemContainers: []ContainerConfig{ SystemContainers: []ContainerConfig{
{ {
Cmd: "--name=system-state " + Cmd: "--name=system-volumes " +
"--net=none " + "--net=none " +
"--read-only " + "--read-only " +
"-v=/var/lib/rancher/conf:/var/lib/rancher/conf " + "-v=/var/lib/rancher/conf:/var/lib/rancher/conf " +
"-v=/lib/modules:/lib/modules:ro " +
"-v=/var/run:/var/run " +
"state",
},
{
Cmd: "--name=console-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/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 " +
"-v=/var/lib/rancher/state/home:/home " +
"-v=/var/lib/rancher/state/opt:/opt " +
"state", "state",
}, },
{ {
@ -38,38 +57,6 @@ func NewConfig() *Config {
"--rm " + "--rm " +
"network", "network",
}, },
{
Cmd: "--name=userdocker " +
"-d " +
"--restart=always " +
"--pid=host " +
"--net=host " +
"--privileged " +
"-v=/lib/modules:/lib/modules:ro " +
"-v=/usr/bin/docker:/usr/bin/docker:ro " +
"--volumes-from=system-state " +
"userdocker",
},
{
Cmd: "--name=console " +
"-d " +
"--rm " +
"--privileged " +
"-v=/lib/modules:/lib/modules:ro " +
"-v=/usr/bin/docker:/usr/bin/docker:ro " +
"-v=/init:/usr/bin/system-docker:ro " +
"-v=/init:/usr/bin/respawn:ro " +
"-v=/var/run/docker.sock:/var/run/system-docker.sock:ro " +
"-v=/init:/sbin/poweroff:ro " +
"-v=/init:/sbin/reboot:ro " +
"-v=/init:/sbin/halt:ro " +
"-v=/init:/sbin/tlsconf:ro " +
"-v=/init:/usr/bin/rancherctl:ro " +
"--volumes-from=system-state " +
"--net=host " +
"--pid=host " +
"console",
},
{ {
Cmd: "--name=ntp " + Cmd: "--name=ntp " +
"--rm " + "--rm " +
@ -78,17 +65,41 @@ func NewConfig() *Config {
"--net=host " + "--net=host " +
"ntp", "ntp",
}, },
{
Cmd: "--name=userdocker " +
"-d " +
"--rm " +
"--restart=always " +
"--ipc=host " +
"--pid=host " +
"--net=host " +
"--privileged " +
"--volumes-from=system-volumes " +
"-v=/usr/bin/docker:/usr/bin/docker:ro " +
"-v=/var/lib/rancher/state/docker:/var/lib/docker " +
"userdocker",
},
{
Cmd: "--name=console " +
"-d " +
"--rm " +
"--privileged " +
"--volumes-from=console-volumes " +
"--volumes-from=system-volumes " +
"--ipc=host " +
"--net=host " +
"--pid=host " +
"console",
},
}, },
RescueContainer: &ContainerConfig{ RescueContainer: &ContainerConfig{
Cmd: "--name=rescue " + Cmd: "--name=rescue " +
"-d " + "-d " +
"--rm " + "--rm " +
"--privileged " + "--privileged " +
"-v=/lib/modules:/lib/modules:ro " + "--volumes-from=console-volumes " +
"-v=/usr/bin/docker:/usr/bin/docker:ro " + "--volumes-from=system-volumes " +
"-v=/init:/usr/bin/system-docker:ro " + "--ipc=host " +
"-v=/init:/usr/bin/respawn:ro " +
"-v=/var/run/docker.sock:/var/run/system-docker.sock:ro " +
"--net=host " + "--net=host " +
"--pid=host " + "--pid=host " +
"rescue", "rescue",

View File

@ -16,6 +16,7 @@ import (
const ( const (
STATE string = "/var" STATE string = "/var"
DOCKER string = "/usr/bin/docker" DOCKER string = "/usr/bin/docker"
SYSINIT string = "/sbin/rancher-sysinit"
) )
var ( var (
@ -23,37 +24,37 @@ var (
"/etc/ssl/certs", "/etc/ssl/certs",
"/sbin", "/sbin",
"/usr/bin", "/usr/bin",
"/var",
} }
mounts [][]string = [][]string{ mounts [][]string = [][]string{
[]string{"devtmpfs", "/dev", "devtmpfs", ""},
[]string{"none", "/dev/pts", "devpts", ""},
[]string{"none", "/etc/docker", "tmpfs", ""}, []string{"none", "/etc/docker", "tmpfs", ""},
[]string{"none", "/proc", "proc", ""}, []string{"none", "/proc", "proc", ""},
[]string{"devtmpfs", "/dev", "devtmpfs", ""}, []string{"none", "/run", "tmpfs", ""},
[]string{"none", "/sys", "sysfs", ""}, []string{"none", "/sys", "sysfs", ""},
[]string{"none", "/sys/fs/cgroup", "tmpfs", ""}, []string{"none", "/sys/fs/cgroup", "tmpfs", ""},
[]string{"none", "/dev/pts", "devpts", ""}, }
[]string{"none", "/run", "tmpfs", ""}, postMounts [][]string = [][]string{
[]string{"none", "/var/run", "tmpfs", ""},
} }
cgroups []string = []string{ cgroups []string = []string{
"perf_event",
"net_cls",
"freezer",
"devices",
"blkio", "blkio",
"memory",
"cpuacct",
"cpu", "cpu",
"cpuacct",
"cpuset", "cpuset",
"devices",
"freezer",
"memory",
"net_cls",
"perf_event",
} }
// Notice this map is the reverse order of a "ln -s x y" command // Notice this map is the reverse order of a "ln -s x y" command
// so map[y] = x // so map[y] = x
symlinks map[string]string = map[string]string{ symlinks map[string]string = map[string]string{
"/etc/ssl/certs/ca-certificates.crt": "/ca.crt", "/etc/ssl/certs/ca-certificates.crt": "/ca.crt",
"/sbin/init-sys": "/init",
"/sbin/init-user": "/init",
"/sbin/modprobe": "/busybox", "/sbin/modprobe": "/busybox",
"/var/run": "/run",
DOCKER: "/docker", DOCKER: "/docker",
SYSINIT: "/init",
} }
) )
@ -177,7 +178,7 @@ func loadModules(cfg *config.Config) error {
} }
func sysInit(cfg *config.Config) error { func sysInit(cfg *config.Config) error {
args := append([]string{"/sbin/init-sys"}, os.Args[1:]...) args := append([]string{SYSINIT}, os.Args[1:]...)
var cmd *exec.Cmd var cmd *exec.Cmd
if util.IsRunningInTty() { if util.IsRunningInTty() {
@ -275,6 +276,9 @@ func RunInit() error {
extractModules, extractModules,
loadModules, loadModules,
mountState, mountState,
func(cfg *config.Config) error {
return createMounts(postMounts...)
},
func(cfg *config.Config) error { func(cfg *config.Config) error {
return cfg.Reload() return cfg.Reload()
}, },

View File

@ -35,7 +35,7 @@ func registerCmd(cmd string, mainFunc func()) {
func main() { func main() {
registerCmd("/init", osInit.MainInit) registerCmd("/init", osInit.MainInit)
registerCmd("/sbin/init-sys", sysinit.SysInit) registerCmd(osInit.SYSINIT, sysinit.SysInit)
registerCmd("/usr/bin/system-docker", systemdocker.Main) registerCmd("/usr/bin/system-docker", systemdocker.Main)
registerCmd("/sbin/poweroff", power.PowerOff) registerCmd("/sbin/poweroff", power.PowerOff)
registerCmd("/sbin/reboot", power.Reboot) registerCmd("/sbin/reboot", power.Reboot)

View File

@ -83,7 +83,7 @@ func loadImages(cfg *config.Config) error {
return err return err
} }
client, err := docker.NewDefaultClient() client, err := docker.NewSystemClient()
if err != nil { if err != nil {
return err return err
} }
@ -122,7 +122,7 @@ func runContainers(cfg *config.Config) error {
} }
for _, containerConfig := range containerConfigs { for _, containerConfig := range containerConfigs {
container := docker.NewContainer(config.DOCKER_HOST, &containerConfig) container := docker.NewContainer(config.DOCKER_SYSTEM_HOST, &containerConfig)
container.Parse() container.Parse()
if util.Contains(cfg.Disable, containerConfig.Id) { if util.Contains(cfg.Disable, containerConfig.Id) {