Various more updates around Warewulf service and erorr cleanup
This commit is contained in:
@@ -2,9 +2,10 @@ package reload
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return warewulfd.DaemonReload()
|
||||
return errors.Wrap(warewulfd.DaemonReload(), "failed to reload Warewulf server")
|
||||
}
|
||||
|
||||
@@ -7,5 +7,9 @@ import (
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return errors.Wrap(warewulfd.DaemonStop(), "failed to stop warewulf daemon")
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ package start
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if SetForeground {
|
||||
return warewulfd.RunServer()
|
||||
return errors.Wrap(warewulfd.RunServer(), "failed to start Warewulf server")
|
||||
} else {
|
||||
return warewulfd.DaemonStart()
|
||||
return errors.Wrap(warewulfd.DaemonStart(), "failed to start Warewulf server")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ package status
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return errors.Wrap(warewulfd.DaemonStatus(), "failed to start daemon")
|
||||
return warewulfd.DaemonStatus()
|
||||
}
|
||||
|
||||
@@ -7,5 +7,5 @@ import (
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return errors.Wrap(warewulfd.DaemonStop(), "failed to stop warewulf daemon")
|
||||
return errors.Wrap(warewulfd.DaemonStop(), "failed to stop Warewulf server")
|
||||
}
|
||||
|
||||
@@ -25,6 +25,10 @@ func DaemonStart() error {
|
||||
}
|
||||
|
||||
} else {
|
||||
if util.IsFile(WAREWULFD_PIDFILE) {
|
||||
return errors.New("process is already running")
|
||||
}
|
||||
|
||||
os.Setenv("WAREWULFD_BACKGROUND", "1")
|
||||
|
||||
f, err := os.OpenFile(WAREWULFD_LOGFILE, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
||||
@@ -49,6 +53,8 @@ func DaemonStart() error {
|
||||
|
||||
fmt.Fprintf(p, "%d", pid)
|
||||
|
||||
fmt.Printf("Started Warewulf server at PID: %d\n", pid)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -56,27 +62,24 @@ func DaemonStart() error {
|
||||
|
||||
func DaemonStatus() error {
|
||||
if !util.IsFile(WAREWULFD_PIDFILE) {
|
||||
fmt.Printf("Warewulf daemon process not running (%s)\n", WAREWULFD_PIDFILE)
|
||||
return nil
|
||||
return errors.New("Warewulf server is not running")
|
||||
}
|
||||
|
||||
dat, err := ioutil.ReadFile(WAREWULFD_PIDFILE)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "could not read Warewulfd PID file")
|
||||
}
|
||||
|
||||
pid, _ := strconv.Atoi(string(dat))
|
||||
process, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to find process: %s\n", err)
|
||||
return err
|
||||
return errors.Wrap(err, "failed to find running PID")
|
||||
} else {
|
||||
err := process.Signal(syscall.Signal(0))
|
||||
if err != nil {
|
||||
fmt.Printf("SIGCONT on pid %d returned: %v\n", pid, err)
|
||||
return err
|
||||
return errors.Wrap(err, "failed to send process SIGCONT")
|
||||
} else {
|
||||
fmt.Printf("Warewulf daemon is running at PID: %d\n", pid)
|
||||
fmt.Printf("Warewulf server is running at PID: %d\n", pid)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,26 +88,22 @@ func DaemonStatus() error {
|
||||
|
||||
func DaemonReload() error {
|
||||
if !util.IsFile(WAREWULFD_PIDFILE) {
|
||||
fmt.Printf("Warewulf daemon process not running (%s)\n", WAREWULFD_PIDFILE)
|
||||
return nil
|
||||
return errors.New("Warewulf server is not running")
|
||||
}
|
||||
|
||||
dat, err := ioutil.ReadFile(WAREWULFD_PIDFILE)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "could not read Warewulfd PID file")
|
||||
}
|
||||
|
||||
pid, _ := strconv.Atoi(string(dat))
|
||||
process, err := os.FindProcess(pid)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to find process: %s\n", err)
|
||||
return err
|
||||
return errors.Wrap(err, "failed to find running PID")
|
||||
} else {
|
||||
err := process.Signal(syscall.Signal(syscall.SIGHUP))
|
||||
if err != nil {
|
||||
fmt.Printf("SIGCONT on pid %d returned: %v\n", pid, err)
|
||||
return err
|
||||
return errors.Wrap(err, "failed to send process SIGHUP")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +112,7 @@ func DaemonReload() error {
|
||||
|
||||
func DaemonStop() error {
|
||||
if !util.IsFile(WAREWULFD_PIDFILE) {
|
||||
fmt.Printf("Warewulf daemon process not running (%s)\n", WAREWULFD_PIDFILE)
|
||||
fmt.Printf("Warewulf daemon process not running\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -122,20 +121,21 @@ func DaemonStop() error {
|
||||
return err
|
||||
}
|
||||
|
||||
_ = os.Remove(WAREWULFD_PIDFILE)
|
||||
|
||||
pid, _ := strconv.Atoi(string(dat))
|
||||
process, err := os.FindProcess(pid)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to find process: %s\n", err)
|
||||
return errors.Wrap(err, "failed to find running PID")
|
||||
} else {
|
||||
err := process.Signal(syscall.Signal(15))
|
||||
if err != nil {
|
||||
fmt.Printf("SIGCONT on pid %d returned: %v\n", pid, err)
|
||||
return errors.Wrap(err, "failed to send process SIGTERM")
|
||||
} else {
|
||||
fmt.Printf("Terminated Warewulf process at PID: %d\n", pid)
|
||||
fmt.Printf("Terminated Warewulf server at PID: %d\n", pid)
|
||||
}
|
||||
}
|
||||
|
||||
os.Remove(WAREWULFD_PIDFILE)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user