Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change stop to be start stop #547

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>d</kbd>: entfernen
<kbd>e</kbd>: hide/show stopped containers
<kbd>p</kbd>: pause
<kbd>s</kbd>: anhalten
<kbd>s</kbd>: start/stop
<kbd>r</kbd>: neustarten
<kbd>a</kbd>: anbinden
<kbd>m</kbd>: zeige Protokolle
Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>d</kbd>: remove
<kbd>e</kbd>: hide/show stopped containers
<kbd>p</kbd>: pause
<kbd>s</kbd>: stop
<kbd>s</kbd>: start/stop
<kbd>r</kbd>: restart
<kbd>a</kbd>: attach
<kbd>m</kbd>: view logs
Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_es.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>d</kbd>: borrar
<kbd>e</kbd>: esconder/mostrar contenedores parados
<kbd>p</kbd>: pausa
<kbd>s</kbd>: parar
<kbd>s</kbd>: start/stop
<kbd>r</kbd>: reiniciar
<kbd>a</kbd>: attach
<kbd>m</kbd>: ver logs
Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>d</kbd>: supprimer
<kbd>e</kbd>: cacher/montrer les conteneurs arrêtés
<kbd>p</kbd>: pause
<kbd>s</kbd>: arrêter
<kbd>s</kbd>: start/stop
<kbd>r</kbd>: redémarrer
<kbd>a</kbd>: attacher
<kbd>m</kbd>: voir les enregistrements
Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>d</kbd>: verwijder
<kbd>e</kbd>: verberg gestopte containers
<kbd>p</kbd>: pause
<kbd>s</kbd>: stop
<kbd>s</kbd>: start/stop
<kbd>r</kbd>: herstart
<kbd>a</kbd>: verbinden
<kbd>m</kbd>: bekijk logs
Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>d</kbd>: usuń
<kbd>e</kbd>: hide/show stopped containers
<kbd>p</kbd>: pause
<kbd>s</kbd>: zatrzymaj
<kbd>s</kbd>: start/stop
<kbd>r</kbd>: restartuj
<kbd>a</kbd>: przyczep
<kbd>m</kbd>: pokaż logi
Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>d</kbd>: remover
<kbd>e</kbd>: ocultar/mostrar contêineres parados
<kbd>p</kbd>: pausar
<kbd>s</kbd>: parar
<kbd>s</kbd>: start/stop
<kbd>r</kbd>: reiniciar
<kbd>a</kbd>: anexar
<kbd>m</kbd>: ver logs
Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_tr.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>d</kbd>: kaldır
<kbd>e</kbd>: hide/show stopped containers
<kbd>p</kbd>: pause
<kbd>s</kbd>: durdur
<kbd>s</kbd>: start/stop
<kbd>r</kbd>: yeniden başlat
<kbd>a</kbd>: bağlan/iliştir
<kbd>m</kbd>: kayıt defterini görüntüle
Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>d</kbd>: 移除
<kbd>e</kbd>: 隐藏/显示已停止的容器
<kbd>p</kbd>: 暂停
<kbd>s</kbd>: 停止
<kbd>s</kbd>: start/stop
<kbd>r</kbd>: 重新启动
<kbd>a</kbd>: attach
<kbd>m</kbd>: 查看日志
Expand Down
6 changes: 6 additions & 0 deletions pkg/commands/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func (c *Container) Remove(options container.RemoveOptions) error {
return nil
}

// Start starts the container
func (c *Container) Start() error {
c.Log.Warn(fmt.Sprintf("starting container %s", c.Name))
return c.Client.ContainerStart(context.Background(), c.ID, container.StartOptions{})
}

// Stop stops the container
func (c *Container) Stop() error {
c.Log.Warn(fmt.Sprintf("stopping container %s", c.Name))
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ type CommandTemplatesConfig struct {

// ServiceTop is the command for viewing the processes under a given service
ServiceTop string `yaml:"serviceTop,omitempty"`

// List of shells that, in given order, will be tried when attaching to a container.
PreferredExecShells []string `yaml:"preferedExecShell,omitempty"`
}

// OSConfig contains config on the level of the os
Expand Down Expand Up @@ -402,6 +405,7 @@ func GetDefaultConfig() UserConfig {
DockerComposeConfig: "{{ .DockerCompose }} config",
CheckDockerComposeConfig: "{{ .DockerCompose }} config --quiet",
ServiceTop: "{{ .DockerCompose }} top {{ .Service.Name }}",
PreferredExecShells: []string{},
},
CustomCommands: CustomCommands{
Containers: []CustomCommand{},
Expand Down
41 changes: 37 additions & 4 deletions pkg/gui/containers_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ func (gui *Gui) handleContainersRemoveMenu(g *gocui.Gui, v *gocui.View) error {
})
}

// TODO: do same thing for start
// Fix UI not showing it being paused (it should say unpaused)
func (gui *Gui) PauseContainer(container *commands.Container) error {
return gui.WithWaitingStatus(gui.Tr.PausingStatus, func() (err error) {
if container.Details.State.Paused {
Expand All @@ -367,12 +369,22 @@ func (gui *Gui) handleContainerPause(g *gocui.Gui, v *gocui.View) error {
return gui.PauseContainer(ctr)
}

func (gui *Gui) handleContainerStop(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) handleContainerStartStop(g *gocui.Gui, v *gocui.View) error {
ctr, err := gui.Panels.Containers.GetSelectedItem()
if err != nil {
return nil
}

if !(ctr.Container.State == "exited" || ctr.Container.State == "running") {
return gui.createErrorPanel(gui.Tr.CannotStartStop)
}

if ctr.Container.State == "exited" {
return gui.WithWaitingStatus(gui.Tr.StoppingStatus, func() error {
return ctr.Start()
})
}

return gui.createConfirmationPanel(gui.Tr.Confirm, gui.Tr.StopContainer, func(g *gocui.Gui, v *gocui.View) error {
return gui.WithWaitingStatus(gui.Tr.StoppingStatus, func() error {
if err := ctr.Stop(); err != nil {
Expand Down Expand Up @@ -449,11 +461,32 @@ func (gui *Gui) containerExecShell(container *commands.Container) error {
commandObject := gui.DockerCommand.NewCommandObject(commands.CommandObject{
Container: container,
})
var command string
shell := ""

preferredExecShells := gui.Config.UserConfig.CommandTemplates.PreferredExecShells
if len(preferredExecShells) > 0 {
for _, preferredExecShell := range preferredExecShells {
command := utils.ApplyTemplate(fmt.Sprintf("docker exec {{ .Container.ID }} which %s", preferredExecShell), commandObject)

err := gui.runCommandSilently(gui.OSCommand.ExecutableFromString(command))
if err == nil {
shell = preferredExecShell
break
}
}
}

// TODO: Use SDK
// Use default implementation in case we cannot fulfill user's preference
if shell == "" {
command = utils.ApplyTemplate("docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'", commandObject)
} else {
command = utils.ApplyTemplate(fmt.Sprintf("docker exec -it {{ .Container.ID }} %s", shell), commandObject)
}

// TODO: use SDK
resolvedCommand := utils.ApplyTemplate("docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'", commandObject)
// attach and return the subprocess error
cmd := gui.OSCommand.ExecutableFromString(resolvedCommand)
cmd := gui.OSCommand.ExecutableFromString(command)
return gui.runSubprocess(cmd)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "containers",
Key: 's',
Modifier: gocui.ModNone,
Handler: gui.handleContainerStop,
Description: gui.Tr.Stop,
Handler: gui.handleContainerStartStop,
Description: gui.Tr.StartStop,
},
{
ViewName: "containers",
Expand Down
29 changes: 23 additions & 6 deletions pkg/gui/subprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,34 @@ func (gui *Gui) runSubprocessWithMessage(cmd *exec.Cmd, msg string) error {

gui.PauseBackgroundThreads = true

gui.runCommand(cmd, msg)
err := gui.runCommand(cmd, msg)

if err := gui.g.Resume(); err != nil {
return gui.createErrorPanel(err.Error())
}

gui.PauseBackgroundThreads = false

return nil
return err
}

func (gui *Gui) runCommand(cmd *exec.Cmd, msg string) {
func (gui *Gui) runCommandSilently(cmd *exec.Cmd) error {
stop := make(chan os.Signal, 1)
defer signal.Stop(stop)

go func() {
signal.Notify(stop, os.Interrupt)
<-stop

if err := gui.OSCommand.Kill(cmd); err != nil {
gui.Log.Error(err)
}
}()

return cmd.Run()
}

func (gui *Gui) runCommand(cmd *exec.Cmd, msg string) error {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
cmd.Stdin = os.Stdin
Expand All @@ -58,9 +74,8 @@ func (gui *Gui) runCommand(cmd *exec.Cmd, msg string) {
if msg != "" {
fmt.Fprintf(os.Stdout, "\n%s\n\n", utils.ColoredString(msg, color.FgGreen))
}
if err := cmd.Run(); err != nil {
// not handling the error explicitly because usually we're going to see it
// in the output anyway
err := cmd.Run()
if err != nil {
gui.Log.Error(err)
}

Expand All @@ -69,4 +84,6 @@ func (gui *Gui) runCommand(cmd *exec.Cmd, msg string) {
cmd.Stderr = io.Discard

gui.promptToReturn()

return err
}
4 changes: 4 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type TranslationSet struct {
CannotAttachStoppedContainerError string
CannotAccessDockerSocketError string
CannotKillChildError string
CannotStartStop string

Donate string
Cancel string
Expand Down Expand Up @@ -59,6 +60,7 @@ type TranslationSet struct {
Down string
DownWithVolumes string
Start string
StartStop string
Rebuild string
Recreate string
PreviousContext string
Expand Down Expand Up @@ -153,6 +155,7 @@ func englishSet() TranslationSet {
CannotAttachStoppedContainerError: "You cannot attach to a stopped container, you need to start it first (which you can actually do with the 'r' key) (yes I'm too lazy to do this automatically for you) (pretty cool that I get to communicate one-on-one with you in the form of an error message though)",
CannotAccessDockerSocketError: "Can't access docker socket at: unix:///var/run/docker.sock\nRun lazydocker as root or read https://docs.docker.com/install/linux/linux-postinstall/",
CannotKillChildError: "Waited three seconds for child process to stop. There may be an orphan process that continues to run on your system.",
CannotStartStop: "Cannot start stop this container",

Donate: "Donate",
Confirm: "Confirm",
Expand Down Expand Up @@ -182,6 +185,7 @@ func englishSet() TranslationSet {
Down: "down project",
DownWithVolumes: "down project with volumes",
Start: "start",
StartStop: "start/stop",
Rebuild: "rebuild",
Recreate: "recreate",
PreviousContext: "previous tab",
Expand Down
Loading