Manual nits
This commit is contained in:
@@ -50,8 +50,6 @@ func reloadLogLevel(inputSource altsrc.InputSourceContext) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybeRunAsService is a no-op on Unix systems.
|
|
||||||
// Windows service mode is not available on Unix.
|
|
||||||
func maybeRunAsService(conf *server.Config) (bool, error) {
|
func maybeRunAsService(conf *server.Config) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,26 +17,23 @@ const serviceName = "ntfy"
|
|||||||
// Windows users can restart the service to reload configuration.
|
// Windows users can restart the service to reload configuration.
|
||||||
func sigHandlerConfigReload(config string) {
|
func sigHandlerConfigReload(config string) {
|
||||||
log.Debug("Config hot-reload via SIGHUP is not supported on Windows")
|
log.Debug("Config hot-reload via SIGHUP is not supported on Windows")
|
||||||
// On Windows, we simply don't set up any signal handler for config reload.
|
|
||||||
// Users must restart the service/process to reload configuration.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// runAsWindowsService runs the ntfy server as a Windows service
|
// runAsWindowsService runs the ntfy server as a Windows service
|
||||||
func runAsWindowsService(conf *server.Config) error {
|
func runAsWindowsService(conf *server.Config) error {
|
||||||
return svc.Run(serviceName, &ntfyService{conf: conf})
|
return svc.Run(serviceName, &windowsService{conf: conf})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ntfyService implements the svc.Handler interface
|
// windowsService implements the svc.Handler interface
|
||||||
type ntfyService struct {
|
type windowsService struct {
|
||||||
conf *server.Config
|
conf *server.Config
|
||||||
server *server.Server
|
server *server.Server
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute is the main entry point for the Windows service
|
// Execute is the main entry point for the Windows service
|
||||||
func (s *ntfyService) Execute(args []string, requests <-chan svc.ChangeRequest, status chan<- svc.Status) (bool, uint32) {
|
func (s *windowsService) Execute(args []string, requests <-chan svc.ChangeRequest, status chan<- svc.Status) (bool, uint32) {
|
||||||
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
|
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
|
||||||
|
|
||||||
status <- svc.Status{State: svc.StartPending}
|
status <- svc.Status{State: svc.StartPending}
|
||||||
|
|
||||||
// Create and start the server
|
// Create and start the server
|
||||||
@@ -92,8 +89,7 @@ func maybeRunAsService(conf *server.Config) (bool, error) {
|
|||||||
isService, err := svc.IsWindowsService()
|
isService, err := svc.IsWindowsService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("failed to detect Windows service mode: %w", err)
|
return false, fmt.Errorf("failed to detect Windows service mode: %w", err)
|
||||||
}
|
} else if !isService {
|
||||||
if !isService {
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
log.Info("Running as Windows service")
|
log.Info("Running as Windows service")
|
||||||
|
|||||||
Reference in New Issue
Block a user