-
Notifications
You must be signed in to change notification settings - Fork 75
/
warewulfd.go
105 lines (90 loc) · 2.58 KB
/
warewulfd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package warewulfd
import (
"net/http"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"github.com/pkg/errors"
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
// TODO: https://github.com/danderson/netboot/blob/master/pixiecore/dhcp.go
// TODO: https://github.com/pin/tftp
/*
wrapper type for the server mux as shim requests http://efiboot//grub.efi
which is filtered out by http to `301 Moved Permanently` what
shim.efi can't handle. So filter out `//` before they hit go/http.
Makes go/http more to behave like apache
*/
type slashFix struct {
mux http.Handler
}
/*
Filter out the '//'
*/
func (h *slashFix) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.URL.Path = strings.Replace(r.URL.Path, "//", "/", -1)
h.mux.ServeHTTP(w, r)
}
func RunServer() error {
err := DaemonInitLogging()
if err != nil {
return errors.Wrap(err, "Failed to initialize logging")
}
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
go func() {
for range c {
wwlog.Warn("Received 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)
}
if err != nil {
wwlog.Warn("couldn't copy default shim: %s", err)
}
var wwHandler http.ServeMux
wwHandler.HandleFunc("/provision/", ProvisionSend)
wwHandler.HandleFunc("/ipxe/", ProvisionSend)
wwHandler.HandleFunc("/efiboot/", ProvisionSend)
wwHandler.HandleFunc("/kernel/", ProvisionSend)
wwHandler.HandleFunc("/kmods/", ProvisionSend)
wwHandler.HandleFunc("/container/", ProvisionSend)
wwHandler.HandleFunc("/overlay-system/", ProvisionSend)
wwHandler.HandleFunc("/overlay-runtime/", ProvisionSend)
wwHandler.HandleFunc("/status", StatusSend)
conf := warewulfconf.Get()
daemonPort := conf.Warewulf.Port
/*
wwlog.Serv("Starting HTTPD REST service on port %d", daemonPort)
s := &http.Server{
Addr: ":" + strconv.Itoa(daemonPort),
Handler: &slashFix{&wwHandler},
ReadTimeout: 10 * time.Second,
IdleTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
err = s.ListenAndServe()
*/
err = http.ListenAndServe(":"+strconv.Itoa(daemonPort), &slashFix{&wwHandler})
if err != nil {
return errors.Wrap(err, "Could not start listening service")
}
return nil
}