Skip to content

Commit

Permalink
Merge pull request warewulf#1229 from anderbubble/warewulfd-foreground
Browse files Browse the repository at this point in the history
Simplify `wwctl server` command and logging
  • Loading branch information
anderbubble authored Oct 31, 2024
2 parents 0be0f20 + d33ca6f commit e54ecfa
Show file tree
Hide file tree
Showing 25 changed files with 38 additions and 290 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add flag `--build` to `wwctl container copy`. #1378
- Add `wwctl clean` to remove OCI cache and overlays from deleted nodes
- Add `wwctl container import --platform`. #1381
- Read environment variables from `/etc/default/warewulfd` #725

### Changed

Expand All @@ -44,12 +45,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Switched from yaml.v2 to yaml.v3 #1462
- Make OCIBlobCache a seperate path and point it to `/var/cache` #1459
- Updated various shell scripts for POSIX compatibility. #1464
- Update `wwctl server` to always run in the foreground #508
- Update `wwctl server` to log to stdout rather than a file #503
- Changed `wwctl server` to use "INFO" for send and receive logs #725


### Removed

- `wwctl node list --fullall` has been removed
- `wwctl profile list --fullall` has been removed
- Remove `wwctl server <start,stop,status,restart,reload>` #508

### Fixed

Expand Down
6 changes: 1 addition & 5 deletions docs/man/man5/warewulf.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ Default: true
.TP
\fBsyslog\fP

When true, Warewulf server logs are written to syslog, rather than a
local file.

When false, Warewulf server logs are written to
`/var/log/warewulfd.log'.
When true, Warewulf server logs are written to syslog.

Default: false
.IP
Expand Down
11 changes: 4 additions & 7 deletions include/systemd/warewulfd.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ After=network-online.target
AssertFileIsExecutable=@BINDIR@/wwctl

[Service]
Type=simple
Type=exec
EnvironmentFile=-/etc/default/warewulfd
User=root
Group=root

ExecStart=@BINDIR@/wwctl server start
ExecReload=@BINDIR@/wwctl server reload
ExecStop=@BINDIR@/wwctl server stop

PIDFile=/var/run/warewulfd.pid
ExecStart=@BINDIR@/wwctl server
ExecReload=/bin/kill -HUP "$MAINPID"
Restart=always

[Install]
Expand Down
11 changes: 0 additions & 11 deletions internal/app/wwctl/server/reload/main.go

This file was deleted.

20 changes: 0 additions & 20 deletions internal/app/wwctl/server/reload/root.go

This file was deleted.

15 changes: 0 additions & 15 deletions internal/app/wwctl/server/restart/main.go

This file was deleted.

20 changes: 0 additions & 20 deletions internal/app/wwctl/server/restart/root.go

This file was deleted.

30 changes: 12 additions & 18 deletions internal/app/wwctl/server/root.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
package server

import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/app/wwctl/server/reload"
"github.com/warewulf/warewulf/internal/app/wwctl/server/restart"
"github.com/warewulf/warewulf/internal/app/wwctl/server/start"
"github.com/warewulf/warewulf/internal/app/wwctl/server/status"
"github.com/warewulf/warewulf/internal/app/wwctl/server/stop"
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
)

var (
baseCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Use: "server COMMAND [OPTIONS]",
Short: "Warewulf server process commands",
Long: "This command will allow you to control the Warewulf daemon process.",
Use: "server [OPTIONS]",
Short: "Start Warewulf server",
RunE: CobraRunE,
}
)

func init() {
baseCmd.AddCommand(start.GetCommand())
baseCmd.AddCommand(status.GetCommand())
baseCmd.AddCommand(stop.GetCommand())
baseCmd.AddCommand(restart.GetCommand())
baseCmd.AddCommand(reload.GetCommand())

}

// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

func CobraRunE(cmd *cobra.Command, args []string) error {
if err := warewulfd.DaemonInitLogging(); err != nil {
return errors.Wrap(err, "failed to configure logging")
}
return errors.Wrap(warewulfd.RunServer(), "failed to start Warewulf server")
}
19 changes: 0 additions & 19 deletions internal/app/wwctl/server/start/main.go

This file was deleted.

22 changes: 0 additions & 22 deletions internal/app/wwctl/server/start/root.go

This file was deleted.

10 changes: 0 additions & 10 deletions internal/app/wwctl/server/status/main.go

This file was deleted.

17 changes: 0 additions & 17 deletions internal/app/wwctl/server/status/root.go

This file was deleted.

11 changes: 0 additions & 11 deletions internal/app/wwctl/server/stop/main.go

This file was deleted.

17 changes: 0 additions & 17 deletions internal/app/wwctl/server/stop/root.go

This file was deleted.

32 changes: 7 additions & 25 deletions internal/pkg/warewulfd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func DaemonInitLogging() error {
wwlog.SetLogLevel(level)
}
} else {
wwlog.SetLogLevel(wwlog.SERV)
wwlog.SetLogLevel(wwlog.INFO)
}

conf := warewulfconf.Get()

if conf.Warewulf.Syslog {

wwlog.Debug("Changingq log output to syslog")
wwlog.Debug("Changing log output to syslog")

logwriter, err := syslog.New(syslog.LOG_NOTICE, "warewulfd")
if err != nil {
Expand Down Expand Up @@ -165,33 +165,15 @@ func DaemonReload() error {
if nodaemon {
return nil
}
if !util.IsFile(WAREWULFD_PIDFILE) {
return errors.New("Warewulf server is not running")
}

dat, err := os.ReadFile(WAREWULFD_PIDFILE)
cmd := exec.Command("/usr/sbin/service", "warewulfd", "reload")
err := cmd.Start()
if err != nil {
return errors.Wrap(err, "could not read Warewulfd PID file")
return errors.Wrap(err, "failed to reload warewulfd")
}

pid, _ := strconv.Atoi(string(dat))
process, err := os.FindProcess(pid)
err = cmd.Wait()
if err != nil {
return errors.Wrap(err, "failed to find running PID")
} else {
err := process.Signal(syscall.Signal(syscall.SIGHUP))
if err != nil {
return errors.Wrap(err, "failed to send process SIGHUP")
}
return errors.Wrap(err, "failed to reload warewulfd")
}

logLevel := wwlog.GetLogLevel()
if logLevel == wwlog.INFO {
os.Setenv("WAREWULFD_LOGLEVEL", strconv.Itoa(wwlog.SERV))
} else {
os.Setenv("WAREWULFD_LOGLEVEL", strconv.Itoa(logLevel))
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/warewulfd/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func ProvisionSend(w http.ResponseWriter, req *http.Request) {
return
}

wwlog.Recv("hwaddr: %s, ipaddr: %s, stage: %s", rinfo.hwaddr, req.RemoteAddr, rinfo.stage)
wwlog.Info("request from hwaddr:%s ipaddr:%s | stage:%s", rinfo.hwaddr, req.RemoteAddr, rinfo.stage)

if (rinfo.stage == "runtime" || len(rinfo.overlay) > 0) && conf.Warewulf.Secure {
if rinfo.remoteport >= 1024 {
Expand Down Expand Up @@ -276,7 +276,7 @@ func ProvisionSend(w http.ResponseWriter, req *http.Request) {
wwlog.ErrorExc(err, "")
}

wwlog.Send("%15s: %s", remoteNode.Id(), stage_file)
wwlog.Info("send %s -> %s", stage_file, remoteNode.Id())

} else {
if rinfo.compress == "gz" {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/warewulfd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func sendFile(
stat.ModTime(),
fd)

wwlog.Send("%15s: %s", sendto, filename)
wwlog.Info("send %s -> %s", filename, sendto)
req.Body.Close()
return nil
}
Expand Down
18 changes: 1 addition & 17 deletions internal/pkg/warewulfd/warewulfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ func (h *slashFix) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

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)

Expand All @@ -57,7 +52,7 @@ func RunServer() error {
}
}()

err = LoadNodeDB()
err := LoadNodeDB()
if err != nil {
wwlog.Error("Could not load database: %s", err)
}
Expand All @@ -84,17 +79,6 @@ func RunServer() error {
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 {
Expand Down
Loading

0 comments on commit e54ecfa

Please sign in to comment.