Files
warewulf/internal/pkg/warewulfd/warewulfd.go
Carter Dodd 379faad51d Refactor of server, logging, building of images, template updates
* Combine provision response handling, add hwaddr and interface to dhcp
* Simplify stage cases, add backward compatible uri parse
* Move control of image compression to client
* Fix kernel search path for ubuntu, buffer template generation
* Implement cpio and gz as functions, add log named functions
* Generalize fs image creation routine
* Combine daemonLogf to generalized wwlog
* Fix template newline insertion, update dhcp and hosts tmpl
* Update IPXE template to handle non-compressed files
* Update DHCP template to set network interfaces and server IP assignment
* Update DHCP/hosts templates to choose a host-name self-consistently
2022-05-13 16:52:59 -05:00

73 lines
1.6 KiB
Go

package warewulfd
import (
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
)
// TODO: https://github.com/danderson/netboot/blob/master/pixiecore/dhcp.go
// TODO: https://github.com/pin/tftp
func RunServer() error {
DaemonInitLogging()
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
go func() {
for range c {
wwlog.Warn("Recieved SIGHUP, reloading...")
err := LoadNodeDB()
if err != nil {
wwlog.Error("Could not load node DB: %s", err)
}
err = LoadNodeStatus()
if err != nil {
wwlog.Error("Could not prepopulate node status DB: %s", err)
}
}
}()
err := LoadNodeDB()
if err != nil {
wwlog.Error("Could not load database: %s", err)
}
err = LoadNodeStatus()
if err != nil {
wwlog.Error("Could not prepopulate node status DB: %s", err)
}
http.HandleFunc("/provision/", ProvisionSend)
http.HandleFunc("/ipxe/", ProvisionSend)
http.HandleFunc("/kernel/", ProvisionSend)
http.HandleFunc("/kmods/", ProvisionSend)
http.HandleFunc("/container/", ProvisionSend)
http.HandleFunc("/overlay-system/", ProvisionSend)
http.HandleFunc("/overlay-runtime/", ProvisionSend)
http.HandleFunc("/status", StatusSend)
conf, err := warewulfconf.New()
if err != nil {
return errors.Wrap(err, "could not get Warewulf configuration")
}
daemonPort := conf.Warewulf.Port
wwlog.Info("Starting HTTPD REST service on port %d", daemonPort)
err = http.ListenAndServe(":"+strconv.Itoa(daemonPort), nil)
if err != nil {
return errors.Wrap(err, "Could not start listening service")
}
return nil
}