Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
ce79783540 | |||
18d35b9224 | |||
f41c93368d | |||
452b0e4b4e | |||
dbe9622a01 | |||
6ead474a78 | |||
4edd0b7414 | |||
b54ebfd915 | |||
69665fdcef | |||
7e1c213ff4 | |||
26ceb1630a | |||
87e9ae894a | |||
ed5f8f0b1c |
@ -22,13 +22,9 @@ gocage create jail1 -r 13.2-RELEASE
|
||||
gocage set Config.Ip4_addr="vnet0|192.168.1.91/24" Config.Vnet=1 jail1
|
||||
</code></pre>
|
||||
|
||||
Create basejail (jail based on a template, system will be nullfs read-only mounted from the template):
|
||||
Create basejail (jail based on a release, system will be nullfs read-only mounted from the release directory):
|
||||
<pre><code>
|
||||
# First create basetpl from 13.2-RELEASE, set it as a template
|
||||
gocage create -r 13.2-RELEASE basetpl
|
||||
gocage set Config.Jailtype="template" basetpl
|
||||
# Then create basejail1 based on basetpl
|
||||
gocage create -b basetpl basejail1
|
||||
gocage create -b -r 14.0-RELEASE basejail1
|
||||
</code></pre>
|
||||
|
||||
|
||||
|
11
TODO.md
11
TODO.md
@ -1,8 +1,19 @@
|
||||
Replicating jails between two servers (use zrepl)
|
||||
Manage remote jails :
|
||||
- Make gocage a service
|
||||
- All commands should become API endpoint
|
||||
- How to handle authentication ?
|
||||
|
||||
DEBUG:
|
||||
- cmd/list.go:275:
|
||||
// FIXME ??? Shouldn't be ioc-$Name ?
|
||||
j.InternalName = rj.Name
|
||||
- WriteConfigToDisk don't write neither "release" in cmd stop neither "last_started" in cmd start
|
||||
26/08/2023 : Last_started is updated
|
||||
|
||||
BUGS:
|
||||
- unable to set values containing equal sign :
|
||||
# gocage set Config.Exec_poststart="jail -m allow.mount.linprocfs=1 name=ioc-poudriere-noo" poudriere-noo
|
||||
Error parsing args: Config.Exec_poststart=jail -m allow.mount.linprocfs=1 name=ioc-poudriere-noo
|
||||
- Fix fstab when migrating jail
|
||||
|
||||
|
@ -16,6 +16,11 @@ func CreateJail(args []string) {
|
||||
var err error
|
||||
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 {
|
||||
jtype = []string{gCreateArgs.JailType}
|
||||
}
|
||||
@ -50,21 +55,20 @@ func CreateJail(args []string) {
|
||||
}
|
||||
|
||||
// Get base template if specified
|
||||
if len(gCreateArgs.BaseTemplate) > 0 {
|
||||
if gCreateArgs.BaseJail {
|
||||
/**************************************************************************
|
||||
* Create based jail from a template
|
||||
*/
|
||||
log.Debugf("Jail will be created from a base template\n")
|
||||
bj, err := getJailFromArray(gCreateArgs.BaseTemplate, []string{"template"}, gJails)
|
||||
if err != nil {
|
||||
if strings.EqualFold(err.Error(), "Jail not found") {
|
||||
fmt.Printf("Template not found\n")
|
||||
return
|
||||
} else {
|
||||
fmt.Printf("ERROR: %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
log.Debugf("Jail will be created read-only from release %s\n", gCreateArgs.Release)
|
||||
|
||||
// First check if we got release on the same datastore
|
||||
releasePath := fmt.Sprintf("%s/releases/%s/root", ds.Mountpoint, gCreateArgs.Release)
|
||||
_, err := os.Stat(releasePath)
|
||||
if os.IsNotExist(err) {
|
||||
fmt.Printf("ERROR: Release locally not available. Run \"gocage fetch\"\n")
|
||||
return
|
||||
}
|
||||
|
||||
// Create jail datasets
|
||||
dstDset := fmt.Sprintf("%s/jails/%s", ds.ZFSDataset, jname)
|
||||
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)
|
||||
for _, d := range append(gBaseDirs, gEmptyDirs...) {
|
||||
dstPath := dstRootDir
|
||||
srcPath := bj.RootPath
|
||||
srcPath := releasePath
|
||||
for _, cd := range strings.Split(d, "/") {
|
||||
srcPath = fmt.Sprintf("%s/%s", srcPath, cd)
|
||||
dstPath = fmt.Sprintf("%s/%s", dstPath, cd)
|
||||
@ -110,9 +114,9 @@ func CreateJail(args []string) {
|
||||
// Copy these from basejail
|
||||
fmt.Printf(" > Create base writable directories\n")
|
||||
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 {
|
||||
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())
|
||||
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
|
||||
// 3. Add a gocage specific config ("config.gocage.json" p.e.)
|
||||
j.Config.Jailtype = "basejail"
|
||||
j.Config.Origin = bj.Name
|
||||
j.Config.Origin = gCreateArgs.Release
|
||||
j.Config.Host_hostname = jname
|
||||
j.Config.Host_hostuuid = jname
|
||||
|
||||
@ -166,7 +170,7 @@ func CreateJail(args []string) {
|
||||
defer fstabHandle.Close()
|
||||
|
||||
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")
|
||||
|
@ -1,8 +1,9 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"fmt"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -20,7 +21,7 @@ func GetJailProperties(args []string) {
|
||||
jail, err = getJailFromArray(a, []string{""}, gJails)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err.Error())
|
||||
return
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
props = append(props, a)
|
||||
@ -105,20 +106,20 @@ func SetJailProperties(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
// Get jail by index to modify it
|
||||
for i, _ := range gJails {
|
||||
if gJails[i].Name == jail.Name {
|
||||
for _, p := range props {
|
||||
err := setStructFieldValue(&gJails[i], p.name, p.value)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err.Error())
|
||||
return
|
||||
} else {
|
||||
fmt.Printf("%s: %s set to %s\n", gJails[i].Name, p.name, p.value)
|
||||
gJails[i].ConfigUpdated = true
|
||||
}
|
||||
}
|
||||
writeConfigToDisk(&gJails[i], false)
|
||||
cj, err := getJailFromArray(jail.Name, []string{""}, gJails)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting jail %s: %v\n", jail.Name, err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, p := range props {
|
||||
err := setStructFieldValue(cj, p.name, p.value)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err.Error())
|
||||
return
|
||||
} else {
|
||||
fmt.Printf("%s: %s set to %s\n", cj.Name, p.name, p.value)
|
||||
}
|
||||
}
|
||||
cj.WriteConfigToDisk(false)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
gVersion = "0.38"
|
||||
gVersion = "0.40"
|
||||
|
||||
// TODO : Get from $jail_zpool/defaults.json
|
||||
MIN_DYN_DEVFS_RULESET = 1000
|
||||
@ -22,7 +22,7 @@ const (
|
||||
|
||||
type createArgs struct {
|
||||
Release string
|
||||
BaseTemplate string
|
||||
BaseJail bool
|
||||
Datastore string
|
||||
JailType string
|
||||
}
|
||||
@ -420,7 +420,7 @@ func init() {
|
||||
upgradeCmd.MarkFlagRequired("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.")
|
||||
|
||||
// Now declare commands
|
||||
|
35
cmd/start.go
35
cmd/start.go
@ -340,7 +340,7 @@ func configureDhcpOrAcceptRtadv(jail *Jail, ipproto int, enable bool) error {
|
||||
|
||||
if ipproto == IPv6 {
|
||||
key = fmt.Sprintf("%s_ipv6", key)
|
||||
value = "inet6 auto_linklocal accept_rtadv autoconf"
|
||||
value = "\"inet6 auto_linklocal accept_rtadv autoconf\""
|
||||
}
|
||||
|
||||
if enable == true {
|
||||
@ -363,7 +363,7 @@ func checkRtsold(jail *Jail) error {
|
||||
if strings.Contains(jail.Config.Ip6_addr, "accept_rtadv") == false {
|
||||
return fmt.Errorf("Must set at least one ip6_addr to accept_rtadv!\n")
|
||||
}
|
||||
err := enableRcKeyValue(jail.ConfigPath, "rtsold_enable", "yes")
|
||||
err := enableRcKeyValue(fmt.Sprintf("%s/etc/rc.conf", jail.RootPath), "rtsold_enable", "yes")
|
||||
if err != nil {
|
||||
return fmt.Errorf("ERROR setting rtsold_enable=YES with sysrc for jail %s: %s\n", jail.Name, err)
|
||||
}
|
||||
@ -810,7 +810,9 @@ func generateMAC(jail *Jail, nic string) ([]byte, []byte, error) {
|
||||
}
|
||||
|
||||
hsmac := append(prefix, suffix...)
|
||||
jsmac := append(hsmac[:5], hsmac[5]+1)
|
||||
jsmac := make([]byte, 6)
|
||||
copy(jsmac, hsmac)
|
||||
jsmac[5] = jsmac[5] + 1
|
||||
|
||||
// Save MACs to config
|
||||
pname := fmt.Sprintf("Config.%s_mac", strings.Title(nic))
|
||||
@ -840,7 +842,7 @@ func setupVnetInterfaceHostSide(jail *Jail) ([]string, error) {
|
||||
bridge := v[1]
|
||||
|
||||
// Get host side MAC
|
||||
pname := fmt.Sprintf("Config.%s_mac", nic)
|
||||
pname := fmt.Sprintf("Config.%s_mac", strings.Title(nic))
|
||||
var val *reflect.Value
|
||||
val, pname, err = getStructFieldValue(jail, pname)
|
||||
if err != nil {
|
||||
@ -853,7 +855,16 @@ func setupVnetInterfaceHostSide(jail *Jail) ([]string, error) {
|
||||
return []string{}, err
|
||||
}
|
||||
} else {
|
||||
hsmac = val.Bytes()
|
||||
if strings.EqualFold(val.String(), "none") {
|
||||
hsmac, _, err = generateMAC(jail, nic)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
}
|
||||
hsmac, err = hex.DecodeString(strings.Split(val.String(), " ")[0])
|
||||
if err != nil {
|
||||
return []string{}, fmt.Errorf("Error converting %s to hex\n", strings.Split(val.String(), " ")[0])
|
||||
}
|
||||
}
|
||||
|
||||
// Get bridge MTU
|
||||
@ -909,7 +920,9 @@ func setupVnetInterfaceJailSide(jail *Jail, hostepairs []string) error {
|
||||
|
||||
for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
|
||||
v := strings.Split(i, "|")
|
||||
ip4s[v[0]] = v[1]
|
||||
if len(v) > 1 {
|
||||
ip4s[v[0]] = v[1]
|
||||
}
|
||||
}
|
||||
for _, i := range strings.Split(jail.Config.Ip6_addr, ",") {
|
||||
v := strings.Split(i, "|")
|
||||
@ -934,7 +947,7 @@ func setupVnetInterfaceJailSide(jail *Jail, hostepairs []string) error {
|
||||
jsepair := fmt.Sprintf("%sb", strings.TrimSuffix(hostepairs[i], "a"))
|
||||
|
||||
// Get jail side MAC
|
||||
pname := fmt.Sprintf("Config.%s_mac", nic)
|
||||
pname := fmt.Sprintf("Config.%s_mac", strings.Title(nic))
|
||||
var val *reflect.Value
|
||||
val, pname, err = getStructFieldValue(jail, pname)
|
||||
if err != nil {
|
||||
@ -947,7 +960,11 @@ func setupVnetInterfaceJailSide(jail *Jail, hostepairs []string) error {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
jsmac = val.Bytes()
|
||||
jsmac, err = hex.DecodeString(strings.Split(val.String(), " ")[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error converting %s to hex\n", strings.Split(val.String(), " ")[1])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cmd := fmt.Sprintf("/sbin/ifconfig %s vnet %s", jsepair, jail.InternalName)
|
||||
@ -1431,7 +1448,7 @@ func StartJail(args []string) {
|
||||
fmt.Printf(" > Setup VNet network: OK\n")
|
||||
|
||||
// Set default route, unless main network is dhcp
|
||||
if ! cj.isFirstNetDhcp() {
|
||||
if ! cj.isFirstNetDhcp() && !strings.EqualFold(cj.Config.Ip4_addr, "none") {
|
||||
fmt.Printf(" > Setup default ipv4 gateway:\n")
|
||||
cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d route add default %s", cj.Config.Exec_fib, cj.JID, cj.Config.Defaultrouter)
|
||||
out, err := executeCommand(cmd)
|
||||
|
33
cmd/stop.go
33
cmd/stop.go
@ -83,15 +83,30 @@ func umountAndUnjailZFS(jail *Jail) error {
|
||||
}
|
||||
|
||||
func destroyVNetInterfaces(jail *Jail) error {
|
||||
for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
|
||||
iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
|
||||
fmt.Printf("%s: ", iname)
|
||||
_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
|
||||
//_, err := executeScript(fmt.Sprintf("ifconfig %s destroy >/dev/null 2>&1", iname))
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("OK\n")
|
||||
if !strings.EqualFold(jail.Config.Ip4_addr, "none") {
|
||||
for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
|
||||
iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
|
||||
fmt.Printf("%s: ", iname)
|
||||
_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
|
||||
//_, err := executeScript(fmt.Sprintf("ifconfig %s destroy >/dev/null 2>&1", iname))
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("OK\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
if !strings.EqualFold(jail.Config.Ip6_addr, "none") {
|
||||
for _, i := range strings.Split(jail.Config.Ip6_addr, ",") {
|
||||
iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
|
||||
fmt.Printf("%s: ", iname)
|
||||
_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
|
||||
//_, err := executeScript(fmt.Sprintf("ifconfig %s destroy >/dev/null 2>&1", iname))
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("OK\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
//"log"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
@ -63,6 +64,12 @@ func UpdateJail(args []string) {
|
||||
continue
|
||||
}
|
||||
|
||||
// We cant update basejail as system is readonly
|
||||
if strings.EqualFold(cj.Config.Jailtype, "basejail") {
|
||||
fmt.Printf("%s is a basejail using %s system files. Please update %s!\n", cj.Name, cj.Config.Origin, cj.Config.Origin)
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf(" > Snapshot jail %s\n", cj.Name)
|
||||
// Set snapshot name
|
||||
dt := time.Now()
|
||||
|
@ -917,7 +917,8 @@ func getFstab(path string) ([]Mount, error) {
|
||||
scan := bufio.NewScanner(f)
|
||||
for scan.Scan() {
|
||||
res := strings.Fields(scan.Text())
|
||||
if len(res) != 6 {
|
||||
// iocage create lines like that : "/iocage/releases/13.2-RELEASE/root/bin /iocage/jails/smtp-router-02/root/bin nullfs ro 0 0 # Added by iocage on 2023-10-10 17:20:51"
|
||||
if (len(res) > 6 && !strings.EqualFold(res[6], "#")) || len(res) < 6 {
|
||||
return mounts, fmt.Errorf("Incorrect format for fstab line %s", scan.Text())
|
||||
}
|
||||
freq, err := strconv.Atoi(res[4])
|
||||
|
Reference in New Issue
Block a user