mirror of
https://github.com/rancher/os.git
synced 2025-07-01 09:11:48 +00:00
Move more commands to subcommands of ros
This commit is contained in:
parent
b767e5e1a7
commit
21fb3ebfa9
@ -44,6 +44,13 @@ func Main() {
|
||||
HideHelp: true,
|
||||
Subcommands: consoleSubcommands(),
|
||||
},
|
||||
{
|
||||
Name: "console-init",
|
||||
Hidden: true,
|
||||
HideHelp: true,
|
||||
SkipFlagParsing: true,
|
||||
Action: consoleInitAction,
|
||||
},
|
||||
{
|
||||
Name: "dev",
|
||||
Hidden: true,
|
||||
@ -51,6 +58,13 @@ func Main() {
|
||||
SkipFlagParsing: true,
|
||||
Action: devAction,
|
||||
},
|
||||
{
|
||||
Name: "docker-init",
|
||||
Hidden: true,
|
||||
HideHelp: true,
|
||||
SkipFlagParsing: true,
|
||||
Action: dockerInitAction,
|
||||
},
|
||||
{
|
||||
Name: "engine",
|
||||
Usage: "manage which Docker engine is used",
|
||||
@ -85,6 +99,13 @@ func Main() {
|
||||
SkipFlagParsing: true,
|
||||
Action: preloadImagesAction,
|
||||
},
|
||||
{
|
||||
Name: "switch-console",
|
||||
Hidden: true,
|
||||
HideHelp: true,
|
||||
SkipFlagParsing: true,
|
||||
Action: switchConsoleAction,
|
||||
},
|
||||
{
|
||||
Name: "tls",
|
||||
Usage: "setup tls configuration",
|
||||
@ -98,6 +119,13 @@ func Main() {
|
||||
SkipFlagParsing: true,
|
||||
Action: udevSettleAction,
|
||||
},
|
||||
{
|
||||
Name: "user-docker",
|
||||
Hidden: true,
|
||||
HideHelp: true,
|
||||
SkipFlagParsing: true,
|
||||
Action: userDockerAction,
|
||||
},
|
||||
installCommand,
|
||||
selinuxCommand(),
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ func consoleSwitch(c *cli.Context) error {
|
||||
Labels: map[string]string{
|
||||
config.SCOPE: config.SYSTEM,
|
||||
},
|
||||
Command: []string{"/usr/bin/switch-console", newConsole},
|
||||
Command: []string{"/usr/bin/ros", "switch-console", newConsole},
|
||||
VolumesFrom: []string{"all-volumes"},
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package console
|
||||
package control
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/rancher/os/cmd/cloudinitexecute"
|
||||
"github.com/rancher/os/config"
|
||||
"github.com/rancher/os/util"
|
||||
@ -29,7 +30,7 @@ type symlink struct {
|
||||
oldname, newname string
|
||||
}
|
||||
|
||||
func Main() {
|
||||
func consoleInitAction(c *cli.Context) error {
|
||||
cfg := config.LoadConfig()
|
||||
|
||||
if _, err := os.Stat(rancherHome); os.IsNotExist(err) {
|
||||
@ -124,10 +125,10 @@ func Main() {
|
||||
|
||||
respawnBinPath, err := exec.LookPath("respawn")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Fatal(syscall.Exec(respawnBinPath, []string{"respawn", "-f", "/etc/respawn.conf"}, os.Environ()))
|
||||
return syscall.Exec(respawnBinPath, []string{"respawn", "-f", "/etc/respawn.conf"}, os.Environ())
|
||||
}
|
||||
|
||||
func generateRespawnConf(cmdline string) string {
|
@ -1,4 +1,4 @@
|
||||
package dockerinit
|
||||
package control
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -10,18 +10,18 @@ import (
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/rancher/os/config"
|
||||
"github.com/rancher/os/util"
|
||||
)
|
||||
|
||||
const (
|
||||
consoleDone = "/run/console-done"
|
||||
dockerConf = "/var/lib/rancher/conf/docker"
|
||||
dockerDone = "/run/docker-done"
|
||||
dockerLog = "/var/log/docker.log"
|
||||
dockerConf = "/var/lib/rancher/conf/docker"
|
||||
dockerDone = "/run/docker-done"
|
||||
dockerLog = "/var/log/docker.log"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
func dockerInitAction(c *cli.Context) error {
|
||||
for {
|
||||
if _, err := os.Stat(consoleDone); err == nil {
|
||||
break
|
||||
@ -54,7 +54,7 @@ func Main() {
|
||||
|
||||
mountInfo, err := ioutil.ReadFile("/proc/self/mountinfo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
for _, mount := range strings.Split(string(mountInfo), "\n") {
|
||||
@ -66,7 +66,7 @@ func Main() {
|
||||
args := []string{
|
||||
"bash",
|
||||
"-c",
|
||||
fmt.Sprintf(`[ -e %s ] && source %s; exec /usr/bin/dockerlaunch %s %s $DOCKER_OPTS >> %s 2>&1`, dockerConf, dockerConf, dockerBin, strings.Join(os.Args[1:], " "), dockerLog),
|
||||
fmt.Sprintf(`[ -e %s ] && source %s; exec /usr/bin/dockerlaunch %s %s $DOCKER_OPTS >> %s 2>&1`, dockerConf, dockerConf, dockerBin, strings.Join(c.Args(), " "), dockerLog),
|
||||
}
|
||||
|
||||
cfg := config.LoadConfig()
|
||||
@ -75,5 +75,5 @@ func Main() {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
log.Fatal(syscall.Exec("/bin/bash", args, os.Environ()))
|
||||
return syscall.Exec("/bin/bash", args, os.Environ())
|
||||
}
|
@ -16,10 +16,6 @@ import (
|
||||
"github.com/rancher/os/util/network"
|
||||
)
|
||||
|
||||
const (
|
||||
dockerDone = "/run/docker-done"
|
||||
)
|
||||
|
||||
func engineSubcommands() []cli.Command {
|
||||
return []cli.Command{
|
||||
{
|
||||
|
@ -1,31 +1,32 @@
|
||||
package switchconsole
|
||||
package control
|
||||
|
||||
import (
|
||||
"os"
|
||||
"errors"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/project/options"
|
||||
"github.com/rancher/os/compose"
|
||||
"github.com/rancher/os/config"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
if len(os.Args) != 2 {
|
||||
log.Fatal("Must specify exactly one existing container")
|
||||
func switchConsoleAction(c *cli.Context) error {
|
||||
if len(c.Args()) != 1 {
|
||||
return errors.New("Must specify exactly one existing container")
|
||||
}
|
||||
newConsole := os.Args[1]
|
||||
newConsole := c.Args()[0]
|
||||
|
||||
cfg := config.LoadConfig()
|
||||
|
||||
project, err := compose.GetProject(cfg, true, false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if newConsole != "default" {
|
||||
if err = compose.LoadSpecialService(project, cfg, "console", newConsole); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,10 +37,12 @@ func Main() {
|
||||
if err = project.Up(context.Background(), options.Up{
|
||||
Log: true,
|
||||
}, "console"); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = project.Restart(context.Background(), 10, "docker"); err != nil {
|
||||
log.Errorf("Failed to restart Docker: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package userdocker
|
||||
package control
|
||||
|
||||
import (
|
||||
"io"
|
||||
@ -13,9 +13,9 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
composeClient "github.com/docker/libcompose/docker/client"
|
||||
"github.com/docker/libcompose/project"
|
||||
"github.com/rancher/os/cmd/control"
|
||||
"github.com/rancher/os/compose"
|
||||
"github.com/rancher/os/config"
|
||||
rosDocker "github.com/rancher/os/docker"
|
||||
@ -25,24 +25,30 @@ import (
|
||||
const (
|
||||
DEFAULT_STORAGE_CONTEXT = "console"
|
||||
DOCKER_PID_FILE = "/var/run/docker.pid"
|
||||
DOCKER_COMMAND = "docker-init"
|
||||
userDocker = "user-docker"
|
||||
sourceDirectory = "/engine"
|
||||
destDirectory = "/var/lib/rancher/engine"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
var (
|
||||
DOCKER_COMMAND = []string{
|
||||
"ros",
|
||||
"docker-init",
|
||||
}
|
||||
)
|
||||
|
||||
func userDockerAction(c *cli.Context) error {
|
||||
if err := copyBinaries(sourceDirectory, destDirectory); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := syscall.Mount("/host/sys", "/sys", "", syscall.MS_BIND|syscall.MS_REC, ""); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
cfg := config.LoadConfig()
|
||||
|
||||
log.Fatal(startDocker(cfg))
|
||||
return startDocker(cfg)
|
||||
}
|
||||
|
||||
func copyBinaries(source, dest string) error {
|
||||
@ -98,15 +104,15 @@ func copyBinaries(source, dest string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeCerts(cfg *config.CloudConfig) error {
|
||||
outDir := control.ServerTlsPath
|
||||
func writeConfigCerts(cfg *config.CloudConfig) error {
|
||||
outDir := ServerTlsPath
|
||||
if err := os.MkdirAll(outDir, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
caCertPath := filepath.Join(outDir, control.CaCert)
|
||||
caKeyPath := filepath.Join(outDir, control.CaKey)
|
||||
serverCertPath := filepath.Join(outDir, control.ServerCert)
|
||||
serverKeyPath := filepath.Join(outDir, control.ServerKey)
|
||||
caCertPath := filepath.Join(outDir, CaCert)
|
||||
caKeyPath := filepath.Join(outDir, CaKey)
|
||||
serverCertPath := filepath.Join(outDir, ServerCert)
|
||||
serverKeyPath := filepath.Join(outDir, ServerKey)
|
||||
if cfg.Rancher.Docker.CACert != "" {
|
||||
if err := util.WriteFileAtomic(caCertPath, []byte(cfg.Rancher.Docker.CACert), 0400); err != nil {
|
||||
return err
|
||||
@ -160,7 +166,7 @@ func startDocker(cfg *config.CloudConfig) error {
|
||||
log.Debugf("User Docker args: %v", args)
|
||||
|
||||
if dockerCfg.TLS {
|
||||
if err := writeCerts(cfg); err != nil {
|
||||
if err := writeConfigCerts(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -173,7 +179,7 @@ func startDocker(cfg *config.CloudConfig) error {
|
||||
cmd := []string{"docker-runc", "exec", "--", info.ID, "env"}
|
||||
log.Info(dockerCfg.AppendEnv())
|
||||
cmd = append(cmd, dockerCfg.AppendEnv()...)
|
||||
cmd = append(cmd, DOCKER_COMMAND)
|
||||
cmd = append(cmd, DOCKER_COMMAND...)
|
||||
cmd = append(cmd, args...)
|
||||
log.Infof("Running %v", cmd)
|
||||
|
@ -9,4 +9,3 @@ RUN sed -i 's/rancher:!/rancher:*/g' /etc/shadow && \
|
||||
echo '## allow password less for docker user' >> /etc/sudoers && \
|
||||
echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
|
||||
COPY prompt.sh /etc/profile.d/
|
||||
CMD ["/usr/sbin/console.sh"]
|
||||
|
9
main.go
9
main.go
@ -8,16 +8,12 @@ import (
|
||||
"github.com/rancher/cniglue"
|
||||
"github.com/rancher/os/cmd/cloudinitexecute"
|
||||
"github.com/rancher/os/cmd/cloudinitsave"
|
||||
"github.com/rancher/os/cmd/console"
|
||||
"github.com/rancher/os/cmd/control"
|
||||
"github.com/rancher/os/cmd/dockerinit"
|
||||
"github.com/rancher/os/cmd/network"
|
||||
"github.com/rancher/os/cmd/power"
|
||||
"github.com/rancher/os/cmd/respawn"
|
||||
"github.com/rancher/os/cmd/switchconsole"
|
||||
"github.com/rancher/os/cmd/sysinit"
|
||||
"github.com/rancher/os/cmd/systemdocker"
|
||||
"github.com/rancher/os/cmd/userdocker"
|
||||
"github.com/rancher/os/cmd/wait"
|
||||
"github.com/rancher/os/dfs"
|
||||
osInit "github.com/rancher/os/init"
|
||||
@ -26,10 +22,7 @@ import (
|
||||
var entrypoints = map[string]func(){
|
||||
"cloud-init-execute": cloudinitexecute.Main,
|
||||
"cloud-init-save": cloudinitsave.Main,
|
||||
"console": console.Main,
|
||||
"console.sh": console.Main,
|
||||
"docker": docker.Main,
|
||||
"docker-init": dockerinit.Main,
|
||||
"dockerlaunch": dfs.Main,
|
||||
"halt": power.Halt,
|
||||
"init": osInit.MainInit,
|
||||
@ -39,9 +32,7 @@ var entrypoints = map[string]func(){
|
||||
"respawn": respawn.Main,
|
||||
"ros-sysinit": sysinit.Main,
|
||||
"shutdown": power.Main,
|
||||
"switch-console": switchconsole.Main,
|
||||
"system-docker": systemdocker.Main,
|
||||
"user-docker": userdocker.Main,
|
||||
"wait-for-docker": wait.Main,
|
||||
"cni-glue": glue.Main,
|
||||
"bridge": bridge.Main,
|
||||
|
@ -135,7 +135,6 @@ rancher:
|
||||
read_only: true
|
||||
volumes:
|
||||
- /usr/bin/ros:/usr/bin/dockerlaunch:ro
|
||||
- /usr/bin/ros:/usr/bin/user-docker:ro
|
||||
- /usr/bin/ros:/usr/bin/system-docker:ro
|
||||
- /usr/bin/ros:/sbin/poweroff:ro
|
||||
- /usr/bin/ros:/sbin/reboot:ro
|
||||
@ -147,13 +146,9 @@ rancher:
|
||||
- /usr/bin/ros:/usr/bin/cloud-init-save:ro
|
||||
- /usr/bin/ros:/usr/sbin/netconf:ro
|
||||
- /usr/bin/ros:/usr/sbin/wait-for-docker:ro
|
||||
- /usr/bin/ros:/usr/bin/switch-console:ro
|
||||
- /usr/bin/ros:/usr/bin/console:ro
|
||||
- /usr/bin/ros:/usr/sbin/console.sh:ro
|
||||
- /usr/bin/ros:/usr/sbin/docker-init:ro
|
||||
console:
|
||||
image: {{.OS_REPO}}/os-console:{{.VERSION}}{{.SUFFIX}}
|
||||
command: console
|
||||
command: ros console-init
|
||||
labels:
|
||||
io.rancher.os.scope: system
|
||||
io.rancher.os.after: network
|
||||
@ -316,7 +311,7 @@ rancher:
|
||||
{{else -}}
|
||||
image: {{.OS_REPO}}/os-docker:1.11.2{{.SUFFIX}}
|
||||
{{end -}}
|
||||
command: /usr/bin/user-docker
|
||||
command: ros user-docker
|
||||
environment:
|
||||
- HTTP_PROXY
|
||||
- HTTPS_PROXY
|
||||
|
Loading…
Reference in New Issue
Block a user