Use getJailFromArray so we can handle same name jails + check pertinence before jailing non existing DS
This commit is contained in:
parent
e7a6bdd376
commit
484e05e8d1
57
cmd/start.go
57
cmd/start.go
@ -212,25 +212,27 @@ func prepareJailedZfsDatasets(jail *Jail) error {
|
||||
}
|
||||
|
||||
func jailZfsDatasets(jail *Jail) error {
|
||||
for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") {
|
||||
// Jail dataset
|
||||
cmd := fmt.Sprintf("zfs jail %d %s/%s", jail.JID, jail.Zpool, d)
|
||||
out, err := executeCommand(cmd)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Error jailling zfs dataset %s: %v: out", d, err, out))
|
||||
}
|
||||
|
||||
// Mount from inside jail if mountpoint is set
|
||||
cmd = fmt.Sprintf("zfs get -H -o value mountpoint %s/%s", jail.JID, jail.Zpool, d)
|
||||
out, err = executeCommand(cmd)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Error getting zfs dataset %s mountpoint: %v: out", d, err, out))
|
||||
}
|
||||
if len(out) > 0 && out != "-" && (false == strings.EqualFold(out, "none")) {
|
||||
cmd = fmt.Sprintf("zfs mount %s", jail.Zpool, d)
|
||||
out, err = executeCommandInJail(jail, cmd)
|
||||
if jail.Config.Jail_zfs > 0 {
|
||||
for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") {
|
||||
// Jail dataset
|
||||
cmd := fmt.Sprintf("zfs jail %d %s/%s", jail.JID, jail.Zpool, d)
|
||||
out, err := executeCommand(cmd)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Error mounting zfs dataset %s: %v: out", d, err, out))
|
||||
return errors.New(fmt.Sprintf("Error jailling zfs dataset %s: %v: out", d, err, out))
|
||||
}
|
||||
|
||||
// Mount from inside jail if mountpoint is set
|
||||
cmd = fmt.Sprintf("zfs get -H -o value mountpoint %s/%s", jail.JID, jail.Zpool, d)
|
||||
out, err = executeCommand(cmd)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Error getting zfs dataset %s mountpoint: %v: out", d, err, out))
|
||||
}
|
||||
if len(out) > 0 && out != "-" && (false == strings.EqualFold(out, "none")) {
|
||||
cmd = fmt.Sprintf("zfs mount %s", jail.Zpool, d)
|
||||
out, err = executeCommandInJail(jail, cmd)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Error mounting zfs dataset %s: %v: out", d, err, out))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1028,18 +1030,11 @@ func StartJail(args []string) {
|
||||
var cj *Jail
|
||||
var err error
|
||||
|
||||
for _, j := range args {
|
||||
fmt.Printf("> Starting jail %s\n", j)
|
||||
|
||||
for i, rj := range gJails {
|
||||
if rj.Name == j {
|
||||
// Get jail reference, not a copy of it; So we can modify attributes
|
||||
cj = &gJails[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if cj == nil {
|
||||
fmt.Printf("Jail not found: %s\n", j)
|
||||
for _, a := range args {
|
||||
// Check if jail exist and is distinctly named
|
||||
cj, err = getJailFromArray(a, gJails)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting jail: %s\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -1048,6 +1043,8 @@ func StartJail(args []string) {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("> Starting jail %s\n", a)
|
||||
|
||||
// Set InternalName as it is used by some of these
|
||||
cj.InternalName = fmt.Sprintf("ioc-%s", cj.Name)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user