From 983214f253ddc27262ca30dc408485ba9389d95e Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Fri, 24 May 2024 16:40:47 -0600 Subject: [PATCH] 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 --- CHANGELOG.md | 3 ++ docs/man/man5/warewulf.conf.5 | 6 +--- include/systemd/warewulfd.service.in | 10 ++----- internal/app/wwctl/server/reload/main.go | 11 ------- internal/app/wwctl/server/reload/root.go | 20 ------------- internal/app/wwctl/server/restart/main.go | 15 ---------- internal/app/wwctl/server/restart/root.go | 20 ------------- internal/app/wwctl/server/root.go | 30 ++++++++----------- internal/app/wwctl/server/start/main.go | 19 ------------ internal/app/wwctl/server/start/root.go | 22 -------------- internal/app/wwctl/server/status/main.go | 10 ------- internal/app/wwctl/server/status/root.go | 17 ----------- internal/app/wwctl/server/stop/main.go | 11 ------- internal/app/wwctl/server/stop/root.go | 17 ----------- internal/pkg/warewulfd/daemon.go | 30 ++++--------------- internal/pkg/warewulfd/warewulfd.go | 18 +---------- userdocs/contents/configuration.rst | 3 +- userdocs/contents/initialization.rst | 19 ------------ .../development-environment-kvm.rst | 4 +-- .../development-environment-vagrant.rst | 2 +- .../development-environment-vbox.rst | 4 +-- 21 files changed, 30 insertions(+), 261 deletions(-) delete mode 100644 internal/app/wwctl/server/reload/main.go delete mode 100644 internal/app/wwctl/server/reload/root.go delete mode 100644 internal/app/wwctl/server/restart/main.go delete mode 100644 internal/app/wwctl/server/restart/root.go delete mode 100644 internal/app/wwctl/server/start/main.go delete mode 100644 internal/app/wwctl/server/start/root.go delete mode 100644 internal/app/wwctl/server/status/main.go delete mode 100644 internal/app/wwctl/server/status/root.go delete mode 100644 internal/app/wwctl/server/stop/main.go delete mode 100644 internal/app/wwctl/server/stop/root.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 28acade7..79f4eb1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ` #508 ### Fixed diff --git a/docs/man/man5/warewulf.conf.5 b/docs/man/man5/warewulf.conf.5 index 9c222858..3b21ec9e 100644 --- a/docs/man/man5/warewulf.conf.5 +++ b/docs/man/man5/warewulf.conf.5 @@ -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 diff --git a/include/systemd/warewulfd.service.in b/include/systemd/warewulfd.service.in index 7ba04a7a..6ba38606 100644 --- a/include/systemd/warewulfd.service.in +++ b/include/systemd/warewulfd.service.in @@ -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] diff --git a/internal/app/wwctl/server/reload/main.go b/internal/app/wwctl/server/reload/main.go deleted file mode 100644 index ad285cc1..00000000 --- a/internal/app/wwctl/server/reload/main.go +++ /dev/null @@ -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") -} diff --git a/internal/app/wwctl/server/reload/root.go b/internal/app/wwctl/server/reload/root.go deleted file mode 100644 index b8b6d4c2..00000000 --- a/internal/app/wwctl/server/reload/root.go +++ /dev/null @@ -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 -} diff --git a/internal/app/wwctl/server/restart/main.go b/internal/app/wwctl/server/restart/main.go deleted file mode 100644 index d2b98fc2..00000000 --- a/internal/app/wwctl/server/restart/main.go +++ /dev/null @@ -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") -} diff --git a/internal/app/wwctl/server/restart/root.go b/internal/app/wwctl/server/restart/root.go deleted file mode 100644 index 12be5f97..00000000 --- a/internal/app/wwctl/server/restart/root.go +++ /dev/null @@ -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 -} diff --git a/internal/app/wwctl/server/root.go b/internal/app/wwctl/server/root.go index ef6380a4..2e864549 100644 --- a/internal/app/wwctl/server/root.go +++ b/internal/app/wwctl/server/root.go @@ -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") +} diff --git a/internal/app/wwctl/server/start/main.go b/internal/app/wwctl/server/start/main.go deleted file mode 100644 index be562d9e..00000000 --- a/internal/app/wwctl/server/start/main.go +++ /dev/null @@ -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") - } -} diff --git a/internal/app/wwctl/server/start/root.go b/internal/app/wwctl/server/start/root.go deleted file mode 100644 index ba0d02b0..00000000 --- a/internal/app/wwctl/server/start/root.go +++ /dev/null @@ -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 -} diff --git a/internal/app/wwctl/server/status/main.go b/internal/app/wwctl/server/status/main.go deleted file mode 100644 index 3744611f..00000000 --- a/internal/app/wwctl/server/status/main.go +++ /dev/null @@ -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() -} diff --git a/internal/app/wwctl/server/status/root.go b/internal/app/wwctl/server/status/root.go deleted file mode 100644 index 396c44d3..00000000 --- a/internal/app/wwctl/server/status/root.go +++ /dev/null @@ -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 -} diff --git a/internal/app/wwctl/server/stop/main.go b/internal/app/wwctl/server/stop/main.go deleted file mode 100644 index 08926109..00000000 --- a/internal/app/wwctl/server/stop/main.go +++ /dev/null @@ -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") -} diff --git a/internal/app/wwctl/server/stop/root.go b/internal/app/wwctl/server/stop/root.go deleted file mode 100644 index 02ec9808..00000000 --- a/internal/app/wwctl/server/stop/root.go +++ /dev/null @@ -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 -} diff --git a/internal/pkg/warewulfd/daemon.go b/internal/pkg/warewulfd/daemon.go index 816c958b..e595f509 100644 --- a/internal/pkg/warewulfd/daemon.go +++ b/internal/pkg/warewulfd/daemon.go @@ -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 } diff --git a/internal/pkg/warewulfd/warewulfd.go b/internal/pkg/warewulfd/warewulfd.go index 0a7e1794..94e3847f 100644 --- a/internal/pkg/warewulfd/warewulfd.go +++ b/internal/pkg/warewulfd/warewulfd.go @@ -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 { diff --git a/userdocs/contents/configuration.rst b/userdocs/contents/configuration.rst index 238f8bc9..37c7e3b0 100644 --- a/userdocs/contents/configuration.rst +++ b/userdocs/contents/configuration.rst @@ -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. diff --git a/userdocs/contents/initialization.rst b/userdocs/contents/initialization.rst index 6d56a42f..79a374f5 100644 --- a/userdocs/contents/initialization.rst +++ b/userdocs/contents/initialization.rst @@ -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``. diff --git a/userdocs/contributing/development-environment-kvm.rst b/userdocs/contributing/development-environment-kvm.rst index 3f981652..1abd3e99 100644 --- a/userdocs/contributing/development-environment-kvm.rst +++ b/userdocs/contributing/development-environment-kvm.rst @@ -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 diff --git a/userdocs/contributing/development-environment-vagrant.rst b/userdocs/contributing/development-environment-vagrant.rst index 40c0c4d8..8d8944b7 100644 --- a/userdocs/contributing/development-environment-vagrant.rst +++ b/userdocs/contributing/development-environment-vagrant.rst @@ -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 diff --git a/userdocs/contributing/development-environment-vbox.rst b/userdocs/contributing/development-environment-vbox.rst index 17c9f16b..577bae52 100644 --- a/userdocs/contributing/development-environment-vbox.rst +++ b/userdocs/contributing/development-environment-vbox.rst @@ -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