Simplify wwctl server

- Always run in the foreground
- Always log to stdout/err (unless syslog is requested)
- Update systemd to reload with a direct signal
- Omit any pidfile for "warewulfd"

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-05-24 16:40:47 -06:00
parent 0be0f20823
commit 983214f253
21 changed files with 30 additions and 261 deletions

View File

@@ -44,12 +44,15 @@ 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
### 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

View File

@@ -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

View File

@@ -5,15 +5,11 @@ After=network-online.target
AssertFileIsExecutable=@BINDIR@/wwctl
[Service]
Type=simple
Type=exec
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]

View File

@@ -1,11 +0,0 @@
package reload
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
return errors.Wrap(warewulfd.DaemonReload(), "failed to reload Warewulf server")
}

View File

@@ -1,20 +0,0 @@
package reload
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Use: "reload [OPTIONS]",
Short: "Reload the Warewulf server configuration",
RunE: CobraRunE,
}
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,15 +0,0 @@
package restart
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
err := warewulfd.DaemonStop()
if err != nil {
return errors.Wrap(err, "failed to stop Warewulf server")
}
return errors.Wrap(warewulfd.DaemonStart(), "failed to start Warewulf server")
}

View File

@@ -1,20 +0,0 @@
package restart
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Use: "restart [OPTIONS]",
Short: "Restart the Warewulf server",
RunE: CobraRunE,
}
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -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")
}

View File

@@ -1,19 +0,0 @@
package start
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
if SetForeground {
conf := warewulfconf.Get()
conf.Warewulf.Syslog = false
return errors.Wrap(warewulfd.RunServer(), "failed to start Warewulf server")
} else {
return errors.Wrap(warewulfd.DaemonStart(), "failed to start Warewulf server")
}
}

View File

@@ -1,22 +0,0 @@
package start
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Use: "start [OPTIONS]",
Short: "Start Warewulf server",
RunE: CobraRunE,
}
SetForeground bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SetForeground, "foreground", "f", false, "Run daemon process in the foreground")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,10 +0,0 @@
package status
import (
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
return warewulfd.DaemonStatus()
}

View File

@@ -1,17 +0,0 @@
package status
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Use: "status [OPTIONS]",
Short: "Warewulf server status",
RunE: CobraRunE,
}
)
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,11 +0,0 @@
package stop
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
return errors.Wrap(warewulfd.DaemonStop(), "failed to stop Warewulf server")
}

View File

@@ -1,17 +0,0 @@
package stop
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Use: "stop [OPTIONS]",
Short: "Stop Warewulf server",
RunE: CobraRunE,
}
)
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -60,7 +60,7 @@ func DaemonInitLogging() error {
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 {
@@ -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
}

View File

@@ -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)
@@ -57,7 +52,7 @@ func RunServer() error {
}
}()
err = LoadNodeDB()
err := LoadNodeDB()
if err != nil {
wwlog.Error("Could not load database: %s", err)
}
@@ -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 {

View File

@@ -114,8 +114,7 @@ explained as follows:
services.)
* ``warewulf:syslog``: This determines whether Warewulf server logs go
to syslog or are written directly to a log file. (e.g.,
``/var/log/warewulfd.log``)
to syslog.
* ``nfs:export paths``: Warewulf can automatically set up these NFS
exports.

View File

@@ -48,22 +48,3 @@ systemd service:
.. code-block:: console
# systemctl enable --now warewulfd
You can also check and control the Warewulf service using the ``wwctl``
command line program as follows:
.. code-block:: console
# wwctl server status
.. note::
If the Warewulf service is running via systemd, restarting
stopping, and starting it from the ``wwctl`` command may result in
unexpected results.
Logs
----
The Warewulf server logs are by default written to
``/var/log/warewulfd.log``.

View File

@@ -121,8 +121,6 @@ Build and install Warewulf on wwdev
sudo wwctl overlay build -a
# Start the Warewulf daemon
sudo wwctl ready
sudo wwctl server start
sudo wwctl server status
sudo wwctl server &
Boot your node and watch the bash and the output of the Warewulfd process

View File

@@ -223,7 +223,7 @@ Vagrantfile
systemd name: nfs-server
CONF
sed -i 's@ExecStart=/usr/bin/wwctl server start@ExecStart=/usr/bin/wwctl server start -d -v@' /usr/lib/systemd/system/warewulfd.service
sed -i 's@ExecStart=/usr/bin/wwctl server@ExecStart=/usr/bin/wwctl server -d -v@' /usr/lib/systemd/system/warewulfd.service
systemctl enable --now warewulfd
wwctl configure --all

View File

@@ -137,9 +137,7 @@ I have VirtualBox running on my desktop.
sudo wwctl overlay build -a
# Start the Warewulf daemon
sudo wwctl ready
sudo wwctl server start
sudo wwctl server status
sudo wwctl server &
4. Create a new guest VM instance inside the VirtualBox to be the
Warewulf client/compute node. Under the system configuration make