mirror of
https://github.com/rancher/os.git
synced 2025-09-02 15:24:32 +00:00
First class consoles
This commit is contained in:
41
cmd/switchconsole/switch_console.go
Normal file
41
cmd/switchconsole/switch_console.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package switchconsole
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"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")
|
||||
}
|
||||
newConsole := os.Args[1]
|
||||
|
||||
cfg := config.LoadConfig()
|
||||
|
||||
project, err := compose.GetProject(cfg, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err = compose.LoadService(project, cfg, true, newConsole); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err = project.Up(context.Background(), options.Up{}, "console"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err = project.Restart(context.Background(), 10, "docker"); err != nil {
|
||||
log.Errorf("Failed to restart Docker: %v", err)
|
||||
}
|
||||
|
||||
if err = config.Set("rancher.console", newConsole); err != nil {
|
||||
log.Errorf("Failed to update 'rancher.console': %v", err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user