diff --git a/Makefile b/Makefile index d4e74189..b71f2782 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ lint: @echo Running golangci-lint... @$(GOLANGCI_LINT) run --build-tags "$(WW_BUILD_GO_BUILD_TAGS)" ./... -all: vendor warewulfd wwctl wwclient +all: vendor wwctl wwclient files: all install -d -m 0755 /var/warewulf/ @@ -60,9 +60,6 @@ services: files # sudo systemctl enable tftp # sudo systemctl restart tftp -warewulfd: - cd cmd/warewulfd; go build -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../warewulfd - wwctl: cd cmd/wwctl; go build -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwctl @@ -70,7 +67,6 @@ wwclient: cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags '-extldflags -static' -o ../../wwclient clean: - rm -f warewulfd rm -f wwclient rm -f wwctl diff --git a/cmd/warewulfd/main.go b/cmd/warewulfd/main.go deleted file mode 100644 index 019de38f..00000000 --- a/cmd/warewulfd/main.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "github.com/hpcng/warewulf/internal/app/warewulfd" -) - - -func main() { - root := warewulfd.GetRootCommand() - - root.Execute() -} \ No newline at end of file diff --git a/internal/app/warewulfd/root.go b/internal/app/warewulfd/root.go deleted file mode 100644 index 7d0032c3..00000000 --- a/internal/app/warewulfd/root.go +++ /dev/null @@ -1,39 +0,0 @@ -package warewulfd - -import ( - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "github.com/spf13/cobra" -) - -var ( - baseCmd = &cobra.Command{ - Use: "warewulfd", - Short: "Warewulf Daemon Service", - Long: "This is the primary Warewulf system for provisioning nodes", - RunE: CobraRunE, - PersistentPreRunE: rootPersistentPreRunE, - } - verboseArg bool - debugArg bool -) - -func init() { - baseCmd.PersistentFlags().BoolVarP(&verboseArg, "verbose", "v", false, "Run with increased verbosity.") - baseCmd.PersistentFlags().BoolVarP(&debugArg, "debug", "d", false, "Run with debugging messages enabled.") -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetRootCommand() *cobra.Command { - return baseCmd -} - -func rootPersistentPreRunE(cmd *cobra.Command, args []string) error { - if verboseArg == true { - wwlog.SetLevel(wwlog.VERBOSE) - } else if debugArg == true { - wwlog.SetLevel(wwlog.DEBUG) - } else { - wwlog.SetLevel(wwlog.INFO) - } - return nil -} diff --git a/internal/app/warewulfd/warewulfd.go b/internal/app/warewulfd/warewulfd.go deleted file mode 100644 index a6805d2a..00000000 --- a/internal/app/warewulfd/warewulfd.go +++ /dev/null @@ -1,24 +0,0 @@ -package warewulfd - -import ( - "github.com/hpcng/warewulf/internal/app/warewulfd/response" - "github.com/spf13/cobra" - "net/http" -) - -// TODO: https://github.com/danderson/netboot/blob/master/pixiecore/dhcp.go -// TODO: https://github.com/pin/tftp - -func CobraRunE(cmd *cobra.Command, args []string) error { - - http.HandleFunc("/ipxe/", response.IpxeSend) - http.HandleFunc("/kernel/", response.KernelSend) - http.HandleFunc("/kmods/", response.KmodsSend) - http.HandleFunc("/container/", response.ContainerSend) - http.HandleFunc("/overlay-system/", response.SystemOverlaySend) - http.HandleFunc("/overlay-runtime", response.RuntimeOverlaySend) - - http.ListenAndServe(":9873", nil) - - return nil -} diff --git a/internal/app/wwctl/server/root.go b/internal/app/wwctl/server/root.go index 26870499..b368ac4d 100644 --- a/internal/app/wwctl/server/root.go +++ b/internal/app/wwctl/server/root.go @@ -1,6 +1,11 @@ package server -import "github.com/spf13/cobra" +import ( + "github.com/hpcng/warewulf/internal/app/wwctl/server/start" + "github.com/hpcng/warewulf/internal/app/wwctl/server/status" + "github.com/hpcng/warewulf/internal/app/wwctl/server/stop" + "github.com/spf13/cobra" +) var ( baseCmd = &cobra.Command{ @@ -12,6 +17,10 @@ var ( ) func init() { + baseCmd.AddCommand(start.GetCommand()) + baseCmd.AddCommand(status.GetCommand()) + baseCmd.AddCommand(stop.GetCommand()) + } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/server/start/main.go b/internal/app/wwctl/server/start/main.go index 3f368ae7..82a18c20 100644 --- a/internal/app/wwctl/server/start/main.go +++ b/internal/app/wwctl/server/start/main.go @@ -1,8 +1,11 @@ package start -import "github.com/spf13/cobra" +import ( + "github.com/hpcng/warewulf/internal/pkg/warewulfd" + "github.com/spf13/cobra" +) func CobraRunE(cmd *cobra.Command, args []string) error { - return nil + return warewulfd.RunServer() } diff --git a/internal/app/wwctl/server/status/main.go b/internal/app/wwctl/server/status/main.go index 5c1b993d..6edbe268 100644 --- a/internal/app/wwctl/server/status/main.go +++ b/internal/app/wwctl/server/status/main.go @@ -1,8 +1,12 @@ package status -import "github.com/spf13/cobra" +import ( + "fmt" + "github.com/spf13/cobra" +) func CobraRunE(cmd *cobra.Command, args []string) error { + fmt.Printf("Not implemented yet\n") return nil } diff --git a/internal/app/wwctl/server/stop/main.go b/internal/app/wwctl/server/stop/main.go index daa8898b..19ca0495 100644 --- a/internal/app/wwctl/server/stop/main.go +++ b/internal/app/wwctl/server/stop/main.go @@ -1,8 +1,11 @@ package stop -import "github.com/spf13/cobra" +import ( + "fmt" + "github.com/spf13/cobra" +) func CobraRunE(cmd *cobra.Command, args []string) error { - + fmt.Printf("Not implemented yet\n") return nil } diff --git a/internal/app/warewulfd/response/container.go b/internal/pkg/warewulfd/container.go similarity index 97% rename from internal/app/warewulfd/response/container.go rename to internal/pkg/warewulfd/container.go index da58d804..1aa0b69d 100644 --- a/internal/app/warewulfd/response/container.go +++ b/internal/pkg/warewulfd/container.go @@ -1,4 +1,4 @@ -package response +package warewulfd import ( "github.com/hpcng/warewulf/internal/pkg/container" diff --git a/internal/app/warewulfd/response/ipxe.go b/internal/pkg/warewulfd/ipxe.go similarity index 99% rename from internal/app/warewulfd/response/ipxe.go rename to internal/pkg/warewulfd/ipxe.go index 0b838ecd..6022ca59 100644 --- a/internal/app/warewulfd/response/ipxe.go +++ b/internal/pkg/warewulfd/ipxe.go @@ -1,4 +1,4 @@ -package response +package warewulfd import ( "fmt" diff --git a/internal/app/warewulfd/response/kernel.go b/internal/pkg/warewulfd/kernel.go similarity index 97% rename from internal/app/warewulfd/response/kernel.go rename to internal/pkg/warewulfd/kernel.go index e530de98..4d8d7a5c 100644 --- a/internal/app/warewulfd/response/kernel.go +++ b/internal/pkg/warewulfd/kernel.go @@ -1,4 +1,4 @@ -package response +package warewulfd import ( "github.com/hpcng/warewulf/internal/pkg/kernel" diff --git a/internal/app/warewulfd/response/kmods.go b/internal/pkg/warewulfd/kmods.go similarity index 97% rename from internal/app/warewulfd/response/kmods.go rename to internal/pkg/warewulfd/kmods.go index 4622b3b2..7558de83 100644 --- a/internal/app/warewulfd/response/kmods.go +++ b/internal/pkg/warewulfd/kmods.go @@ -1,4 +1,4 @@ -package response +package warewulfd import ( "github.com/hpcng/warewulf/internal/pkg/kernel" diff --git a/internal/app/warewulfd/response/runtime.go b/internal/pkg/warewulfd/runtime.go similarity index 99% rename from internal/app/warewulfd/response/runtime.go rename to internal/pkg/warewulfd/runtime.go index ec6291b7..7f13668d 100644 --- a/internal/app/warewulfd/response/runtime.go +++ b/internal/pkg/warewulfd/runtime.go @@ -1,4 +1,4 @@ -package response +package warewulfd import ( "fmt" diff --git a/internal/app/warewulfd/response/system.go b/internal/pkg/warewulfd/system.go similarity index 97% rename from internal/app/warewulfd/response/system.go rename to internal/pkg/warewulfd/system.go index 3a3cf285..3a92a7a5 100644 --- a/internal/app/warewulfd/response/system.go +++ b/internal/pkg/warewulfd/system.go @@ -1,4 +1,4 @@ -package response +package warewulfd import ( "github.com/hpcng/warewulf/internal/pkg/config" diff --git a/internal/app/warewulfd/response/util.go b/internal/pkg/warewulfd/util.go similarity index 98% rename from internal/app/warewulfd/response/util.go rename to internal/pkg/warewulfd/util.go index 8ef67270..3e5403ab 100644 --- a/internal/app/warewulfd/response/util.go +++ b/internal/pkg/warewulfd/util.go @@ -1,4 +1,4 @@ -package response +package warewulfd import ( "fmt" diff --git a/internal/pkg/warewulfd/warewulfd.go b/internal/pkg/warewulfd/warewulfd.go new file mode 100644 index 00000000..ba90adcc --- /dev/null +++ b/internal/pkg/warewulfd/warewulfd.go @@ -0,0 +1,27 @@ +package warewulfd + +import ( + "github.com/hpcng/warewulf/internal/pkg/wwlog" + "net/http" +) + +// TODO: https://github.com/danderson/netboot/blob/master/pixiecore/dhcp.go +// TODO: https://github.com/pin/tftp + +func RunServer() error { + + wwlog.Printf(wwlog.DEBUG, "Registering handlers for the web service\n") + + http.HandleFunc("/ipxe/", IpxeSend) + http.HandleFunc("/kernel/", KernelSend) + http.HandleFunc("/kmods/", KmodsSend) + http.HandleFunc("/container/", ContainerSend) + http.HandleFunc("/overlay-system/", SystemOverlaySend) + http.HandleFunc("/overlay-runtime", RuntimeOverlaySend) + + wwlog.Printf(wwlog.VERBOSE, "Starting HTTPD REST service\n") + + http.ListenAndServe(":9873", nil) + + return nil +}