gocage console jailname now working
This commit is contained in:
parent
0bf825ee5a
commit
a446a19a08
@ -1,39 +1,39 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ShellJail(args []string) error {
|
func ShellJail(args []string) error {
|
||||||
var jailnames []string
|
// We cant shell more than one jail bc we replace gocage execution with jexec, so there wont be no return to gocage
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
for _, a := range args {
|
for _, cj := range gJails {
|
||||||
jailnames = append(jailnames, a)
|
if strings.EqualFold(cj.Name, args[0]) {
|
||||||
}
|
shellJail(cj)
|
||||||
}
|
|
||||||
|
|
||||||
for _, cj := range gJails {
|
|
||||||
for _, jn := range jailnames {
|
|
||||||
if strings.EqualFold(cj.Name, jn) {
|
|
||||||
err := shellJail(cj)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Jail not found: %s\n", args[0])
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func shellJail(jail Jail) error {
|
func shellJail(jail Jail) {
|
||||||
cmd := fmt.Sprintf("jexec %s /bin/csh", jail.JID)
|
jid := strconv.Itoa(jail.JID)
|
||||||
_, err := executeCommand(cmd)
|
|
||||||
|
err := syscall.Exec("/usr/sbin/jexec", []string{"jexec", jid, "/bin/csh"}, os.Environ())
|
||||||
|
|
||||||
|
// We should never get here, as syscall.Exec replace the gocage binary execution with jexec
|
||||||
|
// This means the moment syscall.Exec fires, gocage execution halt.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("Error executing %s: %s", cmd, err.Error())
|
log.Printf("Exec returned %v\n", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
32
cmd/root.go
32
cmd/root.go
@ -15,7 +15,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gVersion = "0.27c"
|
gVersion = "0.27d"
|
||||||
|
|
||||||
|
DEVFS_DEFAULT_RULESET = 4
|
||||||
|
|
||||||
|
// TODO : Get from $jail_zpool/defaults.json
|
||||||
|
MIN_DYN_DEVFS_RULESET = 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -35,6 +40,7 @@ var (
|
|||||||
gSnapshotName string
|
gSnapshotName string
|
||||||
|
|
||||||
gMigrateDestPool string
|
gMigrateDestPool string
|
||||||
|
gYesToAll bool
|
||||||
|
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "gocage",
|
Use: "gocage",
|
||||||
@ -98,16 +104,16 @@ ex: gocage list srv-db srv-web`,
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/* shellCmd = &cobra.Command {
|
shellCmd = &cobra.Command {
|
||||||
Use: "console",
|
Use: "console",
|
||||||
Short: "Execute shell on jail",
|
Short: "Execute shell on jail",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// Load inventory
|
// Load inventory
|
||||||
ListJails(args, false)
|
ListJails(args, false)
|
||||||
ShellJail(args)
|
ShellJail(args)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
setCmd = &cobra.Command{
|
setCmd = &cobra.Command{
|
||||||
Use: "set",
|
Use: "set",
|
||||||
Short: "Set a jail property",
|
Short: "Set a jail property",
|
||||||
@ -194,7 +200,7 @@ You can specify multiple jails.`,
|
|||||||
|
|
||||||
migrateCmd = &cobra.Command{
|
migrateCmd = &cobra.Command{
|
||||||
Use: "migrate",
|
Use: "migrate",
|
||||||
Short: "Migrate jail to another zpool",
|
Short: "Migrate jail to another zfs pool",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// Load inventory
|
// Load inventory
|
||||||
ListJails(args, false)
|
ListJails(args, false)
|
||||||
@ -241,6 +247,7 @@ func init() {
|
|||||||
snapshotRollbackCmd.MarkFlagRequired("snapname")
|
snapshotRollbackCmd.MarkFlagRequired("snapname")
|
||||||
|
|
||||||
migrateCmd.Flags().StringVarP(&gMigrateDestPool, "destpool", "d", "", "Name of zfs destination pool for jail")
|
migrateCmd.Flags().StringVarP(&gMigrateDestPool, "destpool", "d", "", "Name of zfs destination pool for jail")
|
||||||
|
migrateCmd.Flags().BoolVarP(&gYesToAll, "yes", "y", false, "Answer yes to all questions")
|
||||||
migrateCmd.MarkFlagRequired("destpool")
|
migrateCmd.MarkFlagRequired("destpool")
|
||||||
|
|
||||||
// Now declare commands
|
// Now declare commands
|
||||||
@ -249,6 +256,7 @@ func init() {
|
|||||||
listCmd.AddCommand(listPropsCmd)
|
listCmd.AddCommand(listPropsCmd)
|
||||||
rootCmd.AddCommand(stopCmd)
|
rootCmd.AddCommand(stopCmd)
|
||||||
rootCmd.AddCommand(startCmd)
|
rootCmd.AddCommand(startCmd)
|
||||||
|
rootCmd.AddCommand(shellCmd)
|
||||||
rootCmd.AddCommand(getCmd)
|
rootCmd.AddCommand(getCmd)
|
||||||
rootCmd.AddCommand(setCmd)
|
rootCmd.AddCommand(setCmd)
|
||||||
rootCmd.AddCommand(snapshotCmd)
|
rootCmd.AddCommand(snapshotCmd)
|
||||||
|
Loading…
Reference in New Issue
Block a user