mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-30 00:45:20 +08:00
Merge pull request #1539 from gravitl/bugfix_v0.15.2_RunCmds
use RunCmd for postup/postdown
This commit is contained in:
commit
5475aa90ee
7 changed files with 32 additions and 26 deletions
|
@ -659,8 +659,7 @@ func deleteInterface(ifacename string, postdown string) error {
|
|||
}
|
||||
_, err = ncutils.RunCmd(ipExec+" link del "+ifacename, false)
|
||||
if postdown != "" {
|
||||
runcmds := strings.Split(postdown, "; ")
|
||||
err = ncutils.RunCmds(runcmds, false)
|
||||
_, err = ncutils.RunCmd(postdown, false)
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -191,8 +191,7 @@ func removeLocalServer(node *models.Node) error {
|
|||
logger.Log(1, out)
|
||||
}
|
||||
if node.PostDown != "" {
|
||||
runcmds := strings.Split(node.PostDown, "; ")
|
||||
_ = ncutils.RunCmds(runcmds, false)
|
||||
ncutils.RunCmd(node.PostDown, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,8 +87,6 @@ func Daemon() error {
|
|||
|
||||
func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
wg.Add(1)
|
||||
go Checkin(ctx, wg)
|
||||
serverSet := make(map[string]bool)
|
||||
networks, _ := ncutils.GetSystemNetworks()
|
||||
for _, network := range networks {
|
||||
|
@ -116,6 +114,8 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
|
|||
go messageQueue(ctx, wg, &cfg)
|
||||
}
|
||||
}
|
||||
wg.Add(1)
|
||||
go Checkin(ctx, wg)
|
||||
return cancel
|
||||
}
|
||||
|
||||
|
|
|
@ -437,6 +437,10 @@ func Copy(src, dst string) error {
|
|||
func RunCmds(commands []string, printerr bool) error {
|
||||
var err error
|
||||
for _, command := range commands {
|
||||
//prevent panic
|
||||
if len(strings.Trim(command, " ")) == 0 {
|
||||
continue
|
||||
}
|
||||
args := strings.Fields(command)
|
||||
out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
|
||||
if err != nil && printerr {
|
||||
|
|
|
@ -335,22 +335,31 @@ func WriteWgConfig(node *models.Node, privateKey string, peers []wgtypes.PeerCon
|
|||
// wireguard.Section(section_interface).Key("DNS").SetValue(cfg.Server.CoreDNSAddr)
|
||||
//}
|
||||
//need to split postup/postdown because ini lib adds a ` and the ` breaks freebsd
|
||||
//works fine on others
|
||||
if node.PostUp != "" {
|
||||
parts := strings.Split(node.PostUp, " ; ")
|
||||
for i, part := range parts {
|
||||
if i == 0 {
|
||||
wireguard.Section(section_interface).Key("PostUp").SetValue(part)
|
||||
if node.OS == "freebsd" {
|
||||
parts := strings.Split(node.PostUp, " ; ")
|
||||
for i, part := range parts {
|
||||
if i == 0 {
|
||||
wireguard.Section(section_interface).Key("PostUp").SetValue(part)
|
||||
}
|
||||
wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
|
||||
}
|
||||
wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
|
||||
} else {
|
||||
wireguard.Section(section_interface).Key("PostUp").SetValue((node.PostUp))
|
||||
}
|
||||
}
|
||||
if node.PostDown != "" {
|
||||
parts := strings.Split(node.PostDown, " ; ")
|
||||
for i, part := range parts {
|
||||
if i == 0 {
|
||||
wireguard.Section(section_interface).Key("PostDown").SetValue(part)
|
||||
if node.OS == "freebsd" {
|
||||
parts := strings.Split(node.PostDown, " ; ")
|
||||
for i, part := range parts {
|
||||
if i == 0 {
|
||||
wireguard.Section(section_interface).Key("PostDown").SetValue(part)
|
||||
}
|
||||
wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
|
||||
}
|
||||
wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
|
||||
} else {
|
||||
wireguard.Section(section_interface).Key("PostUp").SetValue((node.PostUp))
|
||||
}
|
||||
}
|
||||
if node.MTU != 0 {
|
||||
|
|
|
@ -19,8 +19,7 @@ func WgQuickDownMac(node *models.Node, iface string) error {
|
|||
return err
|
||||
}
|
||||
if node.PostDown != "" {
|
||||
runcmds := strings.Split(node.PostDown, "; ")
|
||||
ncutils.RunCmds(runcmds, true)
|
||||
ncutils.RunCmd(node.PostDown, true)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -85,8 +84,7 @@ func WgQuickUpMac(node *models.Node, iface string, confPath string) error {
|
|||
//next, wg-quick runs monitor_daemon
|
||||
time.Sleep(time.Second / 2)
|
||||
if node.PostUp != "" {
|
||||
runcmds := strings.Split(node.PostUp, "; ")
|
||||
ncutils.RunCmds(runcmds, true)
|
||||
ncutils.RunCmd(node.PostUp, true)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -99,8 +99,7 @@ func ApplyWithoutWGQuick(node *models.Node, ifacename, confPath string, isConnec
|
|||
return err
|
||||
}
|
||||
if node.PostDown != "" {
|
||||
runcmds := strings.Split(node.PostDown, "; ")
|
||||
_ = ncutils.RunCmds(runcmds, false)
|
||||
ncutils.RunCmd(node.PostDown, false)
|
||||
}
|
||||
// set MTU of node interface
|
||||
if _, err := ncutils.RunCmd(ipExec+" link set mtu "+strconv.Itoa(int(node.MTU))+" up dev "+ifacename, true); err != nil {
|
||||
|
@ -108,8 +107,7 @@ func ApplyWithoutWGQuick(node *models.Node, ifacename, confPath string, isConnec
|
|||
return err
|
||||
}
|
||||
if node.PostUp != "" {
|
||||
runcmds := strings.Split(node.PostUp, "; ")
|
||||
_ = ncutils.RunCmds(runcmds, true)
|
||||
ncutils.RunCmd(node.PostUp, false)
|
||||
}
|
||||
if node.Address6 != "" {
|
||||
logger.Log(1, "adding address: ", node.Address6)
|
||||
|
@ -139,8 +137,7 @@ func RemoveWithoutWGQuick(ifacename string) error {
|
|||
nodeconf, err := config.ReadConfig(network)
|
||||
if nodeconf != nil && err == nil {
|
||||
if nodeconf.Node.PostDown != "" {
|
||||
runcmds := strings.Split(nodeconf.Node.PostDown, "; ")
|
||||
_ = ncutils.RunCmds(runcmds, false)
|
||||
ncutils.RunCmd(nodeconf.Node.PostDown, false)
|
||||
}
|
||||
} else if err != nil {
|
||||
logger.Log(1, "error retrieving config: ", err.Error())
|
||||
|
|
Loading…
Add table
Reference in a new issue