From 05237935eb54cbf9104dc92f59d963185755c3dc Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 31 Jan 2023 17:52:42 +0100 Subject: [PATCH] node option also for shell and respect env $SHELL --- internal/app/wwctl/container/exec/main.go | 9 +++++++++ internal/app/wwctl/container/shell/main.go | 7 ++++++- internal/app/wwctl/container/shell/root.go | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/app/wwctl/container/exec/main.go b/internal/app/wwctl/container/exec/main.go index 2324530f..7e974b9e 100644 --- a/internal/app/wwctl/container/exec/main.go +++ b/internal/app/wwctl/container/exec/main.go @@ -48,6 +48,11 @@ func runContainedCmd(args []string) error { if err := c.Run(); err != nil { fmt.Printf("Command exited non-zero, not rebuilding/updating VNFS image\n") + // defer is not called before os.Exit(0) + err = os.RemoveAll(tempDir) + if err != nil { + wwlog.Warn("Couldn't remove temp dir for ephermal mounts:", err) + } os.Exit(0) } return nil @@ -135,3 +140,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { func SetBinds(myBinds []string) { binds = append(binds, myBinds...) } + +func SetNode(myNode string) { + nodeName = myNode +} diff --git a/internal/app/wwctl/container/shell/main.go b/internal/app/wwctl/container/shell/main.go index 01a5cd04..415aa046 100644 --- a/internal/app/wwctl/container/shell/main.go +++ b/internal/app/wwctl/container/shell/main.go @@ -26,9 +26,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error { allargs = append(allargs, "--bind", b) } */ - args = append(args, "/usr/bin/bash") + shellName := os.Getenv("SHELL") + if shellName == "" { + shellName = "/usr/bin/bash" + } + args = append(args, shellName) allargs = append(allargs, args...) wwlog.Debug("Calling exec with args: %s", allargs) cntexec.SetBinds(binds) + cntexec.SetNode(nodeName) return cntexec.CobraRunE(cmd, allargs) } diff --git a/internal/app/wwctl/container/shell/root.go b/internal/app/wwctl/container/shell/root.go index 59f6c56b..dcec3f06 100644 --- a/internal/app/wwctl/container/shell/root.go +++ b/internal/app/wwctl/container/shell/root.go @@ -22,11 +22,13 @@ var ( }, FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, } - binds []string + binds []string + nodeName string ) func init() { baseCmd.PersistentFlags().StringArrayVarP(&binds, "bind", "b", []string{}, "Bind a local path into the container (must exist)") + baseCmd.PersistentFlags().StringVarP(&nodeName, "node", "n", "", "Create a read only view of the container for the given node") } // GetRootCommand returns the root cobra.Command for the application.