Fixed wwclient but and more code cleanups
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os/exec"
|
||||
"path"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func overlaySystem(node assets.NodeInfo, replace map[string]string, wg *sync.WaitGroup) {
|
||||
@@ -15,7 +16,7 @@ func overlaySystem(node assets.NodeInfo, replace map[string]string, wg *sync.Wai
|
||||
|
||||
OverlayDir := fmt.Sprintf("%s/overlays/system/%s", LocalStateDir, node.SystemOverlay)
|
||||
OverlayFile := fmt.Sprintf("%s/provision/overlays/system/%s.img", LocalStateDir, node.Fqdn)
|
||||
/*
|
||||
|
||||
destModTime := time.Time{}
|
||||
destMod, err := os.Stat(OverlayFile)
|
||||
if err == nil {
|
||||
@@ -28,8 +29,8 @@ func overlaySystem(node assets.NodeInfo, replace map[string]string, wg *sync.Wai
|
||||
}
|
||||
configModTime := configMod.ModTime()
|
||||
sourceModTime, _ := util.DirModTime(OverlayDir)
|
||||
*/
|
||||
err := os.MkdirAll(path.Dir(OverlayFile), 0755)
|
||||
|
||||
err = os.MkdirAll(path.Dir(OverlayFile), 0755)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
return
|
||||
@@ -40,7 +41,7 @@ func overlaySystem(node assets.NodeInfo, replace map[string]string, wg *sync.Wai
|
||||
return
|
||||
}
|
||||
|
||||
// if sourceModTime.After(destModTime) || configModTime.After(destModTime) {
|
||||
if sourceModTime.After(destModTime) || configModTime.After(destModTime) {
|
||||
fmt.Printf("SYSTEM: %s\n", node.Fqdn)
|
||||
|
||||
overlayDest := "/tmp/.overlay-" + util.RandomString(16)
|
||||
@@ -53,8 +54,5 @@ func overlaySystem(node assets.NodeInfo, replace map[string]string, wg *sync.Wai
|
||||
}
|
||||
|
||||
os.RemoveAll(overlayDest)
|
||||
|
||||
// } else {
|
||||
// fmt.Printf("SYSTEM: %s (skipped no changes)\n", node.Fqdn)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ func BuildOverlayDir(sourceDir string, destDir string, replace map[string]string
|
||||
replaceString := fmt.Sprintf("@%s@", strings.ToUpper(k))
|
||||
newLine = strings.ReplaceAll(newLine, replaceString, v)
|
||||
}
|
||||
//TODO: Support directives like '#include <filename>' and
|
||||
// conditionals like '#IFDEF ....`
|
||||
|
||||
_, err := w.WriteString(newLine + "\n")
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -118,16 +118,16 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("SETUP KERNEL: %s (%s)\n", kernelSource, kernelDestination)
|
||||
fmt.Printf("SETUP KERNEL: %s\n", kernelSource)
|
||||
err = exec.Command("cp", kernelSource, kernelDestination).Run()
|
||||
if err != nil {
|
||||
fmt.Printf("%s", err)
|
||||
}
|
||||
|
||||
kernelMods := fmt.Sprintf("./lib/modules/%s", kernelVers)
|
||||
kernelMods := fmt.Sprintf("/lib/modules/%s", kernelVers)
|
||||
if _, err := os.Stat(kernelMods); err == nil {
|
||||
fmt.Printf("BUILDING MODS: %s\n", kernelMods)
|
||||
cmd := fmt.Sprintf("cd /; find %s | cpio --quiet -o -H newc -F \"%s\"", kernelMods, kmodsDestination)
|
||||
cmd := fmt.Sprintf("cd /; find .%s | cpio --quiet -o -H newc -F \"%s\"", kernelMods, kmodsDestination)
|
||||
err := exec.Command("/bin/sh", "-c", cmd).Run()
|
||||
if err != nil {
|
||||
fmt.Printf("OUTPUT: %s", err)
|
||||
@@ -174,8 +174,8 @@ func main() {
|
||||
}
|
||||
|
||||
wg.Add(2)
|
||||
overlayRuntime(node, replace, &wg)
|
||||
overlaySystem(node, replace, &wg)
|
||||
go overlayRuntime(node, replace, &wg)
|
||||
go overlaySystem(node, replace, &wg)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
// "os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -67,7 +68,10 @@ func main() {
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
// defer resp.Body.Close()
|
||||
|
||||
|
||||
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
log.Printf("Not updating runtime overlay, got status code: %d\n", resp.StatusCode)
|
||||
@@ -75,25 +79,51 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
command := exec.Command("cpio", "-i")
|
||||
command.Wait()
|
||||
stdin, err := command.StdinPipe()
|
||||
/*
|
||||
// TODO: Turn all of this into a pipe instead of having to use a tmpfile which
|
||||
// I tried to get working, but when running on a node, it always gave a
|
||||
// trying to write on closed file descriptor... This maybe ugly, but it
|
||||
// works.
|
||||
tmpfile := fmt.Sprintf("/tmp/.wwclient-%s", util.RandomString(14))
|
||||
tmpFD, _ := os.Create(tmpfile)
|
||||
defer tmpFD.Close()
|
||||
io.Copy(tmpFD, resp.Body)
|
||||
tmpFD.Close()
|
||||
|
||||
err := exec.Command("cpio", "-i", "-F", tmpfile).Run()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
fmt.Printf("%s", err)
|
||||
}
|
||||
defer stdin.Close()
|
||||
|
||||
go func() {
|
||||
bytes, err := io.Copy(stdin, resp.Body)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: io.Copy() failed: %s\n", err)
|
||||
} else {
|
||||
log.Printf("Updated the runtime overlay (recv: %d)\n", bytes)
|
||||
}
|
||||
os.Remove(tmpfile)
|
||||
|
||||
}()
|
||||
command.Run()
|
||||
*/
|
||||
log.Printf("Updating runtime system\n")
|
||||
command := exec.Command("/bin/cpio", "-i")
|
||||
command.Stdin = resp.Body
|
||||
err := command.Run()
|
||||
if err != nil {
|
||||
log.Printf("ERROR: Failed running CPIO: %s\n", err)
|
||||
}
|
||||
/*
|
||||
command.Wait()
|
||||
stdin, err := command.StdinPipe()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
defer stdin.Close()
|
||||
|
||||
go func() {
|
||||
bytes, err := io.Copy(stdin, resp.Body)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: io.Copy() failed: %s\n", err)
|
||||
} else {
|
||||
log.Printf("Updated the runtime overlay (recv: %d)\n", bytes)
|
||||
}
|
||||
|
||||
}()
|
||||
command.Run()
|
||||
*/
|
||||
// defer webclient.CloseIdleConnections()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user