Compare commits
3 Commits
7c3e14f0f1
...
812c77790a
Author | SHA1 | Date | |
---|---|---|---|
812c77790a | |||
7575da794e | |||
6f9bb504be |
3
CHANGELOG
Normal file
3
CHANGELOG
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
v.0.33b : Support jaling datasets on differents pools : jail_zfs_dataset now have to include the pool name
|
||||||
|
v.0.33c : Parallelize start/stop of jails with same priority
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gVersion = "0.33b"
|
gVersion = "0.33c"
|
||||||
|
|
||||||
// TODO : Get from $jail_zpool/defaults.json
|
// TODO : Get from $jail_zpool/defaults.json
|
||||||
MIN_DYN_DEVFS_RULESET = 1000
|
MIN_DYN_DEVFS_RULESET = 1000
|
||||||
|
52
cmd/start.go
52
cmd/start.go
@ -4,6 +4,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"errors"
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -1055,6 +1056,9 @@ func cleanAfterStartCrash() {
|
|||||||
// Start all jails with boot=true, in priority order
|
// Start all jails with boot=true, in priority order
|
||||||
func StartJailsAtBoot() {
|
func StartJailsAtBoot() {
|
||||||
var startList []Jail
|
var startList []Jail
|
||||||
|
var wg *sync.WaitGroup
|
||||||
|
var curThNb int
|
||||||
|
var curPri int
|
||||||
|
|
||||||
// Get boot enabled jails
|
// Get boot enabled jails
|
||||||
for _, j := range gJails {
|
for _, j := range gJails {
|
||||||
@ -1072,11 +1076,51 @@ func StartJailsAtBoot() {
|
|||||||
}
|
}
|
||||||
JailsOrderedBy(fct.Interface().(jailLessFunc)).Sort(startList)
|
JailsOrderedBy(fct.Interface().(jailLessFunc)).Sort(startList)
|
||||||
|
|
||||||
for _, j := range startList {
|
wg = new(sync.WaitGroup)
|
||||||
|
curThNb = 0
|
||||||
|
for i, j := range startList {
|
||||||
jFullName := fmt.Sprintf("%s/%s", j.Datastore, j.Name)
|
jFullName := fmt.Sprintf("%s/%s", j.Datastore, j.Name)
|
||||||
log.Debugf("Starting %s with priority %s\n", jFullName, j.Config.Priority)
|
log.Debugf("Starting %s with priority %s\n", jFullName, j.Config.Priority)
|
||||||
StartJail([]string{jFullName})
|
jailPri, err := strconv.Atoi(j.Config.Priority)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Invalid format for Priority (Jail %s)\n", jFullName))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curThNb >= gMaxThreads || i == 0) {
|
||||||
|
// FIXME : Use a pool instead of waiting for all threads to run a new one
|
||||||
|
wg.Wait()
|
||||||
|
curThNb = 0
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
curPri = jailPri
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StartJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
} else {
|
||||||
|
if (curPri == jailPri) {
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StartJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
} else {
|
||||||
|
wg.Wait()
|
||||||
|
curThNb = 0
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
curPri = jailPri
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StartJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1423,9 +1467,9 @@ func StartJail(args []string) {
|
|||||||
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)
|
err := executeCommandNonBlocking(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\n", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" > Start services: OK\n")
|
fmt.Printf(" > Start services: OK\n")
|
||||||
}
|
}
|
||||||
|
64
cmd/stop.go
64
cmd/stop.go
@ -4,6 +4,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
//"log"
|
//"log"
|
||||||
|
"sync"
|
||||||
"errors"
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -169,8 +170,13 @@ func stopJail(jail *Jail) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop all running jails by reverse priority
|
// Stop all running jails by reverse priority
|
||||||
|
// Parallelize up to gMaxThreads
|
||||||
|
// Only parallelize same priority level jails
|
||||||
func StopAllRunningJails() {
|
func StopAllRunningJails() {
|
||||||
var stopList []Jail
|
var stopList []Jail
|
||||||
|
var wg *sync.WaitGroup
|
||||||
|
var curThNb int
|
||||||
|
var curPri int
|
||||||
|
|
||||||
// Get boot enabled jails
|
// Get boot enabled jails
|
||||||
for _, j := range gJails {
|
for _, j := range gJails {
|
||||||
@ -188,11 +194,52 @@ func StopAllRunningJails() {
|
|||||||
}
|
}
|
||||||
JailsOrderedBy(fct.Interface().(jailLessFunc)).Sort(stopList)
|
JailsOrderedBy(fct.Interface().(jailLessFunc)).Sort(stopList)
|
||||||
|
|
||||||
for _, j := range stopList {
|
|
||||||
|
wg = new(sync.WaitGroup)
|
||||||
|
curThNb = 0
|
||||||
|
for i, j := range stopList {
|
||||||
jFullName := fmt.Sprintf("%s/%s", j.Datastore, j.Name)
|
jFullName := fmt.Sprintf("%s/%s", j.Datastore, j.Name)
|
||||||
log.Debugf("Stopping %s with priority %s\n", jFullName, j.Config.Priority)
|
log.Debugf("Stopping %s with priority %s\n", jFullName, j.Config.Priority)
|
||||||
StopJail([]string{jFullName})
|
jailPri, err := strconv.Atoi(j.Config.Priority)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Invalid format for Priority (Jail %s)\n", jFullName))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curThNb >= gMaxThreads || i == 0) {
|
||||||
|
// FIXME : Use a pool instead of waiting for all threads to run a new one
|
||||||
|
wg.Wait()
|
||||||
|
curThNb = 0
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
curPri = jailPri
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StopJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
} else {
|
||||||
|
if (curPri == jailPri) {
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StopJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
} else {
|
||||||
|
wg.Wait()
|
||||||
|
curThNb = 0
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
curThNb++
|
||||||
|
curPri = jailPri
|
||||||
|
go func(jailFullName string) {
|
||||||
|
defer wg.Done()
|
||||||
|
StopJail([]string{jailFullName})
|
||||||
|
}(jFullName)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -243,8 +290,16 @@ func StopJail(args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
cvers = strings.TrimRight(cvers, "\n")
|
cvers = strings.TrimRight(cvers, "\n")
|
||||||
fmt.Sprintf(cj.Config.Release, cvers)
|
|
||||||
cj.ConfigUpdated = true
|
//fmt.Sprintf(cj.Config.Release, cvers)
|
||||||
|
//cj.Config.Release = cvers
|
||||||
|
//cj.ConfigUpdated = true
|
||||||
|
|
||||||
|
// This is working in this context, but value is not available in WriteConfigToDisk context :/
|
||||||
|
setStructFieldValue(cj, "Config.Release", cvers)
|
||||||
|
fmt.Printf("DEBUG: release was set, now is : %s\n", cj.Config.Release)
|
||||||
|
|
||||||
|
// We need to get the real Config object, not a copy of it
|
||||||
|
|
||||||
out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName))
|
out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName))
|
||||||
if err == nil && len(out) > 0 {
|
if err == nil && len(out) > 0 {
|
||||||
@ -410,6 +465,7 @@ func StopJail(args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("DEBUG: release = %s\n", cj.Config.Release)
|
||||||
WriteConfigToDisk(cj.Name, false, true)
|
WriteConfigToDisk(cj.Name, false, true)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
70
cmd/utils.go
70
cmd/utils.go
@ -21,6 +21,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
ipv4re = `[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}`
|
ipv4re = `[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}`
|
||||||
ifconfigipv4re = `inet[[:space:]](` + ipv4re + `)`
|
ifconfigipv4re = `inet[[:space:]](` + ipv4re + `)`
|
||||||
|
// Maximum thread qty for start/stop
|
||||||
|
gMaxThreads = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -225,6 +227,72 @@ func executeCommand(cmdline string) (string, error) {
|
|||||||
return string(out), err
|
return string(out), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* From iocage:
|
||||||
|
* # Courtesy of @william-gr
|
||||||
|
* # service(8) and some rc.d scripts have the bad h*abit of
|
||||||
|
* # exec'ing and never closing stdout/stderr. This makes
|
||||||
|
* # sure we read only enough until the command exits and do
|
||||||
|
* # not wait on the pipe to close on the other end.
|
||||||
|
* So this function executes process without waiting after completion
|
||||||
|
*/
|
||||||
|
func executeCommandNonBlocking(cmdline string) (error) {
|
||||||
|
var cmd []string
|
||||||
|
var oCmd *exec.Cmd
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if gUseSudo {
|
||||||
|
cmd = append(cmd, "sudo")
|
||||||
|
}
|
||||||
|
|
||||||
|
var word string
|
||||||
|
var in_escaped bool
|
||||||
|
// Split by words, or " enclosed words
|
||||||
|
for i, c := range (cmdline) {
|
||||||
|
if string(c) == "\"" {
|
||||||
|
if in_escaped {
|
||||||
|
// This is the closing "
|
||||||
|
cmd = append(cmd, word)
|
||||||
|
in_escaped = false
|
||||||
|
} else {
|
||||||
|
in_escaped = true
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if string(c) == " " {
|
||||||
|
if in_escaped {
|
||||||
|
word = word + string(c)
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
cmd = append(cmd, word)
|
||||||
|
word = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if i == (len(cmdline) - 1) {
|
||||||
|
word = word + string(c)
|
||||||
|
cmd = append(cmd, word)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// else
|
||||||
|
word = word + string(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cmd) > 1 {
|
||||||
|
oCmd = exec.Command(cmd[0], cmd[1:]...)
|
||||||
|
} else {
|
||||||
|
oCmd = exec.Command(cmd[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = oCmd.Start(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = oCmd.Wait()
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Executed command outputs to stdout in realtime
|
// Executed command outputs to stdout in realtime
|
||||||
func executeCommandWithOutputToStdout(cmdline string) (error) {
|
func executeCommandWithOutputToStdout(cmdline string) (error) {
|
||||||
var cmd []string
|
var cmd []string
|
||||||
@ -616,7 +684,7 @@ func copyDevfsRuleset(ruleset int, srcrs int) error {
|
|||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Returns value of parameter as read in /var/run/jail.$InternalName.conf
|
* Returns value of parameter as read in /var/run/jail.$InternalName.conf
|
||||||
* Directoves without value will return "true" if found
|
* Directives without value will return "true" if found
|
||||||
* Returns an error if parameter not found in file
|
* Returns an error if parameter not found in file
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
func getValueFromRunningConfig(jname string, param string) (string, error) {
|
func getValueFromRunningConfig(jname string, param string) (string, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user