v0.40: basejail now created from NN.N-RELEASE
This commit is contained in:
parent
f41c93368d
commit
18d35b9224
@ -16,6 +16,11 @@ func CreateJail(args []string) {
|
|||||||
var err error
|
var err error
|
||||||
var jtype []string
|
var jtype []string
|
||||||
|
|
||||||
|
if gCreateArgs.BaseJail && gCreateArgs.Release == "" {
|
||||||
|
fmt.Println("Release should be set when creating basejail")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
if len(gCreateArgs.JailType) > 0 {
|
if len(gCreateArgs.JailType) > 0 {
|
||||||
jtype = []string{gCreateArgs.JailType}
|
jtype = []string{gCreateArgs.JailType}
|
||||||
}
|
}
|
||||||
@ -50,21 +55,20 @@ func CreateJail(args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get base template if specified
|
// Get base template if specified
|
||||||
if len(gCreateArgs.BaseTemplate) > 0 {
|
if gCreateArgs.BaseJail {
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Create based jail from a template
|
* Create based jail from a template
|
||||||
*/
|
*/
|
||||||
log.Debugf("Jail will be created from a base template\n")
|
log.Debugf("Jail will be created read-only from release %s\n", gCreateArgs.Release)
|
||||||
bj, err := getJailFromArray(gCreateArgs.BaseTemplate, []string{"template"}, gJails)
|
|
||||||
if err != nil {
|
// First check if we got release on the same datastore
|
||||||
if strings.EqualFold(err.Error(), "Jail not found") {
|
releasePath := fmt.Sprintf("%s/releases/%s/root", ds.Mountpoint, gCreateArgs.Release)
|
||||||
fmt.Printf("Template not found\n")
|
_, err := os.Stat(releasePath)
|
||||||
return
|
if os.IsNotExist(err) {
|
||||||
} else {
|
fmt.Printf("ERROR: Release locally not available. Run \"gocage fetch\"\n")
|
||||||
fmt.Printf("ERROR: %s\n", err.Error())
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create jail datasets
|
// Create jail datasets
|
||||||
dstDset := fmt.Sprintf("%s/jails/%s", ds.ZFSDataset, jname)
|
dstDset := fmt.Sprintf("%s/jails/%s", ds.ZFSDataset, jname)
|
||||||
fmt.Printf(" > Initialize dataset %s\n", dstDset)
|
fmt.Printf(" > Initialize dataset %s\n", dstDset)
|
||||||
@ -87,7 +91,7 @@ func CreateJail(args []string) {
|
|||||||
dstRootDir := fmt.Sprintf("%s/jails/%s/root", ds.Mountpoint, jname)
|
dstRootDir := fmt.Sprintf("%s/jails/%s/root", ds.Mountpoint, jname)
|
||||||
for _, d := range append(gBaseDirs, gEmptyDirs...) {
|
for _, d := range append(gBaseDirs, gEmptyDirs...) {
|
||||||
dstPath := dstRootDir
|
dstPath := dstRootDir
|
||||||
srcPath := bj.RootPath
|
srcPath := releasePath
|
||||||
for _, cd := range strings.Split(d, "/") {
|
for _, cd := range strings.Split(d, "/") {
|
||||||
srcPath = fmt.Sprintf("%s/%s", srcPath, cd)
|
srcPath = fmt.Sprintf("%s/%s", srcPath, cd)
|
||||||
dstPath = fmt.Sprintf("%s/%s", dstPath, cd)
|
dstPath = fmt.Sprintf("%s/%s", dstPath, cd)
|
||||||
@ -110,9 +114,9 @@ func CreateJail(args []string) {
|
|||||||
// Copy these from basejail
|
// Copy these from basejail
|
||||||
fmt.Printf(" > Create base writable directories\n")
|
fmt.Printf(" > Create base writable directories\n")
|
||||||
for _, d := range gCopyDirs {
|
for _, d := range gCopyDirs {
|
||||||
err := cp.Copy(fmt.Sprintf("%s/%s", bj.RootPath, d), fmt.Sprintf("%s/%s", dstRootDir, d))
|
err := cp.Copy(fmt.Sprintf("%s/%s", releasePath, d), fmt.Sprintf("%s/%s", dstRootDir, d))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR copying %s to %s: %s\n", fmt.Sprintf("%s/%s", bj.RootPath, d),
|
fmt.Printf("ERROR copying %s to %s: %s\n", fmt.Sprintf("%s/%s", releasePath, d),
|
||||||
fmt.Sprintf("%s/%s", dstRootDir, d), err.Error())
|
fmt.Sprintf("%s/%s", dstRootDir, d), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -150,7 +154,7 @@ func CreateJail(args []string) {
|
|||||||
// 2. Add a json item to config ("basejail_template" p.e.), but iocage would delete it once jail is started from iocage
|
// 2. Add a json item to config ("basejail_template" p.e.), but iocage would delete it once jail is started from iocage
|
||||||
// 3. Add a gocage specific config ("config.gocage.json" p.e.)
|
// 3. Add a gocage specific config ("config.gocage.json" p.e.)
|
||||||
j.Config.Jailtype = "basejail"
|
j.Config.Jailtype = "basejail"
|
||||||
j.Config.Origin = bj.Name
|
j.Config.Origin = gCreateArgs.Release
|
||||||
j.Config.Host_hostname = jname
|
j.Config.Host_hostname = jname
|
||||||
j.Config.Host_hostuuid = jname
|
j.Config.Host_hostuuid = jname
|
||||||
|
|
||||||
@ -166,7 +170,7 @@ func CreateJail(args []string) {
|
|||||||
defer fstabHandle.Close()
|
defer fstabHandle.Close()
|
||||||
|
|
||||||
for _, d := range gBaseDirs {
|
for _, d := range gBaseDirs {
|
||||||
fmt.Fprintf(fstabHandle, "%s\t%s\tnullfs\tro\t0\t0\n", fmt.Sprintf("%s/%s", bj.RootPath, d), fmt.Sprintf("%s/%s", dstRootDir, d))
|
fmt.Fprintf(fstabHandle, "%s\t%s\tnullfs\tro\t0\t0\n", fmt.Sprintf("%s/%s", releasePath, d), fmt.Sprintf("%s/%s", dstRootDir, d))
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf(" > Jail created!\n")
|
fmt.Printf(" > Jail created!\n")
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gVersion = "0.39"
|
gVersion = "0.40"
|
||||||
|
|
||||||
// TODO : Get from $jail_zpool/defaults.json
|
// TODO : Get from $jail_zpool/defaults.json
|
||||||
MIN_DYN_DEVFS_RULESET = 1000
|
MIN_DYN_DEVFS_RULESET = 1000
|
||||||
@ -22,7 +22,7 @@ const (
|
|||||||
|
|
||||||
type createArgs struct {
|
type createArgs struct {
|
||||||
Release string
|
Release string
|
||||||
BaseTemplate string
|
BaseJail bool
|
||||||
Datastore string
|
Datastore string
|
||||||
JailType string
|
JailType string
|
||||||
}
|
}
|
||||||
@ -420,7 +420,7 @@ func init() {
|
|||||||
upgradeCmd.MarkFlagRequired("release")
|
upgradeCmd.MarkFlagRequired("release")
|
||||||
|
|
||||||
createCmd.Flags().StringVarP(&gCreateArgs.Release, "release", "r", "", "Release for the jail (e.g.: \"13.1-RELEASE\"")
|
createCmd.Flags().StringVarP(&gCreateArgs.Release, "release", "r", "", "Release for the jail (e.g.: \"13.1-RELEASE\"")
|
||||||
createCmd.Flags().StringVarP(&gCreateArgs.BaseTemplate, "basetpl", "b", "", "Base template. This will create a jail based on basetpl, so every up(date|grade) made to basetpl will immediately propagate to new jail\n")
|
createCmd.Flags().BoolVarP(&gCreateArgs.BaseJail, "basejail", "b", false, "Basejail. This will create a jail mounted read only from a release, so every up(date|grade) made to this release will immediately propagate to new jail.\n")
|
||||||
createCmd.Flags().StringVarP(&gCreateArgs.Datastore, "datastore", "d", "", "Datastore to create the jail on. Defaults to first declared in config.")
|
createCmd.Flags().StringVarP(&gCreateArgs.Datastore, "datastore", "d", "", "Datastore to create the jail on. Defaults to first declared in config.")
|
||||||
|
|
||||||
// Now declare commands
|
// Now declare commands
|
||||||
|
Loading…
Reference in New Issue
Block a user