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

Initial fix to stop other containers before the console

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit 2017-07-28 11:50:07 +10:00
parent 5716be7a34
commit 67d932d9f8
8 changed files with 66 additions and 16 deletions

View File

@ -1,6 +1,7 @@
package control package control
import ( import (
"fmt"
"os" "os"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
@ -14,7 +15,7 @@ func Main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = os.Args[0] app.Name = os.Args[0]
app.Usage = "Control and configure RancherOS" app.Usage = fmt.Sprintf("Control and configure RancherOS\nbuilt: %s", config.BuildDate)
app.Version = config.Version app.Version = config.Version
app.Author = "Rancher Labs, Inc." app.Author = "Rancher Labs, Inc."
app.EnableBashCompletion = true app.EnableBashCompletion = true

View File

@ -11,7 +11,6 @@ import (
func selinuxCommand() cli.Command { func selinuxCommand() cli.Command {
app := cli.Command{} app := cli.Command{}
app.Name = "selinux" app.Name = "selinux"
app.Usage = "Launch SELinux tools container."
app.Action = func(c *cli.Context) error { app.Action = func(c *cli.Context) error {
argv := []string{"system-docker", "run", "-it", "--privileged", "--rm", argv := []string{"system-docker", "run", "-it", "--privileged", "--rm",
"--net", "host", "--pid", "host", "--ipc", "host", "--net", "host", "--pid", "host", "--ipc", "host",

View File

@ -36,7 +36,6 @@ func Commands() cli.Command {
app := cli.Command{} app := cli.Command{}
app.Name = "service" app.Name = "service"
app.ShortName = "s" app.ShortName = "s"
app.Usage = "Command line interface for services and compose."
app.Before = beforeApp app.Before = beforeApp
app.Flags = append(dockerApp.DockerClientFlags(), cli.BoolFlag{ app.Flags = append(dockerApp.DockerClientFlags(), cli.BoolFlag{
Name: "verbose,debug", Name: "verbose,debug",

View File

@ -196,15 +196,21 @@ func shutDownContainers() error {
} }
var stopErrorStrings []string var stopErrorStrings []string
consoleContainerIdx := -1
for _, container := range containers { for idx, container := range containers {
if container.ID == currentContainerID { if container.ID == currentContainerID {
continue continue
} }
if container.Names[0] == "/console" {
consoleContainerIdx = idx
continue
}
log.Infof("Stopping %s : %v", container.ID[:12], container.Names) log.Infof("Stopping %s : %s", container.Names[0], container.ID[:12])
stopErr := client.ContainerStop(context.Background(), container.ID, timeout) stopErr := client.ContainerStop(context.Background(), container.ID, timeout)
if stopErr != nil { if stopErr != nil {
log.Errorf("------- Error Stopping %s : %s", container.Names[0], stopErr.Error())
stopErrorStrings = append(stopErrorStrings, " ["+container.ID+"] "+stopErr.Error()) stopErrorStrings = append(stopErrorStrings, " ["+container.ID+"] "+stopErr.Error())
} }
} }
@ -215,8 +221,31 @@ func shutDownContainers() error {
if container.ID == currentContainerID { if container.ID == currentContainerID {
continue continue
} }
if container.Names[0] == "/console" {
continue
}
log.Infof("Waiting %s : %s", container.Names[0], container.ID[:12])
_, waitErr := client.ContainerWait(context.Background(), container.ID) _, waitErr := client.ContainerWait(context.Background(), container.ID)
if waitErr != nil { if waitErr != nil {
log.Errorf("------- Error Waiting %s : %s", container.Names[0], waitErr.Error())
waitErrorStrings = append(waitErrorStrings, " ["+container.ID+"] "+waitErr.Error())
}
}
// and now stop the console
if consoleContainerIdx != -1 {
container := containers[consoleContainerIdx]
log.Infof("Console Stopping %v : %s", container.Names, container.ID[:12])
stopErr := client.ContainerStop(context.Background(), container.ID, timeout)
if stopErr != nil {
log.Errorf("------- Error Stopping %v : %s", container.Names, stopErr.Error())
stopErrorStrings = append(stopErrorStrings, " ["+container.ID+"] "+stopErr.Error())
}
log.Infof("Console Waiting %v : %s", container.Names, container.ID[:12])
_, waitErr := client.ContainerWait(context.Background(), container.ID)
if waitErr != nil {
log.Errorf("------- Error Waiting %v : %s", container.Names, waitErr.Error())
waitErrorStrings = append(waitErrorStrings, " ["+container.ID+"] "+waitErr.Error()) waitErrorStrings = append(waitErrorStrings, " ["+container.ID+"] "+waitErr.Error())
} }
} }

View File

@ -28,7 +28,7 @@ func Shutdown() {
app := cli.NewApp() app := cli.NewApp()
app.Name = os.Args[0] app.Name = os.Args[0]
app.Usage = "Control and configure RancherOS" app.Usage = fmt.Sprintf("%s RancherOS\nbuilt: %s", app.Name, config.BuildDate)
app.Version = config.Version app.Version = config.Version
app.Author = "Rancher Labs, Inc." app.Author = "Rancher Labs, Inc."
app.EnableBashCompletion = true app.EnableBashCompletion = true
@ -136,6 +136,11 @@ func Shutdown() {
}) })
} }
//TODO: add the time and msg flags... //TODO: add the time and msg flags...
app.HideHelp = true
log.Infof("%s, %s", app.Usage, app.Version)
fmt.Printf("%s, %s", app.Usage, app.Version)
app.Run(os.Args) app.Run(os.Args)
} }

View File

@ -1,6 +1,7 @@
package respawn package respawn
import ( import (
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -13,6 +14,7 @@ import (
"time" "time"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/rancher/os/config"
"github.com/rancher/os/log" "github.com/rancher/os/log"
) )
@ -28,6 +30,11 @@ func Main() {
runtime.LockOSThread() runtime.LockOSThread()
app := cli.NewApp() app := cli.NewApp()
app.Name = os.Args[0]
app.Usage = fmt.Sprintf("%s RancherOS\nbuilt: %s", app.Name, config.BuildDate)
app.Version = config.Version
app.Author = "Rancher Labs, Inc."
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "file, f", Name: "file, f",
@ -36,6 +43,9 @@ func Main() {
} }
app.Action = run app.Action = run
log.Infof("%s, %s", app.Usage, app.Version)
fmt.Printf("%s, %s", app.Usage, app.Version)
app.Run(os.Args) app.Run(os.Args)
} }
@ -69,17 +79,21 @@ func run(c *cli.Context) error {
panic(err) panic(err)
} }
var wg sync.WaitGroup lines := strings.Split(string(input), "\n")
doneChannel := make(chan string, len(lines))
for _, line := range strings.Split(string(input), "\n") { for _, line := range lines {
if strings.TrimSpace(line) == "" || strings.Index(strings.TrimSpace(line), "#") == 0 { if strings.TrimSpace(line) == "" || strings.Index(strings.TrimSpace(line), "#") == 0 {
continue continue
} }
wg.Add(1) go execute(line, doneChannel)
go execute(line, &wg)
} }
wg.Wait() for i := 0; i < len(lines); i++ {
line := <-doneChannel
log.Infof("FINISHED: %s", line)
fmt.Printf("FINISHED: %s", line)
}
return nil return nil
} }
@ -101,19 +115,20 @@ func termPids() {
defer processLock.Unlock() defer processLock.Unlock()
for _, process := range processes { for _, process := range processes {
log.Infof("sending SIGTERM to %d", process.Pid)
process.Signal(syscall.SIGTERM) process.Signal(syscall.SIGTERM)
} }
} }
func execute(line string, wg *sync.WaitGroup) { func execute(line string, doneChannel chan string) {
defer wg.Done() defer func() { doneChannel <- line }()
start := time.Now() start := time.Now()
count := 0 count := 0
for { args := strings.Split(line, " ")
args := strings.Split(line, " ")
for {
cmd := exec.Command(args[0], args[1:]...) cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr

View File

@ -51,6 +51,7 @@ const (
var ( var (
OemConfigFile = OEM + "/oem-config.yml" OemConfigFile = OEM + "/oem-config.yml"
Version string Version string
BuildDate string
Arch string Arch string
Suffix string Suffix string
OsRepo string OsRepo string

View File

@ -14,6 +14,7 @@ fi
OUTPUT=${OUTPUT:-bin/ros} OUTPUT=${OUTPUT:-bin/ros}
echo Building $OUTPUT echo Building $OUTPUT
BUILDDATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
CONST="-X github.com/docker/docker/dockerversion.GitCommit=${COMMIT} -X github.com/docker/docker/dockerversion.Version=${DOCKER_PATCH_VERSION} -X github.com/docker/docker/dockerversion.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -X github.com/docker/docker/dockerversion.IAmStatic=true -X github.com/rancher/os/config.Version=${VERSION} -X github.com/rancher/os/config.OsRepo=${OS_REPO}" CONST="-X github.com/docker/docker/dockerversion.GitCommit=${COMMIT} -X github.com/docker/docker/dockerversion.Version=${DOCKER_PATCH_VERSION} -X github.com/docker/docker/dockerversion.BuildTime='${BUILDDATE}' -X github.com/docker/docker/dockerversion.IAmStatic=true -X github.com/rancher/os/config.Version=${VERSION} -X github.com/rancher/os/config.OsRepo=${OS_REPO} -X github.com/rancher/os/config.BuildDate='${BUILDDATE}'"
go build -tags "selinux cgo daemon netgo dnspatch" -installsuffix netgo -ldflags "$CONST -linkmode external -extldflags -static -s -w" -o ${OUTPUT} go build -tags "selinux cgo daemon netgo dnspatch" -installsuffix netgo -ldflags "$CONST -linkmode external -extldflags -static -s -w" -o ${OUTPUT}