Initial commit

This commit is contained in:
eleksir
2026-04-02 23:56:28 +03:00
commit 9e30243533
34 changed files with 8413 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
//go:build windows
package server
import (
"os"
"os/signal"
"syscall"
"github.com/eleksir/pekoe/internal/logger"
)
// signalSetup configures signal handlers for Windows.
// Windows doesn't support SIGUSR1, so we only handle shutdown signals.
// For log rotation on Windows, use a different mechanism.
func signalSetup() chan os.Signal {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
return sigCh
}
// handleSignal processes a received signal and returns true if the server should shutdown.
func (s *Server) handleSignal(sig os.Signal) bool {
switch sig {
case syscall.SIGINT, syscall.SIGTERM:
// Graceful shutdown
logger.Info("event=shutdown signal=%v", sig)
return true // Shutdown
case syscall.SIGHUP:
// On Windows, SIGHUP can be used for log rotation since SIGUSR1 is not available
// Reopen log files
if err := logger.Reopen(); err != nil {
logger.Error("event=log_reopen_error error=%v", err)
} else {
logger.Info("event=log_reopened")
}
return false // Continue listening
default:
return false
}
}