Generate resolv.conf, copy localtime
This commit is contained in:
parent
e1f6b4f6f9
commit
0c7293ae66
97
cmd/start.go
97
cmd/start.go
@ -1,19 +1,21 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"github.com/c-robinson/iplib"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"io/ioutil"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"gocage/jail"
|
"gocage/jail"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
||||||
|
"github.com/c-robinson/iplib"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mountProcFs(jail *Jail) error {
|
func mountProcFs(jail *Jail) error {
|
||||||
@ -998,6 +1000,48 @@ func setupVnetInterfaceJailSide(jail *Jail, hsepair string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateResolvConf(jail *Jail) error {
|
||||||
|
if jail.Config.Resolver != "/etc/resolv.conf" && jail.Config.Resolver != "none" && jail.Config.Resolver != "/dev/null" {
|
||||||
|
f, err := os.Create(fmt.Sprintf("%s/etc/resolv.conf", jail.RootPath))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
for _, l := range strings.Split(jail.Config.Resolver, ";") {
|
||||||
|
f.WriteString(fmt.Sprintf("%s\n", l))
|
||||||
|
}
|
||||||
|
} else if jail.Config.Resolver == "none" {
|
||||||
|
read, err := ioutil.ReadFile("/etc/resolv.conf")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error opening /etc/resolv.conf: %v", err)
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(fmt.Sprintf("%s/etc/resolv.conf", jail.RootPath), read, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error writing to %s/etc/resolv.conf: %v", jail.RootPath, err)
|
||||||
|
}
|
||||||
|
} else if jail.Config.Resolver == "/dev/null" {
|
||||||
|
// Just do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyLocalTime(jail *Jail) error {
|
||||||
|
if jail.Config.Host_time > 0 {
|
||||||
|
read, err := ioutil.ReadFile("/etc/localtime")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error opening /etc/localtime: %v", err)
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(fmt.Sprintf("%s/etc/localtime", jail.RootPath), read, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error writing to %s/etc/localtime: %v", jail.RootPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: Umount all FS
|
// TODO: Umount all FS
|
||||||
// TODO: Delete devfs ruleset
|
// TODO: Delete devfs ruleset
|
||||||
// TODO: Remove /var/run/jail-${internalname}.conf
|
// TODO: Remove /var/run/jail-${internalname}.conf
|
||||||
@ -1304,7 +1348,7 @@ func StartJail(args []string) {
|
|||||||
fmt.Printf(" > Setup default ipv4 gateway:\n")
|
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)
|
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)
|
out, err := executeCommand(cmd)
|
||||||
if err == nil && len(out) > 0 {
|
if err != nil && len(out) > 0 {
|
||||||
fmt.Printf("Error: %v: %s\n", err, out)
|
fmt.Printf("Error: %v: %s\n", err, out)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" > Setup default ipv4 gateway: OK\n")
|
fmt.Printf(" > Setup default ipv4 gateway: OK\n")
|
||||||
@ -1314,30 +1358,43 @@ func StartJail(args []string) {
|
|||||||
fmt.Printf(" > Setup default ipv6 gateway:\n")
|
fmt.Printf(" > Setup default ipv6 gateway:\n")
|
||||||
cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d route add -6 default %s", cj.Config.Exec_fib, cj.JID, cj.Config.Defaultrouter6)
|
cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d route add -6 default %s", cj.Config.Exec_fib, cj.JID, cj.Config.Defaultrouter6)
|
||||||
out, err := executeCommand(cmd)
|
out, err := executeCommand(cmd)
|
||||||
if err == nil && len(out) > 0 {
|
if err != nil && len(out) > 0 {
|
||||||
fmt.Printf("Error: %v: %s\n", err, out)
|
fmt.Printf("Error: %v: %s\n", err, out)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" > Setup default ipv6 gateway: OK\n")
|
fmt.Printf(" > Setup default ipv6 gateway: OK\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cj.Config.Jail_zfs > 0 {
|
||||||
err = jailZfsDatasets(cj)
|
fmt.Printf(" > Jail ZFS datasets:\n")
|
||||||
if err != nil {
|
err = jailZfsDatasets(cj)
|
||||||
fmt.Printf("%v\n", err)
|
if err != nil {
|
||||||
return
|
fmt.Printf("%v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf(" > Jail ZFS datasets: OK\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// WIP 26/06/2022 : https://github.com/iocage/iocage/blob/master/iocage_lib/ioc_start.py#L792
|
// WIP 26/06/2022 : https://github.com/iocage/iocage/blob/master/iocage_lib/ioc_start.py#L792
|
||||||
// TODO
|
// TODO
|
||||||
//generateResolvConf(cj)
|
err = generateResolvConf(cj)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cj.Config.Host_time > 0 {
|
||||||
|
err = copyLocalTime(cj)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start services
|
// Start services
|
||||||
if len(cj.Config.Exec_start) > 0 {
|
if len(cj.Config.Exec_start) > 0 {
|
||||||
fmt.Printf(" > Start services:\n")
|
fmt.Printf(" > Start services:\n")
|
||||||
cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d %s", cj.Config.Exec_fib, cj.JID, cj.Config.Exec_start)
|
cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d %s", cj.Config.Exec_fib, cj.JID, cj.Config.Exec_start)
|
||||||
out, err := executeCommand(cmd)
|
out, err := executeCommand(cmd)
|
||||||
if err == nil && len(out) > 0 {
|
if err != nil && len(out) > 0 {
|
||||||
fmt.Printf("Error: %v: %s\n", err, out)
|
fmt.Printf("Error: %v: %s\n", err, out)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" > Start services: OK\n")
|
fmt.Printf(" > Start services: OK\n")
|
||||||
@ -1346,6 +1403,18 @@ func StartJail(args []string) {
|
|||||||
|
|
||||||
|
|
||||||
// TODO: Execute Exec_poststart
|
// TODO: Execute Exec_poststart
|
||||||
|
if len(cj.Config.Exec_poststart) > 0 {
|
||||||
|
fmt.Printf(" > Execute post-start:\n")
|
||||||
|
cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d %s", cj.Config.Exec_fib, cj.JID, cj.Config.Exec_poststart)
|
||||||
|
out, err := executeCommand(cmd)
|
||||||
|
if err != nil && len(out) > 0 {
|
||||||
|
fmt.Printf("Error: %v: %s\n", err, out)
|
||||||
|
} else {
|
||||||
|
fmt.Printf(" > Execute post-start: OK\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName))
|
out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName))
|
||||||
|
Loading…
Reference in New Issue
Block a user