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 {
|
func jailZfsDatasets(jail *Jail) error {
|
||||||
for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") {
|
if jail.Config.Jail_zfs > 0 {
|
||||||
// Jail dataset
|
for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") {
|
||||||
cmd := fmt.Sprintf("zfs jail %d %s/%s", jail.JID, jail.Zpool, d)
|
// Jail dataset
|
||||||
out, err := executeCommand(cmd)
|
cmd := fmt.Sprintf("zfs jail %d %s/%s", jail.JID, jail.Zpool, d)
|
||||||
if err != nil {
|
out, err := executeCommand(cmd)
|
||||||
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 {
|
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 cj *Jail
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for _, j := range args {
|
for _, a := range args {
|
||||||
fmt.Printf("> Starting jail %s\n", j)
|
// Check if jail exist and is distinctly named
|
||||||
|
cj, err = getJailFromArray(a, gJails)
|
||||||
for i, rj := range gJails {
|
if err != nil {
|
||||||
if rj.Name == j {
|
fmt.Printf("Error getting jail: %s\n", err)
|
||||||
// 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)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1048,6 +1043,8 @@ func StartJail(args []string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("> Starting jail %s\n", a)
|
||||||
|
|
||||||
// Set InternalName as it is used by some of these
|
// Set InternalName as it is used by some of these
|
||||||
cj.InternalName = fmt.Sprintf("ioc-%s", cj.Name)
|
cj.InternalName = fmt.Sprintf("ioc-%s", cj.Name)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user