2016-06-06 22:13:15 +00:00
|
|
|
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()
|
|
|
|
|
2016-06-12 19:02:07 +00:00
|
|
|
project, err := compose.GetProject(cfg, true, false)
|
2016-06-06 22:13:15 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-06-12 19:02:07 +00:00
|
|
|
if newConsole != "default" {
|
|
|
|
if err = compose.LoadService(project, cfg, true, newConsole); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-06-06 22:13:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 02:19:18 +00:00
|
|
|
if err = project.Up(context.Background(), options.Up{
|
|
|
|
Log: true,
|
|
|
|
}, "console"); err != nil {
|
2016-06-06 22:13:15 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|